All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: Priya Bala Govindasamy <pgovind2@uci.edu>,
	peterz@infradead.org, mingo@redhat.com, will@kernel.org,
	gary@garyguo.net, ojeda@kernel.org, longman@redhat.com,
	lyude@redhat.com, daniel.almeida@collabora.com,
	work@onurozkan.dev, bjorn3_gh@protonmail.com, lossin@kernel.org,
	a.hindborg@kernel.org, tmgross@umich.edu, dakr@kernel.org,
	tamird@kernel.org, acourbot@nvidia.com,
	rust-for-linux@vger.kernel.org, ardalan@uci.edu,
	zhiyunq@cs.ucr.edu, dzueck@uci.edu
Subject: Re: [PATCH 1/1] rust: sync: Make `GlobalLockedBy::as_ref` unavailable if T is not Sync
Date: Mon, 19 Oct 2026 11:00:52 -0700	[thread overview]
Message-ID: <atZa1L5nsoyKtwNf@tardis.local> (raw)
In-Reply-To: <CAH5fLgh7_vpfuU7wLrgO4ZfW=bxvdL7aRhwW20bBK0Y0PURz_w@mail.gmail.com>

On Mon, Oct 19, 2026 at 09:49:22AM +0200, Alice Ryhl wrote:
> On Fri, Oct 16, 2026 at 7:19 PM Priya Bala Govindasamy <pgovind2@uci.edu> wrote:
> >
> > The `GlobalLockedBy::as_ref` method allows `&T` to be obtained from
> > mutliple threads even if `T` is not Sync.
> >
> > This happens because `GlobalLockedBy<T, B>` is Sync if
> > `LockedBy<T, B::item>` is Sync. `LockedBy<T, B>` is Sync if `T` is Send.
> > Since there is no requirement that `T` also implements Sync, it is
> > possible for multiple threads to simultaneously obtain references to a
> > `GlobalLockedBy<T, B>` and then acquire `&T` through
> > `GlobalLockedBy::as_ref`. This can lead to undefined behavior if `T` does
> > not implement Sync.
> >
> > Note that a reference to `GlobalGuard<B>` is required as an argument to
> > `GlobalLockedBy::as_ref`. Therefore, this issue requires that
> > `GlobalGuard<B>` is `Sync` which happens if `B::item` is `Sync`
> > (for example, ()).
> >
> > Fix this by adding a trait bound to `GlobalLockedBy::as_ref` requiring
> > `T: Sync`.
> >
> > Fixes: 8eea62ff94f4 ("rust: sync: add global lock support")
> > Reported-by: Dylan Zueck <dzueck@uci.edu>
> > Assisted-by: LLM
> > Signed-off-by: Priya Bala Govindasamy <pgovind2@uci.edu>
> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Queued for more review and testing.

Thank you both!

Regards,
Boqun

      reply	other threads:[~2026-10-19 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 17:18 [PATCH 0/1] rust: sync: Make `GlobalLockedBy::as_ref` unavailable if T is not Sync Priya Bala Govindasamy
2026-10-16 17:18 ` [PATCH 1/1] " Priya Bala Govindasamy
2026-10-19  7:49   ` Alice Ryhl
2026-10-19 18:00     ` Boqun Feng [this message]

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=atZa1L5nsoyKtwNf@tardis.local \
    --to=boqun@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=ardalan@uci.edu \
    --cc=bjorn3_gh@protonmail.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dzueck@uci.edu \
    --cc=gary@garyguo.net \
    --cc=longman@redhat.com \
    --cc=lossin@kernel.org \
    --cc=lyude@redhat.com \
    --cc=mingo@redhat.com \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pgovind2@uci.edu \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=will@kernel.org \
    --cc=work@onurozkan.dev \
    --cc=zhiyunq@cs.ucr.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.