x86 - why unite when you can fragment?

By: Linus Torvalds (torvalds.delete@this.linux-foundation.org), March 13, 2021 12:18 pm
Room: Moderated Discussions
So honestly, it doesn't look too bad.

The AMD version is essentially "Fix known bugs in the exception handling definition".

The Intel version is basically "Yeah, the protected mode 80286 exception handling was bad, then 386 made it odder with the 32-bit extensions, and then syscall/sysenter made everything worse, and then the x86-64 extensions introduced even more problems. So let's add a mode bit where all the crap goes away".

In contrast, the AMD one is basically a minimal effort to fix actual fundamental problems with all that legacy-induced crap that are nasty to work around and that have caused issues.

For a short list of "IDT exception handling problems", I'll just enumerate some of them:

(a) IDT itself is a horrible nasty format and you shouldn't have to parse memory in odd ways to handle exceptions. It was fundamentally bad from the 80286 beginnings, it got a tiny bit harder to parse for 32-bit, and it arguably got much worse in x86-64.

(b) %rsp not being restored properly by return-to-user mode.

(c) delayed debug traps into supervisor mode

(d) several bad exception nesting problems (NMI, machine checks and STI-shadow handling at the very least)

(e) various atomicity problems with gsbase (swapgs) and stack pointer switching

