News for hackers. Stuff that matters.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by eklitzke on Friday June 04, 2021 @02:41PM (#27397374)
This approach works for I/O devices (and for things like network cards the kernel will typically poll them anyway), but I/O isn't the only thing that generates interrupts. For instance, a processor fault (e.g. divide by zero) should be handled immediately and synchronously since the CPU core generating the fault can't do any useful work until the fault is handled.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by justincormack on Friday June 04, 2021 @02:49PM (#27397482)
Faults for divide by zero are a terrible legacy thing, Arm etc do not do this, you test for zero if you want to, otherwise you get a value.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by DblPlusUngood on Friday June 04, 2021 @03:02PM (#27397659)
A better example: a page fault for a non-present page.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by rwmj on Friday June 04, 2021 @05:27PM (#27399263)
At university we designed an architecture[1] where you had to test for page not present yourself. It was all about seeing if we could make a simpler architecture where all interrupts could be handled synchronously, so you'd never have to save and restore the pipeline. Also division by zero didn't trap - you had to check before dividing. IIRC the conclusion was it was possible but somewhat tedious to write a compiler for[2], plus you had to have a trusted compiler which is a difficult sell.

[1] But sadly didn't implement it in silicon! FPGAs were much more primitive back then.

[2] TCG in modern qemu has similar concerns in that they also need to worry about when code crosses page boundaries, and they also have a kind of "trusted" compiler (in as much as everything must go through TCG).

Re:Intel and AMD Contemplate Different Replacements for x86 ... by Someone on Friday June 04, 2021 @07:15PM (#27400196)
> where you had to test for page not present yourself.

I would think that implies you need calls “lock this page for me” and “unlock this page for me”, as using a page after getting a “yes” on “is this page present?” is asking for race condition problems.

That would make this conceptually similar to the Mac OS memory manager, with a difference that didn’t use pages but arbitrary sized memory allocations (https://en.wikipedia.org/wiki/Classic_Mac_OS_memory_manageme...)

Re:Intel and AMD Contemplate Different Replacements for x86 ... by warkdarrior on Friday June 04, 2021 @06:54PM (#27400001)
Interesting. So what happens if the program does not test for the page? Doesn't the processor have to handle that as an exception of sorts?
Re:Intel and AMD Contemplate Different Replacements for x86 ... by rwmj on Saturday June 05, 2021 @02:12AM (#27402661)
This is why you need a trusted compiler. Basically it's "insecure by design" since the whole point of this optimization is to avoid any asynchronous exception so there's no need to implement that in the pipeline. The machine code must be forced somehow to implement these checks.

There have been architectures which have required a trusted compiler (eg. the Burroughs mainframes) or a trusted verifier (the JVM, NaCl). But it certainly brings along a set of problems.

It's unclear from here whether this is even an optimization. It looked a lot more compelling back in the mid 90s.

Re:Intel and AMD Contemplate Different Replacements for x86 ... by vlovich123 on Friday June 04, 2021 @04:35PM (#27398786)
Could be handled by having the CPU switch to a different process while the kernel CPU faults the data in.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by ben509 on Friday June 04, 2021 @04:58PM (#27398995)
The CPU doesn't know what processes are, that's handled by the OS. So there still needs to be a fault.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by vlovich123 on Friday June 04, 2021 @05:25PM (#27399246)
You’re thinking about computer architecture as designed today. There’s no reason there isn’t a common data structure defined that the CPU can use to select a backup process, much how it uses page table data structures in main memory to resolve TLB misses.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by gpderetta on Saturday June 05, 2021 @04:01AM (#27403158)
X86 had the concept of harware assisted context switching. Yet another unsued feature dropped in 64bit mode.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by Woodi on Saturday June 05, 2021 @05:56PM (#27408748)
It was slow so operating system devs didn't use it. So it was removed. Probably becouse hardware saved, properly, all registers and software can save only needed few (and sometimes miss something).

In effect: we don't know how secure it was...

But if it was good and Intel removed it then why Intel keeps so many useless crap in ?? Good parts - remove, bad - needed for backward compatibility... Can, finally, someone tell backward compatibility with WHAT ? DOS 4.0 ? Drivers for pre-winonly modems using plain ISA or PCI slots ??

Or maybe just like with EVE Online code (few years ago?) - no one anymore knows how some parts works...

Re:Intel and AMD Contemplate Different Replacements for x86 ... by pjc50 on Friday June 04, 2021 @05:27PM (#27399256)
Just to make it explicit for the people having trouble, the mechanism for switching processes in a pre-emptive multitasking system is interrupts.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by DblPlusUngood on Friday June 04, 2021 @05:08PM (#27399099)
In some cases, yes (if there are other runnable threads on this CPU's queue).
Re:Intel and AMD Contemplate Different Replacements for x86 ... by eklitzke on Friday June 04, 2021 @02:55PM (#27397571)
That was just an example, there are many other things the CPU can do that will generate a fault (for example, trying to execute an illegal instruction).
Re:Intel and AMD Contemplate Different Replacements for x86 ... by mschuster91 on Friday June 04, 2021 @03:35PM (#27398109)
Yes, but this one is so hard baked into everything that it would kill any form of backwards compatibility.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by bonzini on Friday June 04, 2021 @03:11PM (#27397782)
Or interprocessor interrupts for flushing the TLB, terminating the scheduling quantum, or anything else.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by vlovich123 on Friday June 04, 2021 @02:46PM (#27397447)
Is that actually true? Wouldn’t this imply you could launch a DOS attack against cloud providers just generating divisions by zero?
Re:Intel and AMD Contemplate Different Replacements for x86 ... by bonzini on Friday June 04, 2021 @03:09PM (#27397763)
You would only attack yourself. The CPU time you're paying for would be spent processing division by zero exceptions.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by vlovich123 on Friday June 04, 2021 @04:30PM (#27398734)
Then the CPU isn’t stopping and is moving on doing other work. Meaning the divide by zero could be processed by a background CPU and doesn’t require immediate handling. Same for page faults.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by bananabreakfast on Friday June 04, 2021 @05:55PM (#27399524)
Incorrect. The "CPU" is stopping and handling the fault. There is no background CPU from your perspective. In a cloud provider you are always in a virtual environment and using a vCPU which is constantly being preempted by the hypervisor.

You cannot DOS a hypervisor just by bogging down your virtualized kernel.

Re:Intel and AMD Contemplate Different Replacements for x86 ... by bonzini on Saturday June 05, 2021 @05:03AM (#27403423)
There are a couple x86 corner cases where you can do so, by causing an endless stream of exceptions. But they are not going to happen in a hot path, so the hypervisors force a vmexit on those exceptions and avoid that the processor freezes forever.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by bonzini on Friday June 04, 2021 @04:33PM (#27398769)
Your instance can still be preempted by the hypervisor.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by fulafel on Saturday June 05, 2021 @03:34AM (#27403036)
The hypervisor is just some software that runs on the same CPU. It wouldn't help if the assertion that the CPU can't continue was true.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by bonzini on Saturday June 05, 2021 @05:02AM (#27403417)
The CPU can't continue running user code because it jumps to the exception handler. But it can get to the hypervisor at any instruction boundary.

(I write a hypervisor for a living :)).

Re:Intel and AMD Contemplate Different Replacements for x86 ... by zaptheimpaler on Saturday June 05, 2021 @01:21AM (#27402446)
The divide by zero in this case is handled by a virtual CPU implemented in the hypervisor, not the actual physical CPU on the server.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by fulafel on Saturday June 05, 2021 @01:53AM (#27402583)
There are mechanisms that can intercede, and there are often more than one cpu thread per core.
Re:Intel and AMD Contemplate Different Replacements for x86 ... by imtringued on Friday June 04, 2021 @03:11PM (#27397789)
A site that renders HTML is more computationally expensive than handling a site that does nothing but division by zero.