Make Linux Fast Again
make-linux-fast-again.com
make-linux-fast-again.com
Some previous appearances -- there were others:
https://news.ycombinator.com/item?id=22830330 (368 points by laurentdc on April 10, 2020)
https://news.ycombinator.com/item?id=19928110 (11 points by Tomte on May 16, 2019)
https://news.ycombinator.com/item?id=18497751 (4 points by jcelerier on Nov 20, 2018)
Source: https://github.com/jcelerier/jcelerier.github.io/blob/master...
Discussion: https://linuxreviews.org/HOWTO_make_Linux_run_blazing_fast_(...
Note the kernel version in the URL as the options evolve with time. Some will be deprecated and some added but the kernel does not always complain if you utilize a deprecated option or an option that does not exist.
[1] - https://www.kernel.org/doc/html/v5.15/admin-guide/kernel-par...
(Simple example: You probably wouldn't care much about Spectre mitigations if you're running Linux on a x86 emulator on an ARM CPU...)
In other words, some of these kernel parameters COULD give speed increases in virtualized environments WITHOUT sacrificing a corresponding loss of security, due to differences between a software-emulated x86 environment, and a hardware bare-metal actual x86 environment...
The trick then, can be boiled down to:
a) Know your Linux host environment...
b) Know what implications given kernel parameters will have in that environment...
c) Choose trade-offs accordingly...
a) The specific x86 chip manufacturer and architecture (i.e., Intel, AMD, VIA, IDT, Cyrix, Transmeta, Zhaoxin, MCST (Elbrus), ? -- see https://en.wikipedia.org/wiki/List_of_x86_manufacturers -- there's a huge difference in potential security issues between say, the earliest Intel 386, and the latest Intel or AMD (or compatible) 64-bit x86 multi-cored multi-threaded CPU...
b) What security issues are potentially present in that CPU;
c) What the Virtual Machine / Emulator and/or Virtualized Environment does or doesn't do.
(For example, if you use Bochs (https://bochs.sourceforge.io/) for the guest environment on an x86 host -- then there's absolutely nothing that the guest OS can do to mitigate host OS security issues -- that's because all instructions inside of the guest are emulated -- security must be handled at the level of the OS/Hardware that is running Bochs, that is, at the level of the host.)
Now, things get slightly more weird with Virtual Machines/Emulators/Virtual Environments that permit some/all of the x86 instructions to run directly on the host hardware.
Here we have to distinguish between user-mode and "protected mode" (OS and/or Hypervisor, Ring < 3, instructions)...
You see, a Virtual Machines/Emulator/Virtual Environments -- may permit patterns of the following sort:
1) Some/All of the user-mode x86 instructions in the guest environment to run directly in the host environment without translation/modification...
2) Some/All of the user-mode x86 instructions AND some/all of the "protected mode" (OS and/or Hypervisor, Ring < 3, instructions) to run directly in the host environment without translation/modification...
Now, I am not an expert on any of this.
I am not an expert on all of the Virtual Machines/Emulator/Virtual Environments out there, nor am I an expert on all x86 instructions, protected mode or user mode...
But what I can tell you is simply this:
What x86 instructions a Virtual Machine/Emulator/Virtual Environment permits to be run directly, that is, which x86 instructions, existing in the guest OS, ran directly on the host CPU (without modification or deletion or "hooking"/"intercepting" or what-have-you), could have a large impact on security...
Which is a double-edged sword!
The more power that is given to the guest OS to access the lower layers (the host or physical hardware) -- the more guest OS's can potentially mitigate security issues...
But on the other hand:
The more power that is given to a guest OS to access the lower layers (the host or physical hardware) -- the more that guest OS can potentially CAUSE security issues!
It's a double-edged sword!
Ultimately: The more you can know about the layers of your specific stack, the better the position you'll be in to control security, and security-related issues...
Anyway, great question!
I'm not the expert... take everything that I'm saying with the proverbial "grain of salt"... It's a good idea to do all of the research necessary to know your own specific stack...
Also, one thing that I do know -- that if you're running an x86 emulator on a non-x86 CPU, the option (from the Virtual Machine/Emulator/Virtual Environment's point-of-view) of simply passing on instructions to the lower-level CPU for direct execution -- no longer exists -- in other words, running on a non-x86 CPU (i.e. ARM, RISC-V, etc.) -- the Virtual Machine/Emulator/Virtual Environment now MUST translate or interpret x86 instructions in the guest -- it can no longer ask the underlying host to run them directly, without modification...
I know that was not your question -- but I think it's an important additional observation...
> What x86 instructions a Virtual Machine/Emulator/Virtual Environment permits to be run directly, that is, which x86 instructions, existing in the guest OS, ran directly on the host CPU (without modification or deletion or "hooking"/"intercepting" or what-have-you), could have a large impact on security...
How would I even begin to map out which instructions get passed directly to the host cpu? I mean even if we just look at KVM, there's many other pieces of software that go into a virtualization environment. Wouldn't qemu, virsh, or KVM versions/configuration impact which instructions go right to the hardware? We haven't even gotten to the guest config, or any host hardware details! My instinct says it's extremely difficult to answer our question without a team of engineers.
> if you're running an x86 emulator on a non-x86 CPU, the option (from the Virtual Machine/Emulator/Virtual Environment's point-of-view) of simply passing on instructions to the lower-level CPU for direct execution -- no longer exists -- in other words, running on a non-x86 CPU (i.e. ARM, RISC-V, etc.) -- the Virtual Machine/Emulator/Virtual Environment now MUST translate or interpret x86 instructions in the guest -- it can no longer ask the underlying host to run them directly, without modification...
Makes sense to me. My follow up is now, does paravirtualization effectively create the same translation requirement? If I have an x86 xen-based hypervisor running x86 guests, does the virtual interface provided by xen give us a similar security control that ARM->x86 provides? (Or at least "good enough")?
I appreciate the appreciation! But please remember I am not an expert in this area -- only a fellow interested party. A "student" (for lack of a better term) of sorts. I'll tell you everything I know -- but keep in mind that in this setting I am not unlike Hamlet's Horatio -- that is, "There are more things in Heaven and Earth -- that are dreamt of in my philosophy..." :-)
>Wouldn't qemu, virsh, or KVM versions/configuration impact which instructions go right to the hardware?
They would indeed!
>How would I even begin to map out which instructions get passed directly to the host cpu?
It's a great question!
If I recall correctly, Bochs has/had a compilation option whereby if a flag was set, Bochs would to (at the expense of a lot of speed!) proceed to create a log or report or tallying of some sort -- such that when you exited it, it would show a list of each x86 instruction type that was used during runtime -- in other words, if you ran an OS in Bochs -- you could then get a list of ALL of the x86 instructions it used! Very handy if you're trying to get a new/alien OS to work on an x86 emulator, if/when in early versions of the emulator there might be bugs in emulating specific x86 instructions...
QEMU might have (or have had!) the same facility. I am not a QEMU expert, so I don't know.
Also, there's at least 3 possible things that can happen to any given instruction:
1) It can go through unmodified;
2) It can go through modified (for example, jumps may have their target address modified; this is because if code portions are expanded because of other modification, jump target locations will change...)
3) It can be intercepted by the VM environment (and/or Hypervisor), where specific code in the VM environment or Hypervisor is executed to replace or emulate the functionality of the instruction...
QEMU might have a way to log/count instructions that it intercepts/modifies, albeit, if this exists, this would probably be a compilation-time switch that would need to be set, and performing this would probably slow down guest considerably...
>My instinct says it's extremely difficult to answer our question without a team of engineers.
My instinct says that your instinct is extremely correct!
>My follow up is now, does paravirtualization effectively create the same translation requirement?
Again, I'm not an expert. I would guess that it would not be off-limits for the paravirtualizer to engage in translation, but I would also guess that if the paravirtualizer could avoid it for the most part, it would... but those are only guesses...
If you really want to understand "how deep the rabbit hole goes" (AFAIK) -- then I would start by going here:
http://pascal.hansotten.com/uploads/pascals/pascal-s%20sneps...
Now, what is this mess of code, you might ask? Well for this exercise, IGNORE MOST OF IT!. Do a word search for 'procedure interpret', of which part looks like this:
procedure interpret;
var pc, sp, j, k, n: integer; i: instr; c: char; h: boolean;
begin pc:= 0; h:= false; repeat i:= code[pc]; pc:= pc+1;
case i.op of
add : begin m[sp+1]:= m[sp+1]+m[sp]; sp:= sp+1 end;
neg : m[sp]:= -m[sp];
mul : begin m[sp+1]:= m[sp+1]*m[sp]; sp:= sp+1 end;
divd : begin m[sp+1]:= m[sp+1] div m[sp]; sp:= sp+1 end;
[...20 or so more lines deleted, for brevity...]
end
until h
end;So what is that, and how is it relevant to this discussion you may ask! Ah! You see, that's a Turing-complete machine implemented 20 or so lines of Pascal Code! (in this case, inside of an early pascal compiler, the reason for which being that if you were running binary instructions (such as compiled output!) on an early computer without memory protection, you could easily crash the computer, but if you ran that same program inside of this emulation environment, then that could no longer happen!)
This procedure, procedure "Interpret" (terrible name for it, IMHO) -- actually implements one of the first known and simplest Virtual Machines in existence! (There are simpler ones, but they're more academic, so we'll ignore them for now!).
Basically that Virtual Machine, procedure "Interpret" -- could (in theory!) run any program that any of today's computers could, everything from DOOM to Spreadsheets to Operating Systems to what-have-you. Why? Because it's Turing-complete!
But... so is the x86 chip! (And every other CPU out there!).
SP, incidentally, which is used inside of that code -- can be thought of as x86's ESP (32-bit), or RSP (64-bit). It's a stack pointer, that's all it is! Similarly when you see 'm' and brackets [] -- that's just (virtualized!) memory! 'pc' (program counter) = x86's IP (16 bit)/EIP (32 bit)/RIP (64 bit).
OK, so now with all of this background, hopefully you see how on the one hand how easy it is to create a Software Virtual Machine (not a hardware one, which is a different animal!) -- but on the other hand, parsing x86 instructions and doing so correctly might require pages and pages of esoteric code!
Then we have the (hardware!) problem that later x86 CPU's allow multiple levels of nested virtualization -- that is, if those later x86 chips were designed correctly, then in theory you could have an almost infinite number of nested virtual machines (subject only to memory availability) -- and that's only in Hardware!
A software virtual machine (such as procedure Interpret, or any other Turing-Complete software!) -- can in theory run an almost infinite number of nested (software) virtual machines! One inside the other! Subject only to CPU resource availability (the more you try to run, the slower they get, etc.)
So between the two (hardware and software), you could have rabbit holes on top of rabbit holes...
Which is why I claim "Socratic Ignorance" ("The only thing I know is that I know nothing").
And then of course there's the age-old philosophic question of "Who guards the guardians?" -- in other words, even though a virtualization environment (or any piece of software or hardware on the stack) can add security -- if it isn't properly written/debugged/audited -- it can take security away.
In other words, "Who guards the guardians?"
Anyway, it's a broad topic area. I'm not the "go-to guy" for this! But great questions!
And turn on eBPF for full insecurity.
if you are especially unlucky the atack comes with you opening a website or similar
and honestly firewalls often only help against atacks against services with open ports running on your system, once they are in your system they have a lot of ways to circumvent your firewall (assuming it's a desktop system or similar, mainly not a single service system)
Even then you have to perform privilege escalation and map out the network. By this point you’re already pwned. The adversary isn’t gonna be looking for or even capable of pulling off a low level cpu exploit.
Of course this is possible if everybody else keeps their mitigations on.
If you have the spare cash and room, it's not a bad idea to keep gaming devices separate from work or personal devices.
Gaming may conflict with security in several aspects:
- Performance optimizations (eg. this website)
- Installing various closed-source drivers, peripheral utilities, or custom installers
- Granting privileged access to legitimate anti-cheat software
- Or even, perish the thought, installing pirated games and cracks
If you enable 2FA on your Steam account, backup your saved games to the cloud, and otherwise keep your gaming PC devoid of any remotely sensitive or valuable data, you can mostly have peace of mind as you blissfully install all kinds of untrusted software on what is essentially a glorified gaming console.
If you want to use your nice 38" curved monitor for non-gaming activities on a secure computer, a KVM switch is pretty cheap.
(Of course, if you're happy playing DRM-free games on Linux with a sufficiently powerful AMD card, you don't need to bother with any of that.)
mods are grate but many (not all) mods basically mean running programs with the same permissions as the game from not necessarily trusted sources
and while there are many trustable and reputable mods out there there have been multiple cases of high profile mods stealing user logins, e.g. in Minecraft.
For speakers you can just use a Y connector. Add a wireless mouse with multiple outputs built-in (eg Logitech MX Master), or a separate gaming mouse if you prefer, and that just leaves the keyboard to switch between the two devices.
Changing the input on my monitor requires three button presses, and comes with a noticeable lag. Then I've got to press a button on the bottom of my mouse, and another button for my keyboard. If I bought a fancy KVM, I'd be able to swap everything in a couple seconds! It'd be nice also to hook up a mic and webcam but I'll probably just think about it for another 6 months and never pull the trigger.
Regardless, I'd expect a small/difficult-to-discern improvement in practical use-cases. Caveat: on relatively recent chips. Many-generations old i3/i5 chips with none of these mitigations in hardware probably are suffering.
I'm sure synthetic `openssl` benchmarks are favorable, but I don't use my computer for that
If you're churning enterprise data, sure, it might be meaningfully quicker - but good luck convincing auditors that was a good idea.
[0] https://github.com/siraben/dotfiles/commit/c0eb0b43083738cab...
also known as
forgot how fundamental broken the security model of many cpus is
also know as
who cares if it's my gaming PC and I'm not a hight profile target
or
omg, don't do online banking on that system
Well... if you keep it just for online banking it's perfectly safe and fast.
They're usually passed in by the bootloader (excepting the case when the kernel itself is the bootloader, such as in a standalone efi build - in that case you pass them in the kernel config).
Realistically, there is very little threat to turning off the mitigations with enough precautions in place. Obviously not recommended on a vps or other shared servers etc.
[0] https://linuxreviews.org/HOWTO_make_Linux_run_blazing_fast_(...
When you do know how computers work and how your threat models looks like, absolutely do run this. 10-15% more performance is no joke.
Funny timing.
https://www.kernel.org/doc/html/latest/admin-guide/kernel-pa...
Also the website is for everyone that does not know about kernel flags completely useless.
For example, I found it useful professionally. We're releasing a new hardware model. We're doing some in-depth performance tuning/evaluation. To understand our performance characteristics, I needed us to break down the performance change into improvement due to new hardware and reduction due to new mitigations.
Linking this page in the Jira issue was the fastest way to get the point across what we needed to look into.
It is not, at all, something I would ever recommend to lay people, or use in the actual shipping product.
At home, I don't do threat models or risk assessments. I also don't care that much about 5 to 15% increase in benchmarks, I just hope that the OS vendor makes sensible decisions in regards to safety and performance.
At work, I do care about small increases but I would never just copy some random kernel options found on an otherwise empty web site. Cargo culting useless or harmful options is a very tangible threat.
Generally not.
If your production system is managed competently, I'm certain that there are engineers that can assess risk vs. performance and whether spectre and similar issues warrant those mitigations in your specific environment and make the appropriate design decisions.
If on the other hand your system is managed by "best-practices", distro defaults, and what "some-guy-on-the-internet said", well then you have much bigger problems.
Also, best website ever.
My gut says that single user machines it doesn't matter so much, however these same machines probably run a lot of untrusted JavaScript that may be able to exploit things.
A crud rest service receiving requests from the open internet, probably a bad idea to disable mitigations on that machine.
On the other hand, a video transcoder or similar picking tasks off a queue and writing back to storage maybe it's fine? Though I'll admit I'm not sure that there wouldn't be ways to cause (sensitive) data to get into the output file, so would default to leaving everything enabled, especially since the input to transcode would be arbitrary
2) No, most people (not just engineers) are bad at risk assessment. Like thinking "my single user system shouldn't care about this".
3) I was talking about prod environments, not your random laptop.