All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: Chaohai Chen <wdhh6@aliyun.com>
Cc: James.Bottomley@hansenpartnership.com,
	martin.petersen@oracle.com, dlemoal@kernel.org,
	bvanassche@acm.org, hch@infradead.org,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] scsi: core: Fix async_scan race condition with READ_ONCE/WRITE_ONCE
Date: Wed, 4 Mar 2026 09:55:08 +0000	[thread overview]
Message-ID: <2c5c8eba-c4d2-46b6-bed4-3dabd8771069@oracle.com> (raw)
In-Reply-To: <aaf+ucySU/sSN8WZ@VM-209-93-tencentos>

On 04/03/2026 09:43, Chaohai Chen wrote:
> On Wed, Mar 04, 2026 at 09:20:25AM +0000, John Garry wrote:
>> On 04/03/2026 07:57, Chaohai Chen wrote:
>>> Previously, host_lock was used to prevent bit-set conflicts in async_scan,
>>> but this approach introduced naked reads in some code paths.
>>>
>>> Convert async_scan from a bitfield to a bool type to eliminate bit-level
>>> conflicts entirely. Use READ_ONCE() and WRITE_ONCE() to ensure proper
>>> memory ordering on Alpha and satisfy KCSAN requirements.
>>
>> Is the shost->scan_mutex always held when shost->async_scan is read/written?
>>
> Yes. In theory, there is no need for READ-ONCE/WRITE-ONCE.

Then I understand that in practice that there is no need (for 
READ/WRITE_ONCE), but having it will do no harm, as you mention below.

> Plus, this belongs
> to defensive programming. 

You could mention what this in the commit log.

> And it indicates that this is a shared variable,
> which means that this variable will be accessed by multiple threads and
> concurrency issues need to be handled carefully.

Reviewed-by: John Garry <john.g.garry@oracle.com>

  parent reply	other threads:[~2026-03-04  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04  7:57 [PATCH v3] scsi: core: Fix async_scan race condition with READ_ONCE/WRITE_ONCE Chaohai Chen
2026-03-04  8:32 ` Damien Le Moal
2026-03-04  9:20 ` John Garry
2026-03-04  9:43   ` Chaohai Chen
2026-03-04  9:52     ` Damien Le Moal
2026-03-04  9:55     ` John Garry [this message]
2026-03-04 12:21     ` Bart Van Assche

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=2c5c8eba-c4d2-46b6-bed4-3dabd8771069@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=bvanassche@acm.org \
    --cc=dlemoal@kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=wdhh6@aliyun.com \
    /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.