The Linux Kernel Mailing List
 help / color / mirror / Atom feed
  • [parent not found: <20260722-setonce-populate-v1-1-fa7455c26c42@google.com>]
  • * Re: [PATCH 0/3] rust: sync: add SetOnce::try_get_or_populate()
           [not found] <20260722-setonce-populate-v1-0-fa7455c26c42@google.com>
           [not found] ` <20260722-setonce-populate-v1-2-fa7455c26c42@google.com>
           [not found] ` <20260722-setonce-populate-v1-1-fa7455c26c42@google.com>
    @ 2026-07-29 14:12 ` Alexandre Courbot
      2 siblings, 0 replies; 4+ messages in thread
    From: Alexandre Courbot @ 2026-07-29 14:12 UTC (permalink / raw)
      To: Alice Ryhl
      Cc: Boqun Feng, Gary Guo, Lyude Paul, Daniel Almeida, Onur Özkan,
    	Greg Kroah-Hartman, Carlos Llamas, Luis Chamberlain, Petr Pavlu,
    	Daniel Gomez, Sami Tolvanen, Aaron Tomlin, Miguel Ojeda,
    	Björn Roy Baron, Benno Lossin, Andreas Hindborg,
    	Trevor Gross, Danilo Krummrich, Tamir Duberstein, linux-modules,
    	linux-kernel, rust-for-linux
    
    On Wed Jul 22, 2026 at 6:16 PM JST, Alice Ryhl wrote:
    > The SetOnce::populate() method does not internally synchronize callers
    > that fail to populate the value with the successful call. This means
    > that naive loops using as_ref() and populate() can lead to spinning on
    > the initialization, which is best avoided. Thus, provide a helper that
    > avoids this issue using a user-provided lock.
    >
    > One potential alternative is to change populate() so that the failing
    > caller actually does synchronize with the successful call to populate().
    > However, this is somewhat tricky:
    >
    > * There are users of SetOnce that construct it in const context, and we
    >   currently don't have the ability to do that for most locks, so we
    >   cannot easily add a lock to SetOnce.
    > * Just spinning on the atomic is undesirable unless we disable
    >   preemption in the success path. If we do disable preemption, then that
    >   raises complications for handling the PREEMPT_RT case.
    > * It also raises questions about deadlocks if populate() is called from
    >   irqs.
    >
    > By using a user-provided lock, we do not have to worry about these
    > issues inside SetOnce.
    >
    > This series is based on char-misc-next.
    >
    > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
    
    If would be nice if the series could also include a patch updating the
    GEM shmem module, which is another potential user of
    `try_get_or_populate` - in particular since the current implementation
    doesn't seem to be a perfect match yet (see my comments on patch 2) so
    it would be an opportunity to refine it.
    
    ^ permalink raw reply	[flat|nested] 4+ messages in thread

  • end of thread, other threads:[~2026-07-29 14:24 UTC | newest]
    
    Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <20260722-setonce-populate-v1-0-fa7455c26c42@google.com>
         [not found] ` <20260722-setonce-populate-v1-2-fa7455c26c42@google.com>
    2026-07-29 14:05   ` [PATCH 2/3] rust: sync: add SetOnce::try_get_or_populate() Alexandre Courbot
    2026-07-29 14:23     ` Boqun Feng
         [not found] ` <20260722-setonce-populate-v1-1-fa7455c26c42@google.com>
    2026-07-29 14:09   ` [PATCH 1/3] rust: sync: return `Result<&T, T>` from `SetOnce::populate()` Alexandre Courbot
    2026-07-29 14:12 ` [PATCH 0/3] rust: sync: add SetOnce::try_get_or_populate() Alexandre Courbot
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox