All of lore.kernel.org
 help / color / mirror / Atom feed
* What is bs->reqs_lock for?
@ 2020-08-13 14:57 Vladimir Sementsov-Ogievskiy
  2020-08-13 15:54 ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2020-08-13 14:57 UTC (permalink / raw)
  To: qemu block
  Cc: Kevin Wolf, Paolo Bonzini, qemu-devel, Stefan Hajnoczi, Max Reitz

Hi!

Sorry my stupid question, but which kind of concurrent access bs->reqs_lock prevents?

In my understanding the whole logic of request tracking for the bs is going in the coroutine, so, we don't have parallel access anyway? How can parallel access to bs->tracked_requests happen?


-- 
Best regards,
Vladimir


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is bs->reqs_lock for?
  2020-08-13 14:57 What is bs->reqs_lock for? Vladimir Sementsov-Ogievskiy
@ 2020-08-13 15:54 ` Paolo Bonzini
  2020-08-13 16:34   ` Vladimir Sementsov-Ogievskiy
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2020-08-13 15:54 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu block
  Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Max Reitz

On 13/08/20 16:57, Vladimir Sementsov-Ogievskiy wrote:
> Hi!
> 
> Sorry my stupid question, but which kind of concurrent access
> bs->reqs_lock prevents?
> 
> In my understanding the whole logic of request tracking for the bs is
> going in the coroutine, so, we don't have parallel access anyway? How
> can parallel access to bs->tracked_requests happen?

Different iothreads can access the same BlockDriverState, and block/io.c
is not protected by the AioContext lock (in fact almost nothing, or
nothing, needs it in the I/O path).

Paolo



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is bs->reqs_lock for?
  2020-08-13 15:54 ` Paolo Bonzini
@ 2020-08-13 16:34   ` Vladimir Sementsov-Ogievskiy
  2020-08-18  6:16     ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2020-08-13 16:34 UTC (permalink / raw)
  To: Paolo Bonzini, qemu block
  Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Max Reitz

13.08.2020 18:54, Paolo Bonzini wrote:
> On 13/08/20 16:57, Vladimir Sementsov-Ogievskiy wrote:
>> Hi!
>>
>> Sorry my stupid question, but which kind of concurrent access
>> bs->reqs_lock prevents?
>>
>> In my understanding the whole logic of request tracking for the bs is
>> going in the coroutine, so, we don't have parallel access anyway? How
>> can parallel access to bs->tracked_requests happen?
> 
> Different iothreads can access the same BlockDriverState, and block/io.c
> is not protected by the AioContext lock (in fact almost nothing, or
> nothing, needs it in the I/O path).
> 

I thought bs is attached to one aio context and aio context attached to one iothread.
And all normal request processing of the bs is done in this one iothread.
And when we need to access bs externally, we do it in
aio_context_acquire / aio_context_release, which protects from parallel access to
BlockDriverState fields...

But you say, that block/io.c is not protected by AioContext lock..

Does it mean that everything must be thread-safe in block/io.c and all block drivers?

Are tracked_requests different from other fields? A lot of other BlockDriverState
fields are not protected by any mutex.. For example: total_sectors, file, backing..

Could you give an example of parallel access to tracked_requests?

-- 
Best regards,
Vladimir


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is bs->reqs_lock for?
  2020-08-13 16:34   ` Vladimir Sementsov-Ogievskiy
@ 2020-08-18  6:16     ` Paolo Bonzini
  2020-08-19  9:41       ` Vladimir Sementsov-Ogievskiy
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2020-08-18  6:16 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy, qemu block
  Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Max Reitz

On 13/08/20 18:34, Vladimir Sementsov-Ogievskiy wrote:
> I thought bs is attached to one aio context and aio context attached to
> one iothread.

For now yes, but with multiqueue there would be many iothreads sending
requests to the AioContext.  The BDS would still have a "home"
aiocontext to request socket readiness events, but
io_uring/linux_aio/threadpool requests could be issued from any iothread.

> And all normal request processing of the bs is done in this one iothread.
> And when we need to access bs externally, we do it in
> aio_context_acquire / aio_context_release, which protects from parallel
> access to BlockDriverState fields...
> 
> But you say, that block/io.c is not protected by AioContext lock..
> Does it mean that everything must be thread-safe in block/io.c and all
> block drivers?

Yes.

> 
> Are tracked_requests different from other fields? A lot of other
> BlockDriverState
> fields are not protected by any mutex.. For example: total_sectors,
> file, backing..

Rules are documented in include/block/block_int.h.  It seems however
that never_freeze was blindly added at the end.

Paolo

> Could you give an example of parallel access to tracked_requests?
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What is bs->reqs_lock for?
  2020-08-18  6:16     ` Paolo Bonzini
@ 2020-08-19  9:41       ` Vladimir Sementsov-Ogievskiy
  0 siblings, 0 replies; 5+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2020-08-19  9:41 UTC (permalink / raw)
  To: Paolo Bonzini, qemu block
  Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Max Reitz

18.08.2020 09:16, Paolo Bonzini wrote:
> On 13/08/20 18:34, Vladimir Sementsov-Ogievskiy wrote:
>> I thought bs is attached to one aio context and aio context attached to
>> one iothread.
> 
> For now yes, but with multiqueue there would be many iothreads sending
> requests to the AioContext.  The BDS would still have a "home"
> aiocontext to request socket readiness events, but
> io_uring/linux_aio/threadpool requests could be issued from any iothread.
> 
>> And all normal request processing of the bs is done in this one iothread.
>> And when we need to access bs externally, we do it in
>> aio_context_acquire / aio_context_release, which protects from parallel
>> access to BlockDriverState fields...
>>
>> But you say, that block/io.c is not protected by AioContext lock..
>> Does it mean that everything must be thread-safe in block/io.c and all
>> block drivers?
> 
> Yes.
> 
>>
>> Are tracked_requests different from other fields? A lot of other
>> BlockDriverState
>> fields are not protected by any mutex.. For example: total_sectors,
>> file, backing..
> 
> Rules are documented in include/block/block_int.h. 

I should have guessed on my own..

> It seems however
> that never_freeze was blindly added at the end.
> 

Thanks for your answers!


-- 
Best regards,
Vladimir


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-19  9:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-13 14:57 What is bs->reqs_lock for? Vladimir Sementsov-Ogievskiy
2020-08-13 15:54 ` Paolo Bonzini
2020-08-13 16:34   ` Vladimir Sementsov-Ogievskiy
2020-08-18  6:16     ` Paolo Bonzini
2020-08-19  9:41       ` Vladimir Sementsov-Ogievskiy

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.