(f) several different exception stack layouts, and literally hundreds of different entrypoints for exceptions, interrupts and system calls (and that's not even counting the call gates that nobody should use in the first place).

But I suspect I forgot some.

AMD aims to fix the outright historical bugs (b)-(e), but keeps things otherwise the same (ie it adds a bit more code to the microcode that basically replaces some of the horrible hacks you currently have to do - badly - in system software).

The Intel one is the recognition that there was more wrong than just the outright bugs that had to be worked around by system software, and introduces a "fixed exceptions" model, which basically fixes all of the above.

Both are valid on their own, and they are actually fairly independent. Honestly, the AMD paper looks like a quick "we haven't even finished thinking all the details through, but we know these parts were broken, so we might as well release this".

I don't know how long it has been brewing, but judging by the "TBD" things in that paper, I think it's a "early rough draft".

The Intel FRED stuff has several years of background, and honestly, I think is the right thing to do. It really relegates the whole IDT to a "we don't even use this at all, unless you have legacy segment selectors". Good riddance to a truly horrid thing that goes back to a truly disgusting CPU architecture: the 80286.

I hope both vendors end up doing both of those things. The AMD version is better if you are an OS vendor that wants to change as little as humanly possible at the OS level, and get rid of known problems. Think "legacy OS that we can't really make big changes to".

But I think the Intel version is better if you think that x86-64 should actually survive longer-term, and you actually want to improve exception handling and speed things up (the "F" historically stood for "Fast", I'm not sure why they've apparently renamed it "Flexible").

Honestly, I like the AMD model of "release early for discussion". It's what they did with the original x86-64 (aka "amd64") spec. I think their paper is very much in line with that original spec, both in that "early release about a non-final this is what we want to do" and a "minimal changes to existing hardware".

But I do think that the Intel approach is actually the better fix to some of the nastiest parts of the whole architecture.

If you ever expect to eventually live in a world where the old 32-bit legacy isn't really relevant any more (we can already pretty much already discount the x86 16-bit modes), the Fred approach actually takes you a good step in that direction, I think.

Anyway, I hope this won't be a fragmentation issue, but realistically, because of how little changes the AMD model does to the legacy mode, and how independent the whole Fred exception model is from the legacy mode, even if you don't end up in that "everybody does both", I suspect it's not exceptionally (pun intended) hard to just support both.

After all, Fred is very clearly defined to have an entirely new model, and any OS vendor that goes that way will still have to support the legacy exception model for older CPU's.

The point being that the Fred exception handling is much simpler, but it's entirely separate code and logic, explicitly bolted to the side in the hope that the original code and logic can be removed entirely some day.

In contrast, the AMD model is meant to very explicitly interface with existing code, and just allow people to avoid the fragile (and sometimes expensive) hacks and workarounds they already have.

So they actually have very little overlap - both conceptually and from a "implementation and use" standpoint.

< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
x86 - why unite when you can fragment?anonymou52021/03/12 05:16 PM
  x86 - why unite when you can fragment?Linus Torvalds2021/03/13 12:18 PM
    x86 - why unite when you can fragment?Jon Masters2021/03/13 06:25 PM
      x86 - why unite when you can fragment?Jon Masters2021/03/13 06:44 PM
        x86 - why unite when you can fragment?Yuhong Bao2021/03/13 07:49 PM
        x86 - why unite when you can fragment?tt2021/03/20 08:30 AM
    x86 - why unite when you can fragment?Andrey2021/03/14 03:15 PM
      x86 - why unite when you can fragment?Linus Torvalds2021/03/14 03:58 PM
        x86 - why unite when you can fragment?anonymou52021/03/14 04:31 PM
          x86 - why unite when you can fragment?anon22021/03/14 07:07 PM
        Microkernel?Anon2021/03/14 10:49 PM
          Microkernel?none2021/03/14 11:37 PM
            Microkernel?Anon2021/03/15 12:56 AM
          Microkernel?anon22021/03/15 12:58 AM
            Microkernel?Simon Farnsworth2021/03/15 02:12 AM
              Microkernel?anon22021/03/15 03:53 AM
                Microkernel?Simon Farnsworth2021/03/15 05:56 AM
                  Microkernel?iz2021/03/15 07:10 AM
                    Microkernel?Anon2021/03/15 08:05 AM
                      Microkernel?iz2021/03/16 12:25 AM
                        Microkernel?Andrey2021/03/16 01:54 AM
                          Microkernel?iz2021/03/16 07:36 AM
                            Microkernel?Andrey2021/03/16 09:06 AM
                              Microkernel?anonymou52021/03/16 10:44 AM
                              Microkernel?iz2021/03/21 01:58 AM
                                Microkernel?Andrey2021/03/21 08:34 AM
                  Microkernel?anon22021/03/15 07:31 AM
                    Microkernel?Simon Farnsworth2021/03/16 03:42 AM
            Microkernel?Gabriele Svelto2021/03/15 02:21 AM
              Microkernel?anon22021/03/15 03:56 AM
                Microkernel?Gabriele Svelto2021/03/15 09:41 AM
                  Microkernel?anon22021/03/15 07:00 PM
                    Microkernel?Gabriele Svelto2021/03/16 06:23 AM
                      Microkernel?anon22021/03/16 04:13 PM
                        Microkernel?anon22021/03/16 04:16 PM
                    Microkernel?Gian-Carlo Pascutto2021/03/16 12:40 PM
                      Microkernel?anon22021/03/16 04:53 PM
                        Microkernel?Linus Torvalds2021/03/16 06:25 PM
                          Microkernel?Doug S2021/03/17 08:30 AM
                            Microkernel?Linus Torvalds2021/03/17 09:30 AM
                              Microkernel?Brendan2021/03/17 09:56 PM
                                Microkernel?Michael S2021/03/18 02:47 AM
                                  Microkernel?Brendan2021/03/18 08:07 AM
                              Microkernel?Jose2021/03/18 08:35 AM
                            Microkernel?zArchJon2021/03/18 04:42 PM
                          TransputerRichardC2021/03/17 08:47 AM
                          Microkernel?dmcq2021/03/17 10:15 AM
                            Microkernel?Linus Torvalds2021/03/17 10:59 AM
                              Microkernel?dmcq2021/03/17 11:38 AM
                              Microkernel?Adrian2021/03/17 12:00 PM
                              Microkernel?Ana R. Riano2021/03/18 03:33 AM
                              Microkernel?2021/04/30 03:52 PM
                          Microkernel?NvaxPlus2021/03/17 10:48 AM
                            Microkernel?Michael S2021/03/18 02:32 AM
                              Microkernel?Adrian2021/03/18 03:12 AM
                                Microkernel?dmcq2021/03/18 05:30 AM
                                  Microkernel?dmcq2021/03/18 05:55 AM
                                  Microkernel?Adrian2021/03/18 07:35 AM
                                    Microkernel?---2021/03/18 08:49 AM
                                    Microkernel?dmcq2021/03/18 09:59 AM
                                      Microkernel?dmcq2021/03/18 03:09 PM
                              Microkernel?---2021/03/18 08:27 AM
                          Microkernel?Kalle A. Sandström2021/03/20 05:34 AM
                            Microkernel?---2021/03/20 07:35 AM
                            Microkernel?anon22021/03/21 04:29 PM
            Microkernel?dmcq2021/03/15 03:06 AM
              Microkernel?anon22021/03/15 03:59 AM
                Microkernel?dmcq2021/03/15 10:51 AM
                  Microkernel?anon22021/03/15 07:31 PM
                    Microkernel?dmcq2021/03/16 08:17 AM
                      Microkernel?Jukka Larja2021/03/16 10:22 AM
                        Microkernel?dmcq2021/03/16 03:06 PM
                          Microkernel?Jukka Larja2021/03/17 02:42 AM
                            Microkernel?dmcq2021/03/17 06:00 AM
                      Microkernel?anon22021/03/16 04:26 PM
                    Microkernel?---2021/03/16 09:07 AM
            Microkernel?-.-2021/03/15 07:15 PM
              Microkernel?anon22021/03/15 08:18 PM
                Microkernel?Foo_2021/03/16 02:37 AM
                  Read the thread (NT)anon22021/03/16 04:27 PM
                    Already did (NT)Foo_2021/03/17 01:55 AM
                      Already didanon22021/03/17 02:46 AM
                        Already didEtienne Lorrain2021/03/18 01:31 AM
                Microkernel?-.-2021/03/17 04:04 AM
                  Microkernel?Gabriele Svelto2021/03/17 07:53 AM
                    Microkernel?-.-2021/03/17 01:43 PM
              Microkernel?dmcq2021/03/16 07:40 AM
        x86 - why unite when you can fragment?Konrad Schwarz2021/03/17 09:19 AM
    x86 - why unite when you can fragment?anonon2021/03/15 06:37 AM
Reply to this Topic
Body: No Text
How do you spell tangerine? 🍊