Rust for Linux List
 help / color / mirror / Atom feed
From: "Benno Lossin" <lossin@kernel.org>
To: "Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Marcelo Moreira" <marcelomoreira1905@gmail.com>
Cc: <benno.lossin@proton.me>, <ojeda@kernel.org>,
	<aliceryhl@google.com>, <rust-for-linux@vger.kernel.org>,
	<skhan@linuxfoundation.org>,
	<linux-kernel-mentees@lists.linuxfoundation.org>,
	<~lkcamp/patches@lists.sr.ht>
Subject: Re: [PATCH] rust: revocable: clarify invariants in safety documentation
Date: Fri, 02 May 2025 09:33:54 +0200	[thread overview]
Message-ID: <D9LI1ISOHMV1.2721CU6HG3SRV@kernel.org> (raw)
In-Reply-To: <CANiq72ncOnDVHCNScjT7Y5+-kXzGvtcia=LpS0h-MfBqBMuOWA@mail.gmail.com>

On Thu May 1, 2025 at 12:18 PM CEST, Miguel Ojeda wrote:
> On Thu, May 1, 2025 at 2:57 AM Marcelo Moreira
> <marcelomoreira1905@gmail.com> wrote:
>>
>> This is part of issue #1160 ("correct safety comments and documentation
>> in revocable.rs"), reported by Miguel Ojeda and Benno Lossin.
>>
>> Reported-by: Miguel Ojeda <ojeda@kernel.org>
>> Closes: https://github.com/Rust-for-Linux/linux/issues/1160
>
> I think it was just Benno. :)
>
>> Tested-by: Marcelo Moreira <marcelomoreira1905@gmail.com>
>
> Normally one is supposed to test a patch before submitting it, i.e. it
> is implicit.
>
>> +/// # Invariants
>
> We also place `// INVARIANT: ...` comments in the places that need to
> ensure the type invariants hold, e.g. in constructors.
>
> Given the issue, I think Benno may have also wanted that you then
> refer to the type invariants to justify some of the comments, e.g. in
> the "Since `self.is_available` is true, ..." ones.

Indeed, we also need the comments that establish/make use of the
invariant. For example in the `try_access_with_guard` function.

There also is a missing invariant on `RevocableGuard` that the
`data_ref` pointer is valid.

>> +/// - Access to `data` must occur only while holding the RCU read-side lock (e.g., vi
>
> The "must occur" wording seems a bit strange for a type invariant, but
> maybe Benno had something in mind here?

Yeah, I don't think that using RCU is even a hard requirement. One could
also call `revoke_nosync`, since one knows the revocable is only used by
a single kernel thread. I also don't think that it's needed for memory
correctness, but I could be wrong there.

The most important invariant is that `data` is valid while
`is_available` is true. That's what's needed by the different functions
accessing it.

---
Cheers,
Benno

  reply	other threads:[~2025-05-02  7:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-01  0:57 [PATCH] rust: revocable: clarify invariants in safety documentation Marcelo Moreira
2025-05-01 10:18 ` Miguel Ojeda
2025-05-02  7:33   ` Benno Lossin [this message]
2025-05-02 17:10     ` Marcelo Moreira

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=D9LI1ISOHMV1.2721CU6HG3SRV@kernel.org \
    --to=lossin@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=marcelomoreira1905@gmail.com \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=~lkcamp/patches@lists.sr.ht \
    /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