From: Zilin Guan <zilinguan811@gmail.com>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Zilin Guan <zilinguan811@gmail.com>
Subject: [PATCH] block: Use WRITE_ONCE for cache->nr_irq update
Date: Mon, 4 Nov 2024 11:37:45 +0000 [thread overview]
Message-ID: <20241104113745.3099644-1-zilinguan811@gmail.com> (raw)
In function bio_put_percpu_cache(), cache->nr_irq is read indirectly
in line 776 using READ_ONCE(). This ensures safe access in a
multi-threaded environment.
776 if (READ_ONCE(cache->nr_irq) + cache->nr > ALLOC_CACHE_MAX)
777 goto out_free;
However, the increment operation is performed directly in line 792 without
using WRITE_ONCE(), which can lead to potential inconsistencies in a
multi-threaded context.
792 cache->nr_irq++;
To ensure consistent protection against data races, this update
should utilize WRITE_ONCE.
Signed-off-by: Zilin Guan <zilinguan811@gmail.com>
---
block/bio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/bio.c b/block/bio.c
index ac4d77c88932..e2648ba71bac 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -789,7 +789,7 @@ static inline void bio_put_percpu_cache(struct bio *bio)
bio_uninit(bio);
bio->bi_next = cache->free_list_irq;
cache->free_list_irq = bio;
- cache->nr_irq++;
+ WRITE_ONCE(cache->nr_irq, cache->nr_irq + 1);
} else {
goto out_free;
}
--
2.34.1
reply other threads:[~2024-11-04 11:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20241104113745.3099644-1-zilinguan811@gmail.com \
--to=zilinguan811@gmail.com \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®