mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Martin Uecker <uecker@tugraz.at>
To: Ralf Jung <post@ralfj.de>, Ventura Jack <venturajack85@gmail.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
	Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
	Gary Guo <gary@garyguo.net>,
	 torvalds@linux-foundation.org, airlied@gmail.com,
	boqun.feng@gmail.com,  david.laight.linux@gmail.com, ej@inai.de,
	gregkh@linuxfoundation.org,  hch@infradead.org, hpa@zytor.com,
	ksummit@lists.linux.dev,  linux-kernel@vger.kernel.org,
	rust-for-linux@vger.kernel.org
Subject: Re: C aggregate passing (Rust kernel policy)
Date: Wed, 26 Feb 2025 20:07:22 +0100	[thread overview]
Message-ID: <dd28fe6e2c174f605a104723a5ab8d5445fe8002.camel@tugraz.at> (raw)
In-Reply-To: <f3a83d60-3506-4e20-b202-ef2ea99ef4dc@ralfj.de>

Am Mittwoch, dem 26.02.2025 um 17:32 +0100 schrieb Ralf Jung:
> Hi VJ,
> 
> > > 
> > > > - Rust has not defined its aliasing model.
> > > 
> > > Correct. But then, neither has C. The C aliasing rules are described in English
> > > prose that is prone to ambiguities and misintepretation. The strict aliasing
> > > analysis implemented in GCC is not compatible with how most people read the
> > > standard (https://bugs.llvm.org/show_bug.cgi?id=21725). There is no tool to
> > > check whether code follows the C aliasing rules, and due to the aforementioned
> > > ambiguities it would be hard to write such a tool and be sure it interprets the
> > > standard the same way compilers do.
> > > 
> > > For Rust, we at least have two candidate models that are defined in full
> > > mathematical rigor, and a tool that is widely used in the community, ensuring
> > > the models match realistic use of Rust.
> > 
> > But it is much more significant for Rust than for C, at least in
> > regards to C's "restrict", since "restrict" is rarely used in C, while
> > aliasing optimizations are pervasive in Rust. For C's "strict aliasing",
> > I think you have a good point, but "strict aliasing" is still easier to
> > reason about in my opinion than C's "restrict". Especially if you
> > never have any type casts of any kind nor union type punning.
> 
> Is it easier to reason about? At least GCC got it wrong, making no-aliasing 
> assumptions that are not justified by most people's interpretation of the model:
> https://bugs.llvm.org/show_bug.cgi?id=21725
> (But yes that does involve unions.)

Did you mean to say LLVM got this wrong?   As far as I know,
the GCC TBBA code is more correct than LLVMs.  It gets 
type-changing stores correct that LLVM does not implement.

> 
> > > > - The aliasing rules in Rust are possibly as hard or
> > > >      harder than for C "restrict", and it is not possible to
> > > >      opt out of aliasing in Rust, which is cited by some
> > > >      as one of the reasons for unsafe Rust being
> > > >      harder than C.
> > > 
> > > That is not quite correct; it is possible to opt-out by using raw pointers.
> > 
> > Again, I did have this list item:
> > 
> > - Applies to certain pointer kinds in Rust, namely
> >      Rust "references".
> >      Rust pointer kinds:
> >      https://doc.rust-lang.org/reference/types/pointer.html
> > 
> > where I wrote that the aliasing rules apply to Rust "references".
> 
> Okay, fair. But it is easy to misunderstand the other items in your list in 
> isolation.
> 
> > 
> > > >      the aliasing rules, may try to rely on MIRI. MIRI is
> > > >      similar to a sanitizer for C, with similar advantages and
> > > >      disadvantages. MIRI uses both the stacked borrow
> > > >      and the tree borrow experimental research models.
> > > >      MIRI, like sanitizers, does not catch everything, though
> > > >      MIRI has been used to find undefined behavior/memory
> > > >      safety bugs in for instance the Rust standard library.
> > > 
> > > Unlike sanitizers, Miri can actually catch everything. However, since the exact
> > > details of what is and is not UB in Rust are still being worked out, we cannot
> > > yet make in good conscience a promise saying "Miri catches all UB". However, as
> > > the Miri README states:
> > > "To the best of our knowledge, all Undefined Behavior that has the potential to
> > > affect a program's correctness is being detected by Miri (modulo bugs), but you
> > > should consult the Reference for the official definition of Undefined Behavior.
> > > Miri will be updated with the Rust compiler to protect against UB as it is
> > > understood by the current compiler, but it makes no promises about future
> > > versions of rustc."
> > > See the Miri README (https://github.com/rust-lang/miri/?tab=readme-ov-file#miri)
> > > for further details and caveats regarding non-determinism.
> > > 
> > > So, the situation for Rust here is a lot better than it is in C. Unfortunately,
> > > running kernel code in Miri is not currently possible; figuring out how to
> > > improve that could be an interesting collaboration.
> > 
> > I do not believe that you are correct when you write:
> > 
> >      "Unlike sanitizers, Miri can actually catch everything."
> > 
> > Critically and very importantly, unless I am mistaken about MIRI, and
> > similar to sanitizers, MIRI only checks with runtime tests. That means
> > that MIRI will not catch any undefined behavior that a test does
> > not encounter. If a project's test coverage is poor, MIRI will not
> > check a lot of the code when run with those tests. Please do
> > correct me if I am mistaken about this. I am guessing that you
> > meant this as well, but I do not get the impression that it is
> > clear from your post.
> 
> Okay, I may have misunderstood what you mean by "catch everything". All 
> sanitizers miss some UB that actually occurs in the given execution. This is 
> because they are inserted in the pipeline after a bunch of compiler-specific 
> choices have already been made, potentially masking some UB. I'm not aware of a 
> sanitizer for sequence point violations. I am not aware of a sanitizer for 
> strict aliasing or restrict. I am not aware of a sanitizer that detects UB due 
> to out-of-bounds pointer arithmetic (I am not talking about OOB accesses; just 
> the arithmetic is already UB), or UB due to violations of "pointer lifetime end 
> zapping", or UB due to comparing pointers derived from different allocations. Is 
> there a sanitizer that correctly models what exactly happens when a struct with 
> padding gets copied? The padding must be reset to be considered "uninitialized", 
> even if the entire struct was zero-initialized before. Most compilers implement 
> such a copy as memcpy; a sanitizer would then miss this UB.

Note that reading padding bytes in C is not UB. Regarding
uninitialized variables, only automatic variables whose address
is not taken is UB in C.   Although I suspect that compilers
have compliance isues here.

But yes, it sanitizers are still rather poor.

Martin

> 
> In contrast, Miri checks for all the UB that is used anywhere in the Rust 
> compiler -- everything else would be a critical bug in either Miri or the compiler.
> But yes, it only does so on the code paths you are actually testing. And yes, it 
> is very slow.
> 
> Kind regards,
> Ralf
> 


  parent reply	other threads:[~2025-02-26 19:07 UTC|newest]

Thread overview: 194+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-22 10:06 Ventura Jack
2025-02-22 14:15 ` Gary Guo
2025-02-22 15:03   ` Ventura Jack
2025-02-22 18:54     ` Kent Overstreet
2025-02-22 19:18       ` Linus Torvalds
2025-02-22 20:00         ` Kent Overstreet
2025-02-22 20:54           ` H. Peter Anvin
2025-02-22 21:22             ` Kent Overstreet
2025-02-22 21:46               ` Linus Torvalds
2025-02-22 22:34                 ` Kent Overstreet
2025-02-22 23:56                   ` Jan Engelhardt
2025-02-22 22:12               ` David Laight
2025-02-22 22:46                 ` Kent Overstreet
2025-02-22 23:50               ` H. Peter Anvin
2025-02-23  0:06                 ` Kent Overstreet
2025-02-22 21:22             ` Linus Torvalds
2025-02-23 15:30         ` Ventura Jack
2025-02-23 16:28           ` David Laight
2025-02-24  0:27           ` Gary Guo
2025-02-24  9:57             ` Ventura Jack
2025-02-24 10:31               ` Benno Lossin
2025-02-24 12:21                 ` Ventura Jack
2025-02-24 12:47                   ` Benno Lossin
2025-02-24 16:57                     ` Ventura Jack
2025-02-24 22:03                       ` Benno Lossin
2025-02-24 23:04                         ` Ventura Jack
2025-02-25 22:38                           ` Benno Lossin
2025-02-25 22:47                             ` Miguel Ojeda
2025-02-25 23:03                               ` Benno Lossin
2025-02-24 12:58           ` Theodore Ts'o
2025-02-24 14:47             ` Miguel Ojeda
2025-02-24 14:54               ` Miguel Ojeda
2025-02-24 16:42                 ` Philip Herron
2025-02-25 15:55                   ` Ventura Jack
2025-02-25 17:30                     ` Arthur Cohen
2025-02-26 11:38               ` Ralf Jung
2025-02-24 15:43             ` Miguel Ojeda
2025-02-24 17:24               ` Kent Overstreet
2025-02-25 16:12           ` Alice Ryhl
2025-02-25 17:21             ` Ventura Jack
2025-02-25 17:36               ` Alice Ryhl
2025-02-25 18:16                 ` H. Peter Anvin
2025-02-25 20:21                   ` Kent Overstreet
2025-02-25 20:37                     ` H. Peter Anvin
2025-02-26 13:03                     ` Ventura Jack
2025-02-26 13:53                       ` Miguel Ojeda
2025-02-26 14:07                         ` Ralf Jung
2025-02-26 14:26                         ` James Bottomley
2025-02-26 14:37                           ` Ralf Jung
2025-02-26 14:39                           ` Greg KH
2025-02-26 14:45                             ` James Bottomley
2025-02-26 16:00                               ` Steven Rostedt
2025-02-26 16:42                                 ` James Bottomley
2025-02-26 16:47                                   ` Kent Overstreet
2025-02-26 16:57                                     ` Steven Rostedt
2025-02-26 17:41                                       ` Kent Overstreet
2025-02-26 17:47                                         ` Steven Rostedt
2025-02-26 22:07                                           ` Josh Poimboeuf
2025-03-02 12:19                                           ` David Laight
2025-02-26 17:11                           ` Miguel Ojeda
2025-02-26 17:42                             ` Kent Overstreet
2025-02-26 12:36                 ` Ventura Jack
2025-02-26 13:52                   ` Miguel Ojeda
2025-02-26 15:21                     ` Ventura Jack
2025-02-26 16:06                       ` Ralf Jung
2025-02-26 17:49                       ` Miguel Ojeda
2025-02-26 18:36                         ` Ventura Jack
2025-02-26 14:14                   ` Ralf Jung
2025-02-26 15:40                     ` Ventura Jack
2025-02-26 16:10                       ` Ralf Jung
2025-02-26 16:50                         ` Ventura Jack
2025-02-26 21:39                           ` Ralf Jung
2025-02-27 15:11                             ` Ventura Jack
2025-02-27 15:32                               ` Ralf Jung
2025-02-25 18:54             ` Linus Torvalds
2025-02-25 19:47               ` Kent Overstreet
2025-02-25 20:25                 ` Linus Torvalds
2025-02-25 20:55                   ` Kent Overstreet
2025-02-25 21:24                     ` Linus Torvalds
2025-02-25 23:34                       ` Kent Overstreet
2025-02-26 11:57                         ` Gary Guo
2025-02-27 14:43                           ` Ventura Jack
2025-02-26 14:26                         ` Ventura Jack
2025-02-25 22:45                   ` Miguel Ojeda
2025-02-26  0:05                     ` Miguel Ojeda
2025-02-25 22:42                 ` Miguel Ojeda
2025-02-26 14:01                   ` Ralf Jung
2025-02-26 13:54               ` Ralf Jung
2025-02-26 17:59                 ` Linus Torvalds
2025-02-26 19:01                   ` Paul E. McKenney
2025-02-26 20:00                   ` Martin Uecker
2025-02-26 21:14                     ` Linus Torvalds
2025-02-26 21:21                       ` Linus Torvalds
2025-02-26 22:54                         ` David Laight
2025-02-27  0:35                           ` Paul E. McKenney
2025-02-26 21:26                       ` Steven Rostedt
2025-02-26 21:37                         ` Steven Rostedt
2025-02-26 21:42                         ` Linus Torvalds
2025-02-26 21:56                           ` Steven Rostedt
2025-02-26 22:13                             ` Steven Rostedt
2025-02-26 22:22                               ` Linus Torvalds
2025-02-26 22:35                                 ` Steven Rostedt
2025-02-26 23:18                                   ` Linus Torvalds
2025-02-26 23:28                                     ` Steven Rostedt
2025-02-27  0:04                                       ` Linus Torvalds
2025-02-27 20:47                                   ` David Laight
2025-02-27 21:33                                     ` Steven Rostedt
2025-02-28 21:29                                       ` Paul E. McKenney
2025-02-27 21:41                                     ` Paul E. McKenney
2025-02-27 22:20                                       ` David Laight
2025-02-27 22:40                                         ` Paul E. McKenney
2025-02-28  7:44                                     ` Ralf Jung
2025-02-28 15:41                                       ` Kent Overstreet
2025-02-28 15:46                                         ` Boqun Feng
2025-02-28 16:04                                           ` Kent Overstreet
2025-02-28 16:13                                             ` Boqun Feng
2025-02-28 16:21                                               ` Kent Overstreet
2025-02-28 16:40                                                 ` Boqun Feng
2025-03-04 18:12                                         ` Ralf Jung
2025-02-26 22:27                       ` Kent Overstreet
2025-02-26 23:16                         ` Linus Torvalds
2025-02-27  0:17                           ` Kent Overstreet
2025-02-27  0:26                           ` comex
2025-02-27 18:33                           ` Ralf Jung
2025-02-27 19:15                             ` Linus Torvalds
2025-02-27 19:55                               ` Kent Overstreet
2025-02-27 20:28                                 ` Linus Torvalds
2025-02-28  7:53                               ` Ralf Jung
2025-03-06 19:16                           ` Ventura Jack
2025-02-27  4:18                       ` Martin Uecker
2025-02-27  5:52                         ` Linus Torvalds
2025-02-27  6:56                           ` Martin Uecker
2025-02-27 14:29                             ` Steven Rostedt
2025-02-27 17:35                               ` Paul E. McKenney
2025-02-27 18:13                                 ` Kent Overstreet
2025-02-27 19:10                                   ` Paul E. McKenney
2025-02-27 18:00                           ` Ventura Jack
2025-02-27 18:44                           ` Ralf Jung
2025-02-27 14:21                     ` Ventura Jack
2025-02-27 15:27                       ` H. Peter Anvin
2025-02-28  8:08                     ` Ralf Jung
2025-02-28  8:32                       ` Martin Uecker
2025-02-26 20:25                   ` Kent Overstreet
2025-02-26 20:34                     ` Andy Lutomirski
2025-02-26 22:45                   ` David Laight
2025-02-22 19:41       ` Miguel Ojeda
2025-02-22 20:49         ` Kent Overstreet
2025-02-26 11:34           ` Ralf Jung
2025-02-26 14:57             ` Ventura Jack
2025-02-26 16:32               ` Ralf Jung
2025-02-26 18:09                 ` Ventura Jack
2025-02-26 22:28                   ` Ralf Jung
2025-02-26 23:08                     ` David Laight
2025-02-27 13:55                       ` Ralf Jung
2025-02-27 17:33                     ` Ventura Jack
2025-02-27 17:58                       ` Ralf Jung
2025-02-27 19:06                         ` Ventura Jack
2025-02-27 19:45                           ` Ralf Jung
2025-02-27 20:22                             ` Kent Overstreet
2025-02-27 22:18                               ` David Laight
2025-02-27 23:18                                 ` Kent Overstreet
2025-02-28  7:38                                   ` Ralf Jung
2025-02-28 20:48                                   ` Ventura Jack
2025-02-28 20:41                             ` Ventura Jack
2025-02-28 22:13                               ` Geoffrey Thomas
2025-03-01 14:19                                 ` Ventura Jack
2025-03-04 18:24                               ` Ralf Jung
2025-03-06 18:49                                 ` Ventura Jack
2025-02-27 17:58                       ` Miguel Ojeda
2025-02-27 19:25                         ` Ventura Jack
2025-02-26 19:07                 ` Martin Uecker [this message]
2025-02-26 19:23                   ` Ralf Jung
2025-02-26 20:22                     ` Martin Uecker
     [not found] <CAFJgqgRZ1w0ONj2wbcczx2=boXYHoLOd=-ke7tHGBAcifSfPUw@mail.gmail.com>
2025-02-25 15:42 ` H. Peter Anvin
2025-02-25 16:45   ` Ventura Jack
     [not found] <CANiq72m-R0tOakf=j7BZ78jDHdy=9-fvZbAT8j91Je2Bxy0sFg@mail.gmail.com>
2025-02-18 16:08 ` Rust kernel policy Christoph Hellwig
2025-02-18 18:46   ` Miguel Ojeda
2025-02-18 21:49     ` H. Peter Anvin
2025-02-18 22:54       ` Miguel Ojeda
2025-02-19  0:58         ` H. Peter Anvin
2025-02-19  3:04           ` Boqun Feng
2025-02-19  5:39             ` Greg KH
2025-02-20 12:28               ` Jan Engelhardt
2025-02-20 12:37                 ` Greg KH
2025-02-20 13:23                   ` H. Peter Anvin
2025-02-20 15:17                     ` C aggregate passing (Rust kernel policy) Jan Engelhardt
2025-02-20 16:46                       ` Linus Torvalds
2025-02-20 20:34                       ` H. Peter Anvin
2025-02-21  8:31                       ` HUANG Zhaobin
2025-02-21 18:34                       ` David Laight
2025-02-21 19:12                         ` Linus Torvalds
2025-02-21 20:07                           ` comex
2025-02-21 21:45                           ` David Laight
2025-02-22  6:32                             ` Willy Tarreau
2025-02-22  6:37                               ` Willy Tarreau
2025-02-22  8:41                                 ` David Laight
2025-02-22  9:11                                   ` Willy Tarreau
2025-02-21 20:06                         ` Jan Engelhardt
2025-02-21 20:23                           ` Laurent Pinchart
2025-02-21 20:24                             ` Laurent Pinchart
2025-02-21 22:02                             ` David Laight
2025-02-21 22:13                               ` Bart Van Assche
2025-02-22  5:56                                 ` comex
2025-02-21 20:26                           ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dd28fe6e2c174f605a104723a5ab8d5445fe8002.camel@tugraz.at \
    --to=uecker@tugraz.at \
    --cc=airlied@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=david.laight.linux@gmail.com \
    --cc=ej@inai.de \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=kent.overstreet@linux.dev \
    --cc=ksummit@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=post@ralfj.de \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=venturajack85@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®