All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Hanna Reitz <hreitz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org,
	Emanuele Giuseppe Esposito <eesposit@redhat.com>
Subject: Re: [PATCH v2 2/3] block: make BlockBackend->disable_request_queuing atomic
Date: Thu, 9 Mar 2023 07:31:18 -0500	[thread overview]
Message-ID: <20230309123118.GB370169@fedora> (raw)
In-Reply-To: <d9ec7184-460d-f5f6-e45b-79c9979bafa0@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1423 bytes --]

On Thu, Mar 09, 2023 at 10:07:40AM +0100, Paolo Bonzini wrote:
> On 3/7/23 22:04, Stefan Hajnoczi wrote:
> > This field is accessed by multiple threads without a lock. Use explicit
> > qatomic_read()/qatomic_set() calls. There is no need for acquire/release
> > because blk_set_disable_request_queuing() doesn't provide any
> > guarantees (it helps that it's used at BlockBackend creation time and
> > not when there is I/O in flight).
> 
> This in turn means itdoes not need to be atomic - atomics are only needed if
> there are concurrent writes.  No big deal; I am now resurrecting the series
> from the time I had noticed the queued_requests thread-safety problem, so
> this will be simplified in 8.1.  For now your version is okay, thanks for
> fixing it!

I was under the impression that variables accessed by multiple threads
outside a lock or similar primitive need memory_order_relaxed both as
documentation and to tell the compiler that they should indeed be atomic
(but without ordering guarantees).

I think memory_order_relaxed also tells the compiler to do a bit more,
like to generate just a single store to the variable for each occurrence
in the code ("speculative" and "out-of-thin air" stores).

It's the documentation part that's most interesting in this case. Do we
not want to identify variables that are accessed outside a lock and
therefore require some thought?

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2023-03-09 12:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 21:04 [PATCH v2 0/3] block: protect BlockBackend->queued_requests with a lock Stefan Hajnoczi
2023-03-07 21:04 ` [PATCH v2 1/3] block: make BlockBackend->quiesce_counter atomic Stefan Hajnoczi
2023-03-07 21:10   ` Philippe Mathieu-Daudé
2023-03-07 21:04 ` [PATCH v2 2/3] block: make BlockBackend->disable_request_queuing atomic Stefan Hajnoczi
2023-03-07 21:10   ` Philippe Mathieu-Daudé
2023-03-09  9:07   ` Paolo Bonzini
2023-03-09 12:31     ` Stefan Hajnoczi [this message]
2023-03-09 13:37       ` Paolo Bonzini
2023-03-09 11:18   ` Paolo Bonzini
2023-03-09 12:12     ` Stefan Hajnoczi
2023-03-07 21:04 ` [PATCH v2 3/3] block: protect BlockBackend->queued_requests with a lock Stefan Hajnoczi
2023-03-08  9:46 ` [PATCH v2 0/3] " Kevin Wolf

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=20230309123118.GB370169@fedora \
    --to=stefanha@redhat.com \
    --cc=eesposit@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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.