mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org
Subject: [PATCH 1/8][next] block: blk_types.h: Use struct_group_tagged() in flex struct bio
Date: Mon, 24 Feb 2025 20:25:08 +1030	[thread overview]
Message-ID: <ccf673b997e771430b7570fb8a6dfc11d07a2bde.1739957534.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1739957534.git.gustavoars@kernel.org>

Use the `struct_group_tagged()` helper to create a new tagged
`struct bio_hdr`. This structure groups together all the members of
the flexible `struct bio` except the flexible array `bi_inline_vecs`.
As a result, the array is effectively separated from the rest of the
members without modifying the memory layout of the flexible structure.

This new tagged struct will be used to fix problematic declarations
of middle-flex-arrays in composite structs, like these[1][2][3], for
instance.

[1] https://git.kernel.org/linus/a7e8997ae18c42d3
[2] https://git.kernel.org/linus/c1ddb29709e675ea
[3] https://git.kernel.org/linus/57be3d3562ca4aa6

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 include/linux/blk_types.h | 84 ++++++++++++++++++++-------------------
 1 file changed, 44 insertions(+), 40 deletions(-)

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index dce7615c35e7..9182750457a8 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -212,62 +212,65 @@ typedef unsigned int blk_qc_t;
  * stacking drivers)
  */
 struct bio {
-	struct bio		*bi_next;	/* request queue link */
-	struct block_device	*bi_bdev;
-	blk_opf_t		bi_opf;		/* bottom bits REQ_OP, top bits
-						 * req_flags.
-						 */
-	unsigned short		bi_flags;	/* BIO_* below */
-	unsigned short		bi_ioprio;
-	enum rw_hint		bi_write_hint;
-	blk_status_t		bi_status;
-	atomic_t		__bi_remaining;
-
-	struct bvec_iter	bi_iter;
-
-	union {
-		/* for polled bios: */
-		blk_qc_t		bi_cookie;
-		/* for plugged zoned writes only: */
-		unsigned int		__bi_nr_segments;
-	};
-	bio_end_io_t		*bi_end_io;
-	void			*bi_private;
+	/* New members MUST be added within the struct_group() macro below. */
+	struct_group_tagged(bio_hdr, __hdr,
+		struct bio		*bi_next;	/* request queue link */
+		struct block_device	*bi_bdev;
+		blk_opf_t		bi_opf;		/* bottom bits REQ_OP, top bits
+							 * req_flags.
+							 */
+		unsigned short		bi_flags;	/* BIO_* below */
+		unsigned short		bi_ioprio;
+		enum rw_hint		bi_write_hint;
+		blk_status_t		bi_status;
+		atomic_t		__bi_remaining;
+
+		struct bvec_iter	bi_iter;
+
+		union {
+			/* for polled bios: */
+			blk_qc_t		bi_cookie;
+			/* for plugged zoned writes only: */
+			unsigned int		__bi_nr_segments;
+		};
+		bio_end_io_t		*bi_end_io;
+		void			*bi_private;
 #ifdef CONFIG_BLK_CGROUP
-	/*
-	 * Represents the association of the css and request_queue for the bio.
-	 * If a bio goes direct to device, it will not have a blkg as it will
-	 * not have a request_queue associated with it.  The reference is put
-	 * on release of the bio.
-	 */
-	struct blkcg_gq		*bi_blkg;
-	struct bio_issue	bi_issue;
+		/*
+		 * Represents the association of the css and request_queue for the bio.
+		 * If a bio goes direct to device, it will not have a blkg as it will
+		 * not have a request_queue associated with it.  The reference is put
+		 * on release of the bio.
+		 */
+		struct blkcg_gq		*bi_blkg;
+		struct bio_issue	bi_issue;
 #ifdef CONFIG_BLK_CGROUP_IOCOST
-	u64			bi_iocost_cost;
+		u64			bi_iocost_cost;
 #endif
 #endif
 
 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
-	struct bio_crypt_ctx	*bi_crypt_context;
+		struct bio_crypt_ctx	*bi_crypt_context;
 #endif
 
 #if defined(CONFIG_BLK_DEV_INTEGRITY)
-	struct bio_integrity_payload *bi_integrity; /* data integrity */
+		struct bio_integrity_payload *bi_integrity; /* data integrity */
 #endif
 
-	unsigned short		bi_vcnt;	/* how many bio_vec's */
+		unsigned short		bi_vcnt;	/* how many bio_vec's */
 
-	/*
-	 * Everything starting with bi_max_vecs will be preserved by bio_reset()
-	 */
+		/*
+		 * Everything starting with bi_max_vecs will be preserved by bio_reset()
+		 */
 
-	unsigned short		bi_max_vecs;	/* max bvl_vecs we can hold */
+		unsigned short		bi_max_vecs;	/* max bvl_vecs we can hold */
 
-	atomic_t		__bi_cnt;	/* pin count */
+		atomic_t		__bi_cnt;	/* pin count */
 
-	struct bio_vec		*bi_io_vec;	/* the actual vec list */
+		struct bio_vec		*bi_io_vec;	/* the actual vec list */
 
-	struct bio_set		*bi_pool;
+		struct bio_set		*bi_pool;
+	);
 
 	/*
 	 * We can inline a number of vecs at the end of the bio, to avoid
@@ -276,6 +279,8 @@ struct bio {
 	 */
 	struct bio_vec		bi_inline_vecs[];
 };
+static_assert(offsetof(struct bio, bi_inline_vecs) == sizeof(struct bio_hdr),
+	      "struct member likely outside of struct_group_tagged()");
 
 #define BIO_RESET_BYTES		offsetof(struct bio, bi_max_vecs)
 #define BIO_MAX_SECTORS		(UINT_MAX >> SECTOR_SHIFT)
-- 
2.43.0


  reply	other threads:[~2025-02-24  9:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24  9:53 [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-02-24  9:55 ` Gustavo A. R. Silva [this message]
2025-02-24 16:39   ` [PATCH 1/8][next] block: blk_types.h: Use struct_group_tagged() in flex struct bio Christoph Hellwig
2025-02-24  9:56 ` [PATCH 2/8][next] md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-02-24  9:57 ` [PATCH 3/8][next] xfs: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-02-24 19:12   ` Darrick J. Wong
2025-02-24 21:45   ` Dave Chinner
2025-02-24  9:58 ` [PATCH 4/8][next] erofs: " Gustavo A. R. Silva
2025-02-24  9:59 ` [PATCH 5/8][next] btrfs: " Gustavo A. R. Silva
2025-02-24 10:00 ` [PATCH 6/8][next] nvme: target: " Gustavo A. R. Silva
2025-02-24 14:19   ` Christoph Hellwig
2025-02-25  1:51     ` Gustavo A. R. Silva
2025-02-24 10:00 ` [PATCH 7/8][next] md/raid5: " Gustavo A. R. Silva
2025-02-24 10:01 ` [PATCH 8/8][next] bcache: " Gustavo A. R. Silva
2025-02-24 14:04   ` Coly Li

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=ccf673b997e771430b7570fb8a6dfc11d07a2bde.1739957534.git.gustavoars@kernel.org \
    --to=gustavoars@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-hardening@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®