linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hongyu Jin <hongyu.jin.cn@gmail.com>
To: agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	axboe@kernel.dk, ebiggers@kernel.org
Cc: zhiguo.niu@unisoc.com, ke.wang@unisoc.com, yibin.ding@unisoc.com,
	hongyu.jin@unisoc.com, linux-kernel@vger.kernel.org,
	dm-devel@lists.linux.dev, linux-block@vger.kernel.org
Subject: [PATCH v6 4/5] dm verity: Fix I/O priority lost when read FEC and hash
Date: Wed, 20 Dec 2023 18:03:32 +0800	[thread overview]
Message-ID: <20231220100333.107049-5-hongyu.jin.cn@gmail.com> (raw)
In-Reply-To: <20231220100333.107049-1-hongyu.jin.cn@gmail.com>

From: Hongyu Jin <hongyu.jin@unisoc.com>

After obtaining the data, verification or error correction process may
trigger a new I/O that loses the priority of the original I/O, that is,
the verification of the higher priority IO may be blocked by the lower
priority IO.

Make the I/O of verification and error correction follow the
priority of original I/O.

Co-developed-by: Yibin Ding <yibin.ding@unisoc.com>
Signed-off-by: Yibin Ding <yibin.ding@unisoc.com>
Signed-off-by: Hongyu Jin <hongyu.jin@unisoc.com>
---
 drivers/md/dm-verity-fec.c    | 20 +++++++++++++++-----
 drivers/md/dm-verity-target.c | 12 ++++++++----
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/drivers/md/dm-verity-fec.c b/drivers/md/dm-verity-fec.c
index 49db19e537f9..a9e5402e3d43 100644
--- a/drivers/md/dm-verity-fec.c
+++ b/drivers/md/dm-verity-fec.c
@@ -18,6 +18,12 @@ bool verity_fec_is_enabled(struct dm_verity *v)
 	return v->fec && v->fec->dev;
 }
 
+static inline struct dm_verity_io *verity_io(struct dm_verity *v, struct dm_verity_fec_io *fio)
+{
+	return (struct dm_verity_io *)
+		((char *)fio + sizeof(struct dm_verity_fec_io) - v->ti->per_io_data_size);
+}
+
 /*
  * Return a pointer to dm_verity_fec_io after dm_verity_io and its variable
  * length fields.
@@ -60,7 +66,8 @@ static int fec_decode_rs8(struct dm_verity *v, struct dm_verity_fec_io *fio,
  * to the data block. Caller is responsible for releasing buf.
  */
 static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
-			   unsigned int *offset, struct dm_buffer **buf)
+			   unsigned int *offset, struct dm_buffer **buf,
+			   unsigned short ioprio)
 {
 	u64 position, block, rem;
 	u8 *res;
@@ -69,7 +76,7 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index,
 	block = div64_u64_rem(position, v->fec->io_size, &rem);
 	*offset = (unsigned int)rem;
 
-	res = dm_bufio_read(v->fec->bufio, block, buf, IOPRIO_DEFAULT);
+	res = dm_bufio_read(v->fec->bufio, block, buf, ioprio);
 	if (IS_ERR(res)) {
 		DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
 		      v->data_dev->name, (unsigned long long)rsb,
@@ -129,8 +136,10 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
 	struct dm_buffer *buf;
 	unsigned int n, i, offset;
 	u8 *par, *block;
+	struct dm_verity_io *io = verity_io(v, fio);
+	struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
 
-	par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
+	par = fec_read_parity(v, rsb, block_offset, &offset, &buf, bio_prio(bio));
 	if (IS_ERR(par))
 		return PTR_ERR(par);
 
@@ -158,7 +167,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio,
 		if (offset >= v->fec->io_size) {
 			dm_bufio_release(buf);
 
-			par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
+			par = fec_read_parity(v, rsb, block_offset, &offset, &buf, bio_prio(bio));
 			if (IS_ERR(par))
 				return PTR_ERR(par);
 		}
@@ -210,6 +219,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io,
 	u8 *bbuf, *rs_block;
 	u8 want_digest[HASH_MAX_DIGESTSIZE];
 	unsigned int n, k;
+	struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
 
 	if (neras)
 		*neras = 0;
@@ -248,7 +258,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io,
 			bufio = v->bufio;
 		}
 
-		bbuf = dm_bufio_read(bufio, block, &buf, IOPRIO_DEFAULT);
+		bbuf = dm_bufio_read(bufio, block, &buf, bio_prio(bio));
 		if (IS_ERR(bbuf)) {
 			DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld",
 				     v->data_dev->name,
diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c
index 4758bfe2c156..8cbf81fc0031 100644
--- a/drivers/md/dm-verity-target.c
+++ b/drivers/md/dm-verity-target.c
@@ -51,6 +51,7 @@ static DEFINE_STATIC_KEY_FALSE(use_tasklet_enabled);
 struct dm_verity_prefetch_work {
 	struct work_struct work;
 	struct dm_verity *v;
+	unsigned short ioprio;
 	sector_t block;
 	unsigned int n_blocks;
 };
@@ -294,6 +295,7 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
 	int r;
 	sector_t hash_block;
 	unsigned int offset;
+	struct bio *bio = dm_bio_from_per_bio_data(io, v->ti->per_io_data_size);
 
 	verity_hash_at_level(v, block, level, &hash_block, &offset);
 
@@ -308,7 +310,7 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
 			return -EAGAIN;
 		}
 	} else
-		data = dm_bufio_read(v->bufio, hash_block, &buf, IOPRIO_DEFAULT);
+		data = dm_bufio_read(v->bufio, hash_block, &buf, bio_prio(bio));
 
 	if (IS_ERR(data))
 		return PTR_ERR(data);
@@ -720,13 +722,14 @@ static void verity_prefetch_io(struct work_struct *work)
 no_prefetch_cluster:
 		dm_bufio_prefetch(v->bufio, hash_block_start,
 				  hash_block_end - hash_block_start + 1,
-				  IOPRIO_DEFAULT);
+				  pw->ioprio);
 	}
 
 	kfree(pw);
 }
 
-static void verity_submit_prefetch(struct dm_verity *v, struct dm_verity_io *io)
+static void verity_submit_prefetch(struct dm_verity *v, struct dm_verity_io *io,
+				   unsigned short ioprio)
 {
 	sector_t block = io->block;
 	unsigned int n_blocks = io->n_blocks;
@@ -754,6 +757,7 @@ static void verity_submit_prefetch(struct dm_verity *v, struct dm_verity_io *io)
 	pw->v = v;
 	pw->block = block;
 	pw->n_blocks = n_blocks;
+	pw->ioprio = ioprio;
 	queue_work(v->verify_wq, &pw->work);
 }
 
@@ -796,7 +800,7 @@ static int verity_map(struct dm_target *ti, struct bio *bio)
 
 	verity_fec_init_io(io);
 
-	verity_submit_prefetch(v, io);
+	verity_submit_prefetch(v, io, bio_prio(bio));
 
 	submit_bio_noacct(bio);
 
-- 
2.34.1


  parent reply	other threads:[~2023-12-20 10:04 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <df68c38e-3e38-eaf1-5c32-66e43d68cae3@ewheeler.net>
2023-12-11  8:59 ` [PATCH v3 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2023-12-11  8:59   ` [PATCH v3 1/5] block: Optimize bio io priority setting Hongyu Jin
2023-12-11 21:12     ` Mike Snitzer
2023-12-11  8:59   ` [PATCH v3 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-11  8:59   ` [PATCH v3 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-11  8:59   ` [PATCH v3 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2023-12-11  9:00   ` [PATCH v3 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2023-12-11 20:32     ` Eric Wheeler
2023-12-11 22:15     ` Mike Snitzer
2023-12-12 11:11       ` [PATCH v4 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2023-12-12 11:11         ` [PATCH v4 1/5] block: Fix bio IO priority setting Hongyu Jin
2023-12-12 13:13           ` Christoph Hellwig
2023-12-12 18:02             ` Mike Snitzer
2023-12-12 11:11         ` [PATCH v4 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-13  4:57           ` Eric Biggers
2023-12-12 11:11         ` [PATCH v4 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-13  5:00           ` Eric Biggers
2023-12-12 11:11         ` [PATCH v4 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2023-12-12 11:11         ` [PATCH v4 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2023-12-13  4:45         ` [PATCH v4 0/5] Fix I/O priority lost in device-mapper Eric Biggers
2023-12-13  9:24           ` Henry King
2023-12-13 10:42             ` Hongyu Jin
2023-12-13 10:42               ` [PATCH v5 1/5] block: Fix bio IO priority setting Hongyu Jin
2023-12-13 16:58                 ` Mike Snitzer
2023-12-18  1:24                   ` Henry King
2023-12-18  1:27                     ` [PATCH v5 RESEND 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2023-12-18  1:27                       ` [PATCH v5 RESEND 1/5] block: Fix bio IO priority setting Hongyu Jin
2023-12-18  1:27                       ` [PATCH v5 RESEND 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-19 22:46                         ` Eric Biggers
2023-12-18  1:27                       ` [PATCH v5 RESEND 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-19 22:46                         ` Eric Biggers
2023-12-18  1:27                       ` [PATCH v5 RESEND 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2023-12-19 22:48                         ` Eric Biggers
2023-12-20  1:14                           ` Hongyu Jin
2023-12-18  1:27                       ` [PATCH v5 RESEND 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2023-12-19 22:50                         ` Eric Biggers
2023-12-19  0:46                       ` [PATCH v5 RESEND 0/5] Fix I/O priority lost in device-mapper Eric Biggers
2023-12-13 10:42               ` [PATCH v5 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-13 10:42               ` [PATCH v5 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-13 10:42               ` [PATCH v5 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2023-12-13 10:42               ` [PATCH v5 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2023-12-20 10:03                 ` [PATCH v6 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2023-12-20 10:03                   ` [PATCH v6 1/5] block: Fix bio IO priority setting Hongyu Jin
2023-12-20 10:03                   ` [PATCH v6 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-20 10:03                   ` [PATCH v6 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-20 10:03                   ` Hongyu Jin [this message]
2023-12-20 18:32                     ` [PATCH v6 4/5] dm verity: Fix I/O priority lost when read FEC and hash Eric Biggers
2023-12-20 10:03                   ` [PATCH v6 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2023-12-21 10:31                     ` [PATCH v7 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2023-12-21 10:31                       ` [PATCH v7 1/5] block: Fix bio IO priority setting Hongyu Jin
2023-12-21 10:31                       ` [PATCH v7 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2023-12-21 10:31                       ` [PATCH v7 3/5] dm-bufio: Support I/O priority Hongyu Jin
2023-12-21 10:31                       ` [PATCH v7 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2023-12-21 10:31                       ` [PATCH v7 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2024-01-24  5:35                         ` [PATCH v8 0/5] Fix I/O priority lost in device-mapper Hongyu Jin
2024-01-24  5:35                           ` [PATCH v8 1/5] block: Fix bio IO priority setting Hongyu Jin
2024-01-24  5:35                           ` [PATCH v8 2/5] dm: Support I/O priority for dm_io() Hongyu Jin
2024-01-24  5:35                           ` [PATCH v8 3/5] dm-bufio: Support I/O priority Hongyu Jin
2024-01-24  5:35                           ` [PATCH v8 4/5] dm verity: Fix I/O priority lost when read FEC and hash Hongyu Jin
2024-01-24  5:35                           ` [PATCH v8 5/5] dm-crypt: Fix lost ioprio when queuing write bios Hongyu Jin
2024-01-29 16:30                           ` [PATCH v8 0/5] Fix I/O priority lost in device-mapper Mike Snitzer
2024-01-29 19:29                           ` Mikulas Patocka
2023-12-23 15:41                       ` [PATCH v7 " Eric Biggers

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=20231220100333.107049-5-hongyu.jin.cn@gmail.com \
    --to=hongyu.jin.cn@gmail.com \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@lists.linux.dev \
    --cc=ebiggers@kernel.org \
    --cc=hongyu.jin@unisoc.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    --cc=yibin.ding@unisoc.com \
    --cc=zhiguo.niu@unisoc.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 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).