Re: [PATCH] scsi: ufs: core: Fix a race condition related to device commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2025-03-12 at 07:25 -0700, Bart Van Assche wrote:
> > 
> > Hi Bart,
> > 
> > This could calling init_completion on the same completion twice?
> 
> Hi Peter,
> 
> My patch will cause init_completion() to be called as many times as
> device management commands are submitted. As far as I know the
> following
> sequence is allowed and does not trigger any race conditions:
> 
> Thread 1                                  Thread 2
> --------                                  --------
> init_completion()
> wait_for_completion_timeout() is called
>                                            complete()
> wait_for_completion_timeout() returns
> 
> init_completion()
> wait_for_completion_timeout() is called
>                                            complete()
> wait_for_completion_timeout() returns
> 
> [ ... ]
> 
> Thanks,
> 
> Bart.

Hi Bart,

https://www.kernel.org/doc/Documentation/scheduler/completion.txt
Calling init_completion() on the same completion object twice is
most likely a bug as it re-initializes the queue to an empty queue and
enqueued tasks could get "lost" - use reinit_completion() in that case,
but be aware of other races.

I understand that it should be protected from racing issues by the 
dev_cmd.lock, but it's probably best not to use it in this way. 
Using reinit_completion might be a better approach.

Thanks.
Peter






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux