linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-ide@vger.kernel.org, linux-block@vger.kernel.org,
	Jens Axboe <axboe@kernel.dk>,
	"Maciej S . Szmigiero" <mail@maciej.szmigiero.name>,
	Hannes Reinecke <hare@suse.de>
Subject: Re: [PATCH v4 1/7] block: Prevent the use of REQ_FUA with read operations
Date: Wed, 2 Nov 2022 00:09:03 -0700	[thread overview]
Message-ID: <Y2IXjzWL5eHA3Co9@infradead.org> (raw)
In-Reply-To: <3af6895b-b776-cf0d-fe1e-866ce5e6b0b0@opensource.wdc.com>

On Wed, Nov 02, 2022 at 07:05:35AM +0900, Damien Le Moal wrote:
> >> +	if (!op_is_write(rq->cmd_flags) && (rq->cmd_flags & REQ_FUA)) {
> >> +		blk_mq_end_request(rq, BLK_STS_NOTSUPP);
> > 
> > How could this even happen?  If we want a debug check,  I think it
> > should be in submit_bio and a WARN_ON_ONCE.
> 
> I have not found any code that issues a FUA read. So I do not think this
> can happen at all currently. The check is about making sure that it
> *never* happens.
> 
> I thought of having the check higher up in the submit path but I wanted to
> avoid adding yet another check in the very hot path. But if you are OK
> with that, I will move it.

I'd do something like this:

---
From 96847cce848938d1ee368e609ccb28a19854fba3 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Wed, 2 Nov 2022 08:05:41 +0100
Subject: block: add a sanity check for non-write flush/fua bios

Check that the PREFUSH and FUA flags are only set on write bios,
given that the flush state machine expects that.

Reported-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-core.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index e9e2bf15cd909..4e2b01a53c6ab 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -720,12 +720,15 @@ void submit_bio_noacct(struct bio *bio)
 	 * Filter flush bio's early so that bio based drivers without flush
 	 * support don't have to worry about them.
 	 */
-	if (op_is_flush(bio->bi_opf) &&
-	    !test_bit(QUEUE_FLAG_WC, &q->queue_flags)) {
-		bio->bi_opf &= ~(REQ_PREFLUSH | REQ_FUA);
-		if (!bio_sectors(bio)) {
-			status = BLK_STS_OK;
+	if (op_is_flush(bio->bi_opf)) {
+		if (WARN_ON_ONCE(bio_op(bio) != REQ_OP_WRITE))
 			goto end_io;
+		if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags)) {
+			bio->bi_opf &= ~(REQ_PREFLUSH | REQ_FUA);
+			if (!bio_sectors(bio)) {
+				status = BLK_STS_OK;
+				goto end_io;
+			}
 		}
 	}
 
-- 
2.30.2


  reply	other threads:[~2022-11-02  7:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31  2:26 [PATCH v4 0/7] Improve libata support for FUA Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 1/7] block: Prevent the use of REQ_FUA with read operations Damien Le Moal
2022-11-01 15:09   ` Christoph Hellwig
2022-11-01 22:05     ` Damien Le Moal
2022-11-02  7:09       ` Christoph Hellwig [this message]
2022-11-02  7:27         ` Damien Le Moal
2022-11-02 15:17         ` Jens Axboe
2022-11-02 22:28           ` Damien Le Moal
2022-11-03  7:49           ` Christoph Hellwig
2022-11-05 15:32             ` Jens Axboe
2022-10-31  2:26 ` [PATCH v4 2/7] ata: libata: Introduce ata_ncq_supported() Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 3/7] ata: libata: Rename and cleanup ata_rwcmd_protocol() Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 4/7] ata: libata: cleanup fua support detection Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 5/7] ata: libata: Fix FUA handling in ata_build_rw_tf() Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 6/7] ata: libata: blacklist FUA support for known buggy drives Damien Le Moal
2022-10-31  2:26 ` [PATCH v4 7/7] ata: libata: Enable fua support by default Damien Le Moal
  -- strict thread matches above, loose matches on Subject: below --
2022-10-31  1:53 [PATCH v4 0/7] Damien Le Moal
2022-10-31  1:53 ` [PATCH v4 1/7] block: Prevent the use of REQ_FUA with read operations Damien Le Moal

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=Y2IXjzWL5eHA3Co9@infradead.org \
    --to=hch@infradead.org \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=hare@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=mail@maciej.szmigiero.name \
    /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;
as well as URLs for NNTP newsgroup(s).