LKML Archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: axboe@kernel.dk, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Subject: [PATCH v2 5/5] block: CONFIG_BLK_DEBUG
Date: Mon,  5 Jun 2023 17:27:17 -0400	[thread overview]
Message-ID: <20230605212717.2570570-5-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20230605212717.2570570-1-kent.overstreet@linux.dev>

This adds a new kconfig option to enable some extra debug mode
assertions. Currently this is just used for some bio iterator
assertions, but hopefully more will be added in the future.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 block/Kconfig        | 7 +++++++
 include/linux/bio.h  | 5 +++++
 include/linux/bvec.h | 8 ++++++++
 3 files changed, 20 insertions(+)

diff --git a/block/Kconfig b/block/Kconfig
index 86122e459f..611dddb59c 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -165,6 +165,13 @@ config BLK_CGROUP_IOPRIO
 	scheduler and block devices process requests. Only some I/O schedulers
 	and some block devices support I/O priorities.
 
+config BLK_DEBUG
+	bool "Extra block layer assertions"
+	depends on DEBUG_KERNEL
+	help
+	Enable extra assertions in the block layer. Currently this is just the
+	bio iterator code, but may be expanded.
+
 config BLK_DEBUG_FS
 	bool "Block layer debugging information in debugfs"
 	default y
diff --git a/include/linux/bio.h b/include/linux/bio.h
index f599bcf15e..cece57c54d 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -81,6 +81,8 @@ static inline void *bio_data(struct bio *bio)
 static inline struct bio_vec bio_iter_all_peek(const struct bio *bio,
 					       struct bvec_iter_all *iter)
 {
+	BLK_BUG_ON(iter->idx >= bio->bi_vcnt);
+
 	return bvec_iter_all_peek(bio->bi_io_vec, iter);
 }
 
@@ -89,6 +91,9 @@ static inline void bio_iter_all_advance(const struct bio *bio,
 					unsigned bytes)
 {
 	bvec_iter_all_advance(bio->bi_io_vec, iter, bytes);
+
+	BLK_BUG_ON(iter->idx > bio->bi_vcnt ||
+		   (iter->idx == bio->bi_vcnt && iter->done));
 }
 
 #define bio_for_each_segment_all_continue(bvl, bio, iter)		\
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index ee5965fedf..2467245da2 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -16,6 +16,12 @@
 
 struct page;
 
+#ifdef CONFIG_BLK_DEBUG
+#define BLK_BUG_ON(cond) BUG_ON(cond)
+#else
+#define BLK_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
+#endif
+
 /**
  * struct bio_vec - a contiguous range of physical memory addresses
  * @bv_page:   First page associated with the address range.
@@ -210,6 +216,8 @@ static inline struct bio_vec __bvec_iter_all_peek(const struct bio_vec *bvec,
 {
 	struct bio_vec bv = bvec[iter->idx];
 
+	BLK_BUG_ON(iter->done >= bv.bv_len);
+
 	bv.bv_offset	+= iter->done;
 	bv.bv_len	-= iter->done;
 
-- 
2.40.1


  parent reply	other threads:[~2023-06-05 21:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 21:27 [PATCH v2 1/5] block: Rework bio_for_each_segment_all() Kent Overstreet
2023-06-05 21:27 ` [PATCH v2 2/5] block: Rework bio_for_each_folio_all() Kent Overstreet
2023-06-05 21:27 ` [PATCH v2 3/5] block: Add documentation for bio iterator macros Kent Overstreet
2023-06-05 21:27 ` [PATCH v2 4/5] block: Change memcpy_(to|from)_bvec to pass bvec by value Kent Overstreet
2023-06-06  7:31   ` kernel test robot
2023-06-05 21:27 ` Kent Overstreet [this message]
2023-06-05 22:41   ` [PATCH v2 5/5] block: CONFIG_BLK_DEBUG Randy Dunlap
2023-06-06  2:03 ` [PATCH v2 1/5] block: Rework bio_for_each_segment_all() Ming Lei
2023-06-06  7:29   ` Kent Overstreet
2023-06-09 20:44 ` Kent Overstreet

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=20230605212717.2570570-5-kent.overstreet@linux.dev \
    --to=kent.overstreet@linux.dev \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).