News: 1713288608

  ARM Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life (Terry Pratchett, Jingo)

Torvalds intentionally complicates his use of indentation in Linux Kconfig

(2024/04/16)


Linux kernel supremo Linus Torvalds has made the use of indentation in kernel config files more ambiguous – intentionally to weed out inferior parsers.

[1]Kernel 6.9-rc4 , the latest release candidate for the next version of the Linux kernel, came out yesterday. Among the usual drivers and bug fixes, it contains some more [2]tweaks for bcachefs, as well as some [3]mitigations against the recently-uncovered Spectre-style [4]Native Branch History Injection data leaks.

However, the change that brought the most amusement to the face of the Reg FOSS desk is a configuration file [5]change from Linus himself, titled "Kconfig: add some hidden tabs on purpose." He switched a space indent to a tab indent to catch out poor-quality parsers.

[6]

Specifically, in this block of text in the kernel source... default 12 if PAGE_SIZE_4KB

default 13 if PAGE_SIZE_8KB

default 14 if PAGE_SIZE_16KB

default 15 if PAGE_SIZE_32KB

default 16 if PAGE_SIZE_64KB

default 18 if PAGE_SIZE_256KB

...the character between default and the integer value is now an eight-character-wide tab indentation. It just happens to fall on the end of a tab boundary so it appears as one space character.

While Torvalds is famed for his [7]robust approach to giving feedback in public, he has been working on it, and in 2018 [8]took a break to help him to get the emotions in his emails under better control.

[9]

[10]

This change could be one example of this. The kernel commandant spotted one particular code change, [11]commit d96c36004e31 which had a single purpose:

Fix FTRACE_RECORD_RECURSION_SIZE entry, replace tab with a space character. It helps Kconfig parsers to read file without error.

Kconfig is [12]the configuration language used to control the kernel build system, and like many other [13]off-side rule languages , it uses indentation to delimit blocks. Yes, significant whitespace, just like in Python, YAML, and many other programming and configuration languages. Love it or hate it, you can't escape it.

In this change, he is intentionally making the use of indentation in kernel build configuration files more complicated, in order to force the authors of tools which parse such files to improve their game. As he explains:

Let's make sure it gets fixed. Because if you can't parse tabs as whitespace, you should not be parsing the kernel Kconfig files.

This seems to us to be an instance of [14]Postel's Law , which Postel enshrined in [15]RFC 761 in 1980: Be liberal in what you accept, and conservative in what you send. Many indentation-marked languages have a recommended style, such as [16]Python's PEP-008 , which says very clearly and distinctly:

Use 4 spaces per indentation level.

But in fact, although the specification is strict, the interpreter will happily accept different numbers of spaces, or tabs in some lines and spaces in others, so long as developers are consistent about how they use them. This is what Linus wants to see, and he quite rightly regards as broken whatever parsing tool it was that failed when it encountered tabs instead of spaces.

[17]Linux 6.9 will be the first to top ten million Git objects

[18]Linus Torvalds flames Google kernel contributor over filesystem suggestion

[19]Long-term support for Linux kernels is about to get a lot shorter

[20]Fed-up Torvalds suggests disabling AMD's 'stupid' performance-killing fTPM RNG

[21]Linux has nearly half of the desktop OS Linux market

So, rather than a savagely critical email response, he is knowingly and with malice aforethought using more complicated indentation in order to expose tools that can't handle it. It should weed out the weaker tools, leaving only the fitter, better-adapted ones… while not publicly hurting anyone's feelings.

Think of it as evolution in action. ®

Get our [22]Tech Resources



[1] https://lore.kernel.org/lkml/CAHk-=whdUP62_7N6s837tTFjvmcGxyRnMGwnVnZwn2fDVf5E8A@mail.gmail.com/T/#u

[2] https://lore.kernel.org/lkml/CAHk-=whdUP62_7N6s837tTFjvmcGxyRnMGwnVnZwn2fDVf5E8A@mail.gmail.com/T/#u

[3] https://lore.kernel.org/lkml/ZhudAcrqVdnwUjKN@gmail.com/

[4] https://www.theregister.com/2024/04/10/intel_cpus_native_spectre_attacks/

