LWN: Comments on "A pair of Rust kernel modules" https://lwn.net/Articles/907685/ This is a special feed containing comments posted to the individual LWN article titled "A pair of Rust kernel modules". en-us Fri, 17 Oct 2025 04:31:09 +0000 Fri, 17 Oct 2025 04:31:09 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net A pair of Rust kernel modules https://lwn.net/Articles/958377/ https://lwn.net/Articles/958377/ yawaramin <div class="FormattedComment"> <span class="QuotedText">&gt; and yet, in Ada, you can not define type for day-of-month which is between 1 and 28 for February and 1 and 31 for January!</span><br> <p> Yes you can:<br> <p> ```<br> procedure Adaproj is<br> type Month is (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);<br> type Month_Day (M : Month) is record<br> case M is<br> when Sep | Apr | Jun | Nov =&gt;<br> Day1_30 : Integer range 1 .. 30;<br> when Feb =&gt;<br> Day1_29 : Integer range 1 .. 29;<br> when Jan | Mar | May | Jul | Aug | Oct | Dec =&gt;<br> Day1_31 : Integer range 1 .. 31;<br> end case;<br> end record;<br> begin<br> null;<br> end Adaproj;<br> ```<br> <p> Sure, it's not exactly trivial; but it's possible.<br> </div> Tue, 16 Jan 2024 13:56:53 +0000 A pair of Rust kernel modules https://lwn.net/Articles/909259/ https://lwn.net/Articles/909259/ nybble41 <div class="FormattedComment"> <font class="QuotedText">&gt; So either the function takes a const pointer to int (which is braindead) and the compiler is brain dead not to see its not modifiable</font><br> <p> Even if the function did take a const-qualified pointer, it wouldn&#x27;t matter. It&#x27;s perfectly legal to do something like this:<br> <p> void f(int const *p) { *(int*)p = 7; }<br> <p> ... as long as the original *object* was not const-qualified. (Attempting to write into a *variable* which was const-qualified at the point of declaration is, of course, undefined behavior, whether or not the pointer being used is const-qualified.) Consequently, the compiler can&#x27;t assume that the function won&#x27;t write into a mutable object even if the pointer argument is const-qualified.<br> <p> Also, the read-only pointer-to-int argument pattern isn&#x27;t quite so &quot;braindead&quot; as you suppose. These functions are generic; in this case the key happens to be an int, but that isn&#x27;t always true, and so the key is passed by reference rather than value. The comparison callback for the standard library&#x27;s qsort() function uses the same pattern, for example, when sorting an int array.<br> </div> Fri, 23 Sep 2022 18:04:28 +0000 A pair of Rust kernel modules https://lwn.net/Articles/909177/ https://lwn.net/Articles/909177/ adobriyan <div class="FormattedComment"> &quot;key&quot; should be pointer to const.<br> <p> BPF_CALL_4(bpf_map_update_elem,<br> struct bpf_map *, map,<br> void *, key,<br> void *, value,<br> u64, flags)<br> {<br> WARN_ON_ONCE(!rcu_read_lock_held() &amp;&amp; !rcu_read_lock_bh_held());<br> return map-&gt;ops-&gt;map_update_elem(map, key, value, flags);<br> }<br> </div> Fri, 23 Sep 2022 11:05:35 +0000 A pair of Rust kernel modules https://lwn.net/Articles/909171/ https://lwn.net/Articles/909171/ rep_movsd <div class="FormattedComment"> It looks like the id loop iterator is being passed by pointer to a function. <br> Why would a function need a primitive value passed in by pointer unless it intended to modify it?<br> <p> The compiler cannot guarantee that id doesnt change whilst you are looping.<br> <p> So either the function takes a const pointer to int (which is braindead) and the compiler is brain dead not to see its not modifiable<br> <p> OR <br> <p> The function takes it by pointer (which may be braindead) and the compiler is right<br> </div> Fri, 23 Sep 2022 09:56:53 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908820/ https://lwn.net/Articles/908820/ amarao <div class="FormattedComment"> For any pythoner c-style end of a function looks like wierd smiles too ); or ;}. And logic operations are terrible ! a&amp;&amp;b||c. Compare with not a and b or c.<br> <p> So when you mock rust for syntax, don&#x27;t forget about !!a&gt;&gt;b%c&amp;&amp;--d--.<br> </div> Tue, 20 Sep 2022 22:25:25 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908818/ https://lwn.net/Articles/908818/ amarao <div class="FormattedComment"> Wow. Do you use systems, or it&#x27;s in the evil camp too?<br> </div> Tue, 20 Sep 2022 22:09:15 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908555/ https://lwn.net/Articles/908555/ marcH <div class="FormattedComment"> LWN is probably the only site in the entire world where you can find people with expertise, writing skills, patience and willingness to politely answer impolite trolls by sharing knowledge badge-like articles - for free. It happens only on LWN but even on LWN it does not happen every time and a tiny bit of semi-automated moderation may not hurt. My 2c.<br> </div> Mon, 19 Sep 2022 03:24:10 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908545/ https://lwn.net/Articles/908545/ ras <div class="FormattedComment"> <font class="QuotedText">&gt; As a spectator in this discussion, I have to say that the antics of people like milesrout make me not want to read the comments section at all.</font><br> <p> As a counter point, I&#x27;ve enjoyed the discussion milesrout has created. Some of the replies have been excellent - the best I&#x27;ve seen on this subject anywhere on the web. They&#x27;re from people who clearly know the subject very well and also write clearly.<br> <p> I think that&#x27;s because they are passionate about the subject. They wear that passion on their sleeves, which I suspect is what you are objecting to - it&#x27;s not a dry &quot;authoritative&quot; academic treatment of the subject. Yes, that passion could easily drag the discussion into the weeds, but without the passion they would not of invested the time and effort needed to craft such replies.<br> <p> It&#x27;s difficult to argue passionately about something, while maintaining the disciplined needed to address the just subject and not the people delivering it. Yet, that is mostly what has been achieved here, in what is effectively an open forum. I put it down to corbet&#x27;s gentle steering. As other&#x27;s have said, he limited tools available. His most effective one seems to be leading by example.<br> </div> Mon, 19 Sep 2022 00:50:55 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908267/ https://lwn.net/Articles/908267/ flussence <div class="FormattedComment"> The system here isn&#x27;t perfect, or modern, and people often criticise it when there&#x27;s an angry mob thread like this, but to date I haven&#x27;t yet witnessed an angry mob directed *at* the moderation. That&#x27;s a better success rate than nearly every web forum I&#x27;ve used in the past 20-odd years.<br> <p> Incidentally a major subreddit became Main Character Of The Day on other social media this week for grotesque moderator overreach. I would say the reddit/voat/8chan/urbit model of expendable community and digital royalty built atop it has produced some of the worst results. That website has trench lines by the hundred and the tools are designed to only escalate.<br> </div> Fri, 16 Sep 2022 12:01:21 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908265/ https://lwn.net/Articles/908265/ flussence <div class="FormattedComment"> <font class="QuotedText">&gt; The entire idea is horrible. I do not want a Rust compiler on my computer, I do not want to need a Rust compiler on my computer to be able to compile the kernel.</font><br> <p> Simply write a better language with measurably lower defects per hour invested and then people will use it.<br> <p> This isn&#x27;t rocket science (according to you), but it *is* science. Not religion. Code talks, bullshit walks, see you when you&#x27;ve done the work.<br> </div> Fri, 16 Sep 2022 11:26:31 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908253/ https://lwn.net/Articles/908253/ Wol <div class="FormattedComment"> Or bpf could take fortran to heart, and the definition in the spec that says &quot;for loops do not guarantee that modifications to the index variable will &quot;stick&quot;&quot;.<br> <p> The standard explicitly permits moving the index into a register (which other code has no access to) and then it saves it to the variable whenever it increments or other fancy tricks. <br> <p> Whatever, as far as the code *inside* the loop is concerned, the index variable is either read-only, or if you do try and modify it, it&#x27;s undefined.<br> <p> So, provided the naive loop terminates, you can guarantee that any loop will terminate.<br> <p> Cheers,<br> Wol<br> </div> Fri, 16 Sep 2022 09:22:45 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908252/ https://lwn.net/Articles/908252/ nybble41 <div class="FormattedComment"> <font class="QuotedText">&gt; Earlier this year I had a persistent failure getting this to verify (under 5.16): …</font><br> <p> Strictly speaking, without taking into account knowledge of the internals of bpf_map_update_elem(), that loop might *not* terminate. You&#x27;re passing in a pointer to the loop counter (id) and the function could potentially update the variable via that pointer to prevent it from incrementing. (Yes, even if the pointer argument is const-qualified; you can cast away the const qualifier on a pointer with const_cast as long you&#x27;re not trying to store into a const object, and the variable id in this example isn&#x27;t a const object.)<br> <p> It would probably compile if you copied id into a separate local variable and passed a pointer to that variable to bpf_map_update_elem(). Then the compiler could easily prove that the function doesn&#x27;t update id since it doesn&#x27;t have its address (given the standard pointer provenance rules), which places a fixed upper bound on the number of loop iterations.<br> </div> Fri, 16 Sep 2022 08:51:45 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908240/ https://lwn.net/Articles/908240/ edomaur <div class="FormattedComment"> Also, an idea would be to add a &quot;cooling down&quot; timer to subtrees selection of discussions, with a visual marker to signal that there is delayed posting enforced in that part of the comments. This can be also linked with a moderator message (typically one &quot;please refrain...&quot; from our favorite editor in chief)<br> </div> Fri, 16 Sep 2022 05:04:26 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908236/ https://lwn.net/Articles/908236/ milesrout <div class="FormattedComment"> <font class="QuotedText">&gt; With no mechanism to counteract this, it&#x27;s unsurprising it keeps happening. Softer measures like hiding, collapsing or locking a thread, sending it to the bottom of the sort order, showing limited reply depth or rate limiting back and forth replies are probably more effective there than hardline moderation.</font><br> <p> And what would be the grounds for doing this? Is this JUST for criticism of Rust? Or does it include a broader category of messages than that?<br> <p> In my opinion there is no issue. The discussion isn&#x27;t even heated. I made a SINGLE comment and was immediately accused of trolling. It seems to me that ANY criticism of Rust immediately gets labelled as trolling. Yet lots of topics covered here are contentious and prompt back-and-forth discussions that often are not particularly productive. Only criticism of Rust seems to get immediately labelled as trolling, as far as I can see. <br> <p> <p> </div> Fri, 16 Sep 2022 03:32:13 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908206/ https://lwn.net/Articles/908206/ Wol <div class="FormattedComment"> <font class="QuotedText">&gt; On one hand, a UB-less C would be &quot;safer&quot;, but its portability would tank because &quot;it worked on my x86_64&quot; means diddly squat when you compile it for aarch64.</font><br> <p> You&#x27;ve missed &quot;implementation defined&quot; and &quot;hardware defined&quot;.<br> <p> If something is &quot;hardware defined&quot; then yes, just because it works on x86_64, you can&#x27;t expect the SAME code to work on aarch64, but firstly the programmer will KNOW that they need to check behaviour, and secondly they can put the ifdefs and whatever in there, and know that that IS DEFINED behaviour.<br> <p> The *only* grounds for UB should be because &quot;we can&#x27;t define it because we can&#x27;t get the logic to add up&quot;. There&#x27;s no need for the C/C++ standard to define everything itself - it can defer the definition to something else - but all behaviour should be defined *somewhere*, if a definition is possible.<br> <p> Take for example the size of a byte. In *PRACTICE* it&#x27;s always 8-bit nowadays. I wouldn&#x27;t be surprised if it&#x27;s actually already implementation or hardware defined, but that&#x27;s a perfect example of something that makes perfect sense as hardware-defined. In places, bytes are 6 bits, and if the programmer doesn&#x27;t account for it it will cause a major problem if they&#x27;re targetting an old platform. But the standard CAN, and SHOULD, address it.<br> <p> Cheers,<br> Wol<br> </div> Thu, 15 Sep 2022 22:33:26 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908200/ https://lwn.net/Articles/908200/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; I wonder how that stance turned into “if standard says something is undefined behavior then we have the carte blanche to destroy the program” and then “if standard doesn&#x27;t say something is undefined behavior yet then we have the permission to destroy your program anyway”.</font><br> <p> Portability I would guess. Once more than one compiler could target a given platform (or one compiler could target more than one platform), &quot;my compiler/platform is better than yours&quot; creeps in and you start down the path of &quot;what kinds of optimizations can we squeeze out here?&quot; come up.<br> <p> Today? Code that is written to work on multiple platforms from the same source. Here, the compiler saying &quot;well, if it were $obscure_arch, this is different behavior, so we&#x27;ll show it to you on your machine via UB-based optimizations (but not make any noise about it either)&quot;.<br> <p> On one hand, a UB-less C would be &quot;safer&quot;, but its portability would tank because &quot;it worked on my x86_64&quot; means diddly squat when you compile it for aarch64.<br> </div> Thu, 15 Sep 2022 21:35:16 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908193/ https://lwn.net/Articles/908193/ thecodedmessage <div class="FormattedComment"> This poster is saying some true things in a loaded way to make them seem bad when they&#x27;re actually reasonable. Rust is a tool, and it can&#x27;t do everything that people sometimes carelessly claim about it. But that doesn&#x27;t mean C++ is just as good, or that Rust experts make these claims.<br> <p> Rust does not eliminate all bugs. It&#x27;s true that Rust&#x27;s safety features only prevent the behaviors that they&#x27;re designed to prevent. Of course that&#x27;s true -- no programming language can prevent all bugs, but Rust&#x27;s safety features do prevent some very bad types of memory corruption that are infamous for causing problems in C and C++. Additionally, even &#x27;unsafe&#x27; Rust does a better job at preventing those failures than C++, which in many cases doesn&#x27;t even give you any tools to manage the problem, relying instead entirely on the programmer.<br> <p> And yes, they tried to eliminate memory leaks in safe code and then realized that wasn&#x27;t an achievable goal in line with their other goals. That doesn&#x27;t mean that Rust is bad. Rust is much better at preventing memory leaks than C++, but it is still possible to leak memory. It&#x27;s way harder to do by accident, though.<br> <p> Rust is better than C++. The fact that it&#x27;s not utopian or perfect doesn&#x27;t mean that it&#x27;s not better.<br> </div> Thu, 15 Sep 2022 21:13:53 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908199/ https://lwn.net/Articles/908199/ nix <div class="FormattedComment"> No, but the problem was the *verifier*, not the input language. The same sort of thing written in raw eBPF was also rejected. (It worked if the loop bound was &lt; 4. How... useful.)<br> <p> Figuring out why required diving into the verifier source code, because there is of course nothing like a spec, and the verifier&#x27;s verification contains enough holes where obviously valid code is rejected out of hand because nobody&#x27;s written code to verify it (if you&#x27;re lucky, there are comments noting the lack of said verification) that it frankly should be called a collection of holes with a little fabric connecting them :)<br> </div> Thu, 15 Sep 2022 21:13:42 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908192/ https://lwn.net/Articles/908192/ khim <p>But the thing is: this is what was supposed to happen with C and C++, too! Except for safe subset, but otherwise it was planned like that.</p> <p>I mean… the <a href="https://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf">Rationale for International Standard— Programming Languages— C</a> says: <i><b>Undefined behavior</b> gives the implementor license not to catch certain program errors that are difficult to diagnose. It also identifies areas of possible conforming language extension: <b>the implementor may augment the language by providing a definition of the officially undefined behavior</b>.</i></p> <p>This is your <i>Tower of Weakenings</i> right there!</p> <p>Note that before C89 was punished it <b>actually</b> worked that way: there was no standard but different implementations permitted different things and even if some were not so easy to implement (e.g. one-element-past-the-end-of-array means it becomes impossible to have simple 64KiB arrays on MS-DOS) they were added to standard where it made sense.</p> <p>I wonder how that stance turned into “if standard says something is undefined behavior then we have the carte blanche to destroy the program” and then “if standard doesn't say something is undefined behavior <b>yet</b> then we have the permission to destroy your program <b>anyway</b>”.</p> <p>I don't think there was some evil mastermind behind all these developments, but the end result sure is complete lack of trust.</p> <p>Periodic Linus outbursts and public complaints is <b>not</b> how you plan development of language which is used by millions!</p> Thu, 15 Sep 2022 20:19:47 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908190/ https://lwn.net/Articles/908190/ rahulsundaram <div class="FormattedComment"> <font class="QuotedText">&gt; And it has never been really intended as a systems language</font><br> <p> Yep, it hasn&#x27;t advertised as one. Aside from the web arena, tools like Puppet or Chef uses it but that&#x27;s quite different from being a systems language. <br> </div> Thu, 15 Sep 2022 19:39:34 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908189/ https://lwn.net/Articles/908189/ rahulsundaram <div class="FormattedComment"> <font class="QuotedText">&gt; Solid? Earlier this year I had a persistent failure getting this to verify (under 5.16):</font><br> <p> Have you tried the Rust ones? https://aya-rs.dev/ or <a href="https://crates.io/crates/bcc">https://crates.io/crates/bcc</a><br> </div> Thu, 15 Sep 2022 19:37:00 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908187/ https://lwn.net/Articles/908187/ Wol <div class="FormattedComment"> <font class="QuotedText">&gt; But somehow in XXI century all that went out of the window. We can only hope Rust wouldn&#x27;t repeat the same mistake.</font><br> <p> As I&#x27;ve said before, the C/C++ standards committee should be removing undefined behaviour. Placing the onus on the compiler writers to provide implementation-defined behaviour. Saying it&#x27;s &quot;whatever the hardware does&quot;. Whatever whatever but getting rid of all that crap.<br> <p> And then there are things you can&#x27;t define for whatever reason, where you admit that a definition is impossible.<br> <p> The thing is, Rust has all three of those, and it clearly pigeonholes them. Safe Rust is supposedly *only* *defined* behaviour. And if undefined behaviour creeps into safe code it is defined as a BUG, a MUST-FIX.<br> <p> I guess all that &quot;hardware defined&quot; stuff probably belongs in the &quot;unsafe Rust&quot; category, where the language can&#x27;t reason because it doesn&#x27;t have any idea what&#x27;s going to happen behind its back.<br> <p> And then there&#x27;s the stuff you can&#x27;t define, which is unsound, because there&#x27;s some fault in the logic somewhere.<br> <p> The important thing is, the programmer can REASON about all this lot, unlike C, where hardware behaviour triggers &quot;undefined behaviour&quot;, and the C compiler makes a whole bunch of false assumptions and screws up your code (like deleting necessary safety checks, etc etc).<br> <p> Cheers,<br> Wol<br> </div> Thu, 15 Sep 2022 19:34:30 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908185/ https://lwn.net/Articles/908185/ nix <blockquote> The easy way to get C++ code into the kernel is via eBPF, which offers solid support for building from C++ </blockquote> Solid? Earlier this year I had a persistent failure getting <i>this</i> to verify (under 5.16): <pre> uint32_t id;mp; dt_bpf_specs_t zero; __builtin_memset(&amp;zero, 0, sizeof (dt_bpf_specs_t)); for (id = 1; id &lt;= 16; id++) { if (bpf_map_update_elem(&amp;specs, &amp;id, &amp;zero, BPF_NOEXIST) == 0) return id; } </pre> A simple loop updating sixteen map values to 0 was rejected... because the verifier could not prove that this incredibly subtle and difficult loop would terminate. (I unrolled it, and everything was fine.) <p> Trying to write nontrivial C++ code and expecting it to turn to working eBPF without massive amounts of verifier agony is an exercise in futility at present. You can try if you like, but I wouldn't want to listen to the resulting cursing if you did. (Maybe this will change in time, but I very much suspect that turning the verifier into something that isn't full of arbitrary restrictions and can actually verify real code that wasn't written with 90% of one's attention on contorting things in unnatural ways to get it to verify will either slow it to unusability or just slam straight into the wall of Rice's theorem.) Thu, 15 Sep 2022 19:14:02 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908183/ https://lwn.net/Articles/908183/ Cyberax <div class="FormattedComment"> <font class="QuotedText">&gt; Using Ada&#x27;s formal verification subset (SPARK)</font><br> <p> SPARK doesn&#x27;t support dynamically allocated objects well: <a href="https://docs.adacore.com/spark2014-docs/html/ug/en/source/language_restrictions.html#memory-ownership-policy">https://docs.adacore.com/spark2014-docs/html/ug/en/source...</a><br> <p> It&#x27;s similar to Rust without lifetime annotations and with less static analysis for stack objects.<br> <p> There are academic papers that try to fix that, but the outcome would basically look like Rust.<br> </div> Thu, 15 Sep 2022 19:10:23 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908168/ https://lwn.net/Articles/908168/ Cyberax <div class="FormattedComment"> <font class="QuotedText">&gt; Not directly for the kernel in fact, rather for the language&#x27;s life expectancy. 15 years ago I was told that Ruby was *the* language of the future, that prevented bugs etc...</font><br> <p> Ruby has been overshadowed by Go and JS now that most complex webapps have frontends in JavaScript and the backend just provides a REST API. But back in the day, Ruby allowed tons of small companies to quickly build decent applications and get to market with them.<br> <p> This list includes GitHub, AirBnB, Groupon, Zillow and many others. The company where I work is built on top of a Ruby app as well. <br> <p> So it&#x27;s fair to say that Ruby absolutely fulfilled its promise in the area of web apps. And it has never been really intended as a systems language or a language for desktop applications.<br> </div> Thu, 15 Sep 2022 19:02:53 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908174/ https://lwn.net/Articles/908174/ marcH <div class="FormattedComment"> <font class="QuotedText">&gt; Softer measures like hiding, collapsing or locking a thread, sending it to the bottom of the sort order, showing limited reply depth or rate limiting back and forth replies are probably more effective there than hardline moderation.</font><br> <p> This.<br> <p> Surprise, surprise, &quot;analog&quot; problems rarely ever have binary solutions (unless of course you read social media).<br> <p> <p> </div> Thu, 15 Sep 2022 18:03:54 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908111/ https://lwn.net/Articles/908111/ farnz <p>Two concrete proposals: <ol> <li>Have the editors able to "flag" a post and all its children as problematic, which results in the thread content being hidden by default, and require readers to click through to read each flagged post in turn. This is a weaker form of deletion. <li>Support delayed posting, with the minimum required delay set by the editors for replies to any post or its children, and also something that can be set on an individual account - the delay applicable at any point in the thread is the maximum delay of all of its parent posts. This means that when I hit "Post comment", instead of it actually posting, it enters a "quarantine" state, and I have to come back to the thread to release the comment from quarantine at a later time. This is a weaker form of blocking. </ol> <p>The idea behind the first option is to reduce the visibility of overheated threads, allowing you to indicate that you think that a given thread is non-productive (and discouraging people from either reading it or replying to it). The idea behind the second is to let you use time to cool off a thread that's become heated, or to increase the effort trolls and abusers have to put into actually being seen. <p>Finally, when I killfile a user, I should have the option to not only killfile that user, but also all immediate replies to them; that way, if I killfile a user who's good at trolling, I don't see the replies that they successfully troll for (but I do see the replies to replies, which may be interesting tangents from the troll). Thu, 15 Sep 2022 13:24:07 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908115/ https://lwn.net/Articles/908115/ farnz <p>The really nice thing about the Tower of Weakenings approach is that Rust is now able to have several layers of rules for provenance. Strict provenance is guaranteed to be correct for all implementations of Rust on all hardware that can support Rust; but because you have this portable set of rules, it's now possible to define rules like "for Rust on AArch64" or "for single-threaded Rust programs" that only apply if you're a special case. <p>In C and C++ standard terms, this has "strict provenance" as the rules that must apply, while permitting implementations to define relaxations of strict provenance that they will also accept as valid. Thu, 15 Sep 2022 13:03:55 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908079/ https://lwn.net/Articles/908079/ ssmith32 <div class="FormattedComment"> Just throwing ideas out: if you ask someone to be an adult more than X times in window Y + random episilon, put them in a cooling off queue - not necessarily a ban, just slow the rate of posts, to a stop, and then ramp back up (assuming no more adult warnings)<br> <p> It could be automated - other than ticking an &quot;adult warning&quot; on your post. The randomness is to prevent gaming - keeps you wondering if this time is the one.<br> <p> I know, a bit naive, just thinking what would help me when I get too troll-y. Particularly in my younger years - I&#x27;d like to think I&#x27;m older and wiser then when I joined. Because I&#x27;m definitely older ;)<br> </div> Thu, 15 Sep 2022 07:05:56 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908073/ https://lwn.net/Articles/908073/ rsidd <div class="FormattedComment"> Sorry for misunderstanding.<br> </div> Thu, 15 Sep 2022 00:50:01 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908067/ https://lwn.net/Articles/908067/ NYKevin <div class="FormattedComment"> That was not anti-Rust, it was anti-anti-Rust. It was in reply to someone who (wrongly) claimed that Rust&#x27;s safety model was broken because it fails to prevent memory leaks. I was pointing out that Rust never claimed to do this in the first place, and that it makes no sense to assert otherwise. You may disagree with my reasoning, but please do not mischaracterize my position.<br> </div> Wed, 14 Sep 2022 22:28:58 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908065/ https://lwn.net/Articles/908065/ NYKevin <div class="FormattedComment"> Was it absolutely necessary to post two different replies both (essentially) saying the same thing? Especially considering that, as another commenter pointed out, mem::forget is significantly older, so your argument is not even correct.<br> </div> Wed, 14 Sep 2022 22:25:55 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908057/ https://lwn.net/Articles/908057/ khim <font class="QuotedText">&gt; I can say that I've seen a lot more work in the free software world to incrementally port portions of software to Rust, such as the original motivating example of Firefox, librsvg, curl, and this work in the Linux kernel, than I have in Ada.</font> <p>The biggest problem of Ada IMO is that it was always supposed to be about safety, but it never addressed the most common source of bugs: pointer safety. Not even with SPARK. It's like discussing about how can you fortify the door in a house with three walls. I <i>suspect</i> they planned to solve it like everyone else (with tracing GC), but that never materialised (because most Ads users don't want tracing GC) thus was always kinda weird “safe” language which doesn't tackle the most common source of bugs.</p> <p>Finally, in year 2020, it <a href="https://blog.adacore.com/using-pointers-in-spark">solved that problem</a>. By picking ideas from Rust, of course.</p> <p>But by that time momentum was lost and it would be very hard to overcome that “safe language without safety” stigma.</p> <p>In addition Ada very much likes to live in the world where it can dictate the rules thus Rust is much more suitable for the kernel IMO.</p> <font class="QuotedText">&gt; The mindshare in Ada seems to mostly be around safety-critical systems, while Rust seems to appeal to free software developers more as a general purpose programming language, which provides some better guarantees out of the box than C or C++ do, even when not doing a full formal verification process for safety critical systems.</font> <p>It would be interesting to see how well <a href="https://ferrous-systems.com/blog/ferrocene-update-three-the-road/">Rust would do there</a>. I'm not sure Rust would be able to push Ada from that niche, but it's also highly unlikely that Ada would be able to go into general-purpose computing.</p> <p>Mindsets of Ada programmers and general-purpose computing programmers are just too different.</p> <font class="QuotedText">&gt; If anyone has writeups on why Ada would be good for this kind of use case, I'd love to see them.</font> <p>It wouldn't. Ada provides some additional facilities which Rust doesn't provide (such as range types), but these are not <a href="https://en.wikipedia.org/wiki/Dependent_type">dependent types</a> which are needed to express safety and thus add bloat to the language without improving safety much.</p> <p>This about it: the most famous example of range types are months and days… and yet, in Ada, you can not define type for day-of-month which is between 1 and 28 for February and 1 and 31 for January!</p> Wed, 14 Sep 2022 22:02:25 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908042/ https://lwn.net/Articles/908042/ Dr-Emann For anyone <em>actually</em> trying to parse the signal type, it helps a lot to have a <a href="https://man7.org/linux/man-pages/man2/signal.2.html">typedef</a>: <pre> typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); </pre> The equivalent in rust is still pretty readable without a typedef: <pre> fn signal(signum: c_int, handler: fn(int)) -&gt; fn(int) </pre> Wed, 14 Sep 2022 19:33:27 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908043/ https://lwn.net/Articles/908043/ ssokolow <div class="FormattedComment"> The fact that the Clockwise/Spiral rule exists, and that I&#x27;ve had to look at this page more than once over the years, seems to disagree.<br> <p> https://c-faq.com/decl/spiral.anderson.html<br> <p> I never had to refresh my memory of how Rust type signatures worked back in the days before I started using it actively.<br> </div> Wed, 14 Sep 2022 19:27:48 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908027/ https://lwn.net/Articles/908027/ atnot <div class="FormattedComment"> <font class="QuotedText">&gt; Assuming we had the time and stomach to go deleting/blocking posts, what are the criteria we should use?</font><br> <p> My opinion is that a large part of the problem is that those two, very blunt weapons are the only ones available. It means that as long as one nominally follows the rules[1], one is completely free to (deliberately or accidentally) abuse LWNs perverse feedback loops to derail discussions: Write the most incendiary thing you think you can get away with, get it as far up the page as possible by being early, fight with every reply and watch your discussion take up vertical space on the page until nobody has the patience to scroll past it to read anything more substantive anymore. At that point you have won by being the loudest and stop replying to avoid getting chastized by Your Editor.<br> <p> With no mechanism to counteract this, it&#x27;s unsurprising it keeps happening. Softer measures like hiding, collapsing or locking a thread, sending it to the bottom of the sort order, showing limited reply depth or rate limiting back and forth replies are probably more effective there than hardline moderation.<br> <p> <font class="QuotedText">&gt; Most of the time, asking LWN readers to behave like adults works; I&#x27;m not sure what to do in cases where it doesn&#x27;t. </font><br> <p> I think it&#x27;s remarkable how well this works, all things considered.<br> <p> [1] <a href="https://eev.ee/blog/2016/07/22/on-a-technicality/">https://eev.ee/blog/2016/07/22/on-a-technicality/</a><br> </div> Wed, 14 Sep 2022 19:21:24 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908024/ https://lwn.net/Articles/908024/ lambda <div class="FormattedComment"> <font class="QuotedText">&gt; Feel free to check when that function was added</font><br> <p> mem::forget was the original variant of this, and it was stabilized as safe pre-1.0 <a href="https://doc.rust-lang.org/std/mem/fn.forget.html">https://doc.rust-lang.org/std/mem/fn.forget.html</a> . It was originally marked as unsafe (in earlier pre-1.0 releases), but when it was realized that safety invariants couldn&#x27;t depend on destructors being guaranteed to run, it was changed to be marked as safe in order to make that point more clear.<br> <p> Box::leak is just a newer variant that provides a nicer API, allowing you to extract a reference to the leaked value at the same time.<br> <p> It was always known that it was possible to leak memory by forming a reference counted pointer cycle, but it was fairly late in the pre-1.0 process that folks realized the interaction between this fact, and some proposed APIs that required blocking in a destructor in order to keep a stack frame alive, were incompatible. There was a long and reasoned discussion about it, and the Rust team decided that because it&#x27;s not possible to categorically prevent resource exhaustion in a Turing complete language, that it was better to have the rules for what could be done in safe code include leaking memory (or otherwise failing to run destructors), and then code that provides safe abstractions has to keep that in mind, so you couldn&#x27;t rely on blocking in a destructor to keep a stack frame alive.<br> <p> It took some time in the development of Rust to figure out what the rules should be for what is marked as &quot;safe&quot; vs &quot;unsafe&quot;; you might imagine that any kind of undesirable behavior, like memory leaks, should be considered unsafe. But the distinction that the Rust project ended up on, and I think is the right decision, is that unsafe is only required for operations which could lead to undefined behavior. Rust provides tools to help prevent other kinds of undesirable behavior, like destructors that free memory for you when exiting a stack frame, but it won&#x27;t refuse to compile code in which you set up a reference cycle and thus leak memory, as the behavior in that case is perfectly well defined, you just use more resources and may eventually run out.<br> <p> Does this make sense to you? I feel like you are implying that there has been some massive rug-pull about what safety guarantees Rust provides, while Rust never guaranteed freedom from resource exhaustion, and during the run-up to 1.0 there was some learning about exactly the kind of guarantees you could make about when destructors were run, and some updates to the understanding of what unsafe code could rely on based on that and some engineering tradeoffs. If I&#x27;m misunderstanding your implication, or not explaining this clearly enough, let me know!<br> </div> Wed, 14 Sep 2022 17:14:04 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908021/ https://lwn.net/Articles/908021/ khim <font class="QuotedText">&gt; In C, the declaration and use syntax are almost exactly the same. Once you know one, you know the other.</font> <p>And in LISP it's even more uniform thus easier, right? Everyone uses lisp, right? No? Not everyone? But why?</p> <p>Think about it.</p> <font class="QuotedText">&gt; It's almost exactly the same as calling it.</font> <p>If you forget about the fact that for function which returns function (like already mentioned <a href="https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html">void (*signal(int, void (*)(int)))(int)</a>) it doesn't work. That function have two arguments yet ends with <code>(int)</code> somehow. And about the fact that standalone variable declared as <code>int x[3];</code> has entirely different type from argument of function declared in the same fashion. And about bazillion other similar quirks.</p> <p>Yes, C is simple if you ignore details. Which invariably bites you in the ass later. While Rust makes sure you wouldn't forget about details.</p> <p>Yes, it's different strategy, but it works much better for the large or huge projects where hundreds or thousands people work on the same codebase.</p> Wed, 14 Sep 2022 16:15:56 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908018/ https://lwn.net/Articles/908018/ lambda <div class="FormattedComment"> <font class="QuotedText">&gt; Ada/C interoperability is on par with Rust/C interoperability as far as I can tell (not a Rust expert).</font><br> <p> Fair enough! I&#x27;m not an Ada expert either, so I can&#x27;t necessarily speak to how the approaches compare.<br> <p> I can say that I&#x27;ve seen a lot more work in the free software world to incrementally port portions of software to Rust, such as the original motivating example of Firefox, librsvg, curl, and this work in the Linux kernel, than I have in Ada. The mindshare in Ada seems to mostly be around safety-critical systems, while Rust seems to appeal to free software developers more as a general purpose programming language, which provides some better guarantees out of the box than C or C++ do, even when not doing a full formal verification process for safety critical systems.<br> <p> I&#x27;d love to see examples where Ada has been used successfully to rewrite parts of free software to improve safety or maintainability, let me know if you know of any!<br> <p> My comments about Ada were mostly to respond to why Rust over Ada or other static analysis tools, and while I don&#x27;t know Ada well enough to do a detailed comparison, there just seems to be a lot more interest in using Rust for these kinds of use cases than Ada. If anyone has writeups on why Ada would be good for this kind of use case, I&#x27;d love to see them.<br> </div> Wed, 14 Sep 2022 16:08:30 +0000 A pair of Rust kernel modules https://lwn.net/Articles/908017/ https://lwn.net/Articles/908017/ rschroev <div class="FormattedComment"> Try printing to PDF first (Windows nowadays has a built-in virtual printer for that), then printing out that PDF. That workaround can sometimes work wonders for applications that don&#x27;t handle printers and their quirks very well.<br> <p> It&#x27;s sad of course that workaround like this are needed for any application, and double (or more) so for a high-profile word processor.<br> </div> Wed, 14 Sep 2022 15:42:18 +0000