[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?utm_source=anzwix&id=d5cf50dafc9dd5faa1e61e7021e3496ddf7fd61e

[6] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/oses&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=2&c=2Zh709-MR7sC2fuBLePE8cgAAABY&t=ct%3Dns%26unitnum%3D2%26raptor%3Dcondor%26pos%3Dtop%26test%3D0

[7] https://www.theregister.com/2012/06/18/torvalds_curses_nvidia/

[8] https://www.theregister.com/2018/09/17/linus_torvalds_linux_apology_break/

[9] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/oses&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=4&c=44Zh709-MR7sC2fuBLePE8cgAAABY&t=ct%3Dns%26unitnum%3D4%26raptor%3Dfalcon%26pos%3Dmid%26test%3D0

[10] https://pubads.g.doubleclick.net/gampad/jump?co=1&iu=/6978/reg_software/oses&sz=300x50%7C300x100%7C300x250%7C300x251%7C300x252%7C300x600%7C300x601&tile=3&c=33Zh709-MR7sC2fuBLePE8cgAAABY&t=ct%3Dns%26unitnum%3D3%26raptor%3Deagle%26pos%3Dmid%26test%3D0

[11] https://git.kernel.dk/?p=linux-block.git;a=commit;h=d96c36004e31

[12] https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt

[13] https://en.wikipedia.org/wiki/Off-side_rule

[14] https://lawsofux.com/postels-law/

[15] https://datatracker.ietf.org/doc/html/rfc761

[16] https://peps.python.org/pep-0008/

[17] https://www.theregister.com/2024/03/11/linux_6_8_arrives/

[18] https://www.theregister.com/2024/01/29/linux_6_8_rc2/

[19] https://www.theregister.com/2023/09/26/linux_kernel_report_2023/

[20] https://www.theregister.com/2023/07/31/linus_torvalds_ftpm/

[21] https://www.theregister.com/2023/07/18/linux_desktop_debate/

[22] https://whitepapers.theregister.com/



Paul Crawford

I always thought this sort of approach would deal with leap-seconds, make every month a jump forward or back, and when you need to move for good simply exclude one of those steps. That way software teams would get borked every month until they fixed their code to work properly. Rather then moan and hiss and throw up their hands in horror every couple of years when the well-documented event was applied as needed for Earth rotation versus UTC alignment.

Tab = four  

Jou (Mxyzptlk)

That is indeed the right choice. I agree here. Even Powershell ISE does it :D .

Re: Tab = four  

Someone Else

But...but...but...not even Linus can countenance that. He demands using the OTBS, which requires tabs, not spaces, each of which must represent 8 columns of whitespace.

Re: Tab = four  

Roland6

Given the equivalence has existed since the first typewriter, it makes you wonder as to the skill level of the people involved in modern parser design and development.

I wonder if Rust suffers from the same problem…

Semicolons and curly braces, forever.

Philo T Farnsworth

I can't count the number of wasted hours I've spent trying to find bugs in python or jade code caused by an accidental stray indent or outdent.

But maybe that's just me.

Re: Semicolons and curly braces, forever.

Ken Hagan

Zero, surely? Either the text lines up with the logic or it doesn't.

Re: Semicolons and curly braces, forever.

bazza

Problem is you then have to write down in comments exactly what the logic should be. Lose an indent accidentally off a line that’s supposed to be inside an if statement and you’ve no way of knowing unless there’s some other record of what the logic should actually be.

Self documenting code is impossible when something that you can’t see can be syntactically significant.

Re: Semicolons and curly braces, forever.

doublelayer

Indentation is many things, but invisible is not one of them. If you can't recognize whether a line belongs in the statement, then it won't help if the statement has a curly bracket at the end or not. The problem isn't knowing where the statement ends, but knowing whether an expression should be inside it. There are lots of reasons why syntactic whitespace is annoying, and I would not include that feature in a language I designed*, but you cannot file it under "something that you can’t see can be syntactically significant".

* I might warn about it in my compiler because I've seen some truly horribly indented code in languages where it is unnecessary, but I wouldn't make indentation control flow. Brackets help prevent people from making mistakes that they have to catch later because a compiler cannot know what structure is appropriate. I'm confident that programmers can do that without brackets, but having them makes it less likely that they'll get into that situation in the first place.

Re: Semicolons and curly braces, forever.

Joe W

The problem is (or was) that the python interpreter was convinced that a tab is a different interpretation than four or eight or however many spaces you used. You had no way to pick that up visually.

The article sounds as if this has been corrected though.

Re: Semicolons and curly braces, forever.

Philo T Farnsworth

In a perfect world, perhaps.

In a world where you need to debug someone else's code, you need to debug your own code six months later (effectively the same thing), or the cat decided to curl up on top of the keyboard while you weren't looking, the flow of logic may not always be apparent.

I wish to Torvalds and van Russum that life were so simple and the fates were so benign.

Re: Semicolons and curly braces, forever.

John Riddoch

I'm sure it was /etc/syslog.conf on Solaris that really didn't like spaces instead of tabs. Of course, everything looked ok to a human, but it just failed spectacularly. It usually happened when copying & pasting from another system, because it would copy the tab as spaces into the new file.

A stand against software leniency

m4r35n357

Coding against idiocy has led directly to the bloated mess that is the web stack. Important stuff _should_ go bang if it is wrong!

Re: A stand against software leniency

bazza

Indeed.

It’s interesting that the language du jour Rust is widely applauded and has some entirely new and powerful ways of pointing out the one’s code is the product of a klutz who should not be allowed near a keyboard. That’s kind of the ultimate anti Web tech reaction.

I Hate Syntax Critical Whitespace Indentation

bazza

As per title.

If you’re the type of coder who likes it, go and write in Whitespace (as in the actual programming language) and then say it’s still a good idea. You’re already half way there if you like Python or Yaml.

It’s a really bad idea that something a computer won’t show or print and, more importantly, cannot be seen to be missing should be considered syntactically important.

!(Postel's Law)

Dan 55

Seems Linus is being liberal in what he sends, not conservative. And parsers are being conservative in what they accept, not liberal.

(IBM motto: "We found five vowels hiding in a corner, and we used
them _all_ for the 'eieio' instruction so that we wouldn't have to use
them anywhere else").

[...]

(IBM motto: "If you can't read our assembly language, you must be
borderline dyslexic, and we don't want you to mess with it anyway").

[...]

(IBM motto: "TEN vowels? Don't you know vowels are scrd?")

- Linus Torvalds on linux-kernel