* [PATCH 0/8][next] Avoid a couple hundred -Wflex-array-member-not-at-end warnings
@ 2025-02-24 9:53 Gustavo A. R. Silva
2025-02-24 10:01 ` [PATCH 8/8][next] bcache: Avoid " Gustavo A. R. Silva
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 9:53 UTC (permalink / raw)
To: Jens Axboe, Song Liu, Yu Kuai, Carlos Maiolino, Darrick J. Wong,
Gao Xiang, Chao Yu, Yue Hu, Jeffle Xu, Sandeep Dhavale,
Chris Mason, Josef Bacik, David Sterba, Christoph Hellwig,
Sagi Grimberg, Chaitanya Kulkarni, Coly Li, Kent Overstreet
Cc: linux-raid, linux-kernel, Gustavo A. R. Silva, linux-hardening,
linux-block, linux-xfs, linux-erofs, linux-btrfs, linux-nvme,
linux-bcache
This patch series aims to fix a couple hundred -Wflex-array-member-not-at-end
warnings by creating a new tagged struct `struct bio_hdr` within flexible
structure `struct bio`.
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
Gustavo A. R. Silva (8):
block: blk_types.h: Use struct_group_tagged() in flex struct bio
md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning
xfs: Avoid -Wflex-array-member-not-at-end warnings
erofs: Avoid -Wflex-array-member-not-at-end warnings
btrfs: Avoid -Wflex-array-member-not-at-end warnings
nvme: target: Avoid -Wflex-array-member-not-at-end warnings
md/raid5: Avoid -Wflex-array-member-not-at-end warnings
bcache: Avoid -Wflex-array-member-not-at-end warnings
drivers/md/bcache/bcache.h | 4 +-
drivers/md/bcache/journal.c | 10 ++--
drivers/md/bcache/journal.h | 4 +-
drivers/md/bcache/super.c | 8 ++--
drivers/md/raid5-ppl.c | 8 ++--
drivers/md/raid5.c | 10 ++--
drivers/md/raid5.h | 2 +-
drivers/nvme/target/nvmet.h | 4 +-
drivers/nvme/target/passthru.c | 2 +-
drivers/nvme/target/zns.c | 2 +-
fs/btrfs/disk-io.c | 4 +-
fs/btrfs/volumes.h | 2 +-
fs/erofs/fileio.c | 25 ++++++----
fs/erofs/fscache.c | 13 +++---
fs/xfs/xfs_log.c | 15 +++---
fs/xfs/xfs_log_priv.h | 2 +-
include/linux/blk_types.h | 84 ++++++++++++++++++----------------
17 files changed, 107 insertions(+), 92 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end warnings
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 10:01 ` Gustavo A. R. Silva
2025-02-24 14:04 ` Coly Li
0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-02-24 10:01 UTC (permalink / raw)
To: Coly Li, Kent Overstreet
Cc: linux-bcache, linux-kernel, Gustavo A. R. Silva, linux-hardening
-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.
Change the type of the middle struct members currently causing trouble
from `struct bio` to `struct bio_hdr`.
We also use `container_of()` whenever we need to retrieve a pointer to
the flexible structure `struct bio`, through which we can access the
flexible-array member in it, if necessary.
With these changes fix 112 of the following warnings:
drivers/md/bcache/bcache.h:233:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:241:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:242:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:308:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:422:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/bcache.h:639:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/journal.h:152:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
drivers/md/bcache/journal.h:156:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/md/bcache/bcache.h | 4 ++--
drivers/md/bcache/journal.c | 10 +++++-----
drivers/md/bcache/journal.h | 4 ++--
drivers/md/bcache/super.c | 8 +++++---
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 785b0d9008fa..328023e90eb2 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -305,7 +305,7 @@ struct cached_dev {
struct cache_sb sb;
struct cache_sb_disk *sb_disk;
- struct bio sb_bio;
+ struct bio_hdr sb_bio;
struct bio_vec sb_bv[1];
struct closure sb_write;
struct semaphore sb_write_mutex;
@@ -419,7 +419,7 @@ struct cache {
struct cache_set *set;
struct cache_sb sb;
struct cache_sb_disk *sb_disk;
- struct bio sb_bio;
+ struct bio_hdr sb_bio;
struct bio_vec sb_bv[1];
struct kobject kobj;
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 7ff14bd2feb8..2ead129f7758 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -36,7 +36,7 @@ static int journal_read_bucket(struct cache *ca, struct list_head *list,
unsigned int bucket_index)
{
struct journal_device *ja = &ca->journal;
- struct bio *bio = &ja->bio;
+ struct bio *bio = container_of(&ja->bio, struct bio, __hdr);
struct journal_replay *i;
struct jset *j, *data = ca->set->journal.w[0].data;
@@ -571,7 +571,7 @@ static void btree_flush_write(struct cache_set *c)
static void journal_discard_endio(struct bio *bio)
{
struct journal_device *ja =
- container_of(bio, struct journal_device, discard_bio);
+ container_of(&bio->__hdr, struct journal_device, discard_bio);
struct cache *ca = container_of(ja, struct cache, journal);
atomic_set(&ja->discard_in_flight, DISCARD_DONE);
@@ -585,13 +585,13 @@ static void journal_discard_work(struct work_struct *work)
struct journal_device *ja =
container_of(work, struct journal_device, discard_work);
- submit_bio(&ja->discard_bio);
+ submit_bio(container_of(&ja->discard_bio, struct bio, __hdr));
}
static void do_journal_discard(struct cache *ca)
{
struct journal_device *ja = &ca->journal;
- struct bio *bio = &ja->discard_bio;
+ struct bio *bio = container_of(&ja->discard_bio, struct bio, __hdr);
if (!ca->discard) {
ja->discard_idx = ja->last_idx;
@@ -787,7 +787,7 @@ static CLOSURE_CALLBACK(journal_write_unlocked)
for (i = 0; i < KEY_PTRS(k); i++) {
ca = c->cache;
- bio = &ca->journal.bio;
+ bio = container_of(&ca->journal.bio, struct bio, __hdr);
atomic_long_add(sectors, &ca->meta_sectors_written);
diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h
index cd316b4a1e95..b4ff5269aee3 100644
--- a/drivers/md/bcache/journal.h
+++ b/drivers/md/bcache/journal.h
@@ -149,11 +149,11 @@ struct journal_device {
atomic_t discard_in_flight;
struct work_struct discard_work;
- struct bio discard_bio;
+ struct bio_hdr discard_bio;
struct bio_vec discard_bv;
/* Bio for journal reads/writes to this device */
- struct bio bio;
+ struct bio_hdr bio;
struct bio_vec bv[8];
};
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index e42f1400cea9..cd1342355cf2 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -337,7 +337,7 @@ static CLOSURE_CALLBACK(bch_write_bdev_super_unlock)
void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
{
struct closure *cl = &dc->sb_write;
- struct bio *bio = &dc->sb_bio;
+ struct bio *bio = container_of(&dc->sb_bio, struct bio, __hdr);
down(&dc->sb_write_mutex);
closure_init(cl, parent);
@@ -374,7 +374,7 @@ void bcache_write_super(struct cache_set *c)
{
struct closure *cl = &c->sb_write;
struct cache *ca = c->cache;
- struct bio *bio = &ca->sb_bio;
+ struct bio *bio = container_of(&ca->sb_bio, struct bio, __hdr);
unsigned int version = BCACHE_SB_VERSION_CDEV_WITH_UUID;
down(&c->sb_write_mutex);
@@ -2230,7 +2230,9 @@ static int cache_alloc(struct cache *ca)
__module_get(THIS_MODULE);
kobject_init(&ca->kobj, &bch_cache_ktype);
- bio_init(&ca->journal.bio, NULL, ca->journal.bio.bi_inline_vecs, 8, 0);
+ bio_init(container_of(&ca->journal.bio, struct bio, __hdr), NULL,
+ container_of(&ca->journal.bio, struct bio, __hdr)->bi_inline_vecs,
+ 8, 0);
/*
* when ca->sb.njournal_buckets is not zero, journal exists,
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end warnings
2025-02-24 10:01 ` [PATCH 8/8][next] bcache: Avoid " Gustavo A. R. Silva
@ 2025-02-24 14:04 ` Coly Li
0 siblings, 0 replies; 3+ messages in thread
From: Coly Li @ 2025-02-24 14:04 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: Kent Overstreet, linux-bcache, linux-kernel, linux-hardening
On Mon, Feb 24, 2025 at 08:31:26PM +0800, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end was introduced in GCC-14, and we are
> getting ready to enable it, globally.
>
> Change the type of the middle struct members currently causing trouble
> from `struct bio` to `struct bio_hdr`.
>
> We also use `container_of()` whenever we need to retrieve a pointer to
> the flexible structure `struct bio`, through which we can access the
> flexible-array member in it, if necessary.
>
> With these changes fix 112 of the following warnings:
>
> drivers/md/bcache/bcache.h:233:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:241:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:242:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:308:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:422:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/bcache.h:639:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/journal.h:152:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> drivers/md/bcache/journal.h:156:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Hi Gustavo,
each struct bio followed by a struct bio_vec at the location where
struct bio is embedded into middle of a structure. So the general
flex-array-in-middle issue doesn't exist here indeed.
I don't suggest to introduce extra complication in bcache code.
How about to improve the checking script, if there is no following
struct bio_vec after struct bio, then that should be something really
suspicious.
Thanks.
Coly Li
> ---
> drivers/md/bcache/bcache.h | 4 ++--
> drivers/md/bcache/journal.c | 10 +++++-----
> drivers/md/bcache/journal.h | 4 ++--
> drivers/md/bcache/super.c | 8 +++++---
> 4 files changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
> index 785b0d9008fa..328023e90eb2 100644
> --- a/drivers/md/bcache/bcache.h
> +++ b/drivers/md/bcache/bcache.h
> @@ -305,7 +305,7 @@ struct cached_dev {
>
> struct cache_sb sb;
> struct cache_sb_disk *sb_disk;
> - struct bio sb_bio;
> + struct bio_hdr sb_bio;
> struct bio_vec sb_bv[1];
> struct closure sb_write;
> struct semaphore sb_write_mutex;
> @@ -419,7 +419,7 @@ struct cache {
> struct cache_set *set;
> struct cache_sb sb;
> struct cache_sb_disk *sb_disk;
> - struct bio sb_bio;
> + struct bio_hdr sb_bio;
> struct bio_vec sb_bv[1];
>
> struct kobject kobj;
> diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
> index 7ff14bd2feb8..2ead129f7758 100644
> --- a/drivers/md/bcache/journal.c
> +++ b/drivers/md/bcache/journal.c
> @@ -36,7 +36,7 @@ static int journal_read_bucket(struct cache *ca, struct list_head *list,
> unsigned int bucket_index)
> {
> struct journal_device *ja = &ca->journal;
> - struct bio *bio = &ja->bio;
> + struct bio *bio = container_of(&ja->bio, struct bio, __hdr);
>
> struct journal_replay *i;
> struct jset *j, *data = ca->set->journal.w[0].data;
> @@ -571,7 +571,7 @@ static void btree_flush_write(struct cache_set *c)
> static void journal_discard_endio(struct bio *bio)
> {
> struct journal_device *ja =
> - container_of(bio, struct journal_device, discard_bio);
> + container_of(&bio->__hdr, struct journal_device, discard_bio);
> struct cache *ca = container_of(ja, struct cache, journal);
>
> atomic_set(&ja->discard_in_flight, DISCARD_DONE);
> @@ -585,13 +585,13 @@ static void journal_discard_work(struct work_struct *work)
> struct journal_device *ja =
> container_of(work, struct journal_device, discard_work);
>
> - submit_bio(&ja->discard_bio);
> + submit_bio(container_of(&ja->discard_bio, struct bio, __hdr));
> }
>
> static void do_journal_discard(struct cache *ca)
> {
> struct journal_device *ja = &ca->journal;
> - struct bio *bio = &ja->discard_bio;
> + struct bio *bio = container_of(&ja->discard_bio, struct bio, __hdr);
>
> if (!ca->discard) {
> ja->discard_idx = ja->last_idx;
> @@ -787,7 +787,7 @@ static CLOSURE_CALLBACK(journal_write_unlocked)
>
> for (i = 0; i < KEY_PTRS(k); i++) {
> ca = c->cache;
> - bio = &ca->journal.bio;
> + bio = container_of(&ca->journal.bio, struct bio, __hdr);
>
> atomic_long_add(sectors, &ca->meta_sectors_written);
>
> diff --git a/drivers/md/bcache/journal.h b/drivers/md/bcache/journal.h
> index cd316b4a1e95..b4ff5269aee3 100644
> --- a/drivers/md/bcache/journal.h
> +++ b/drivers/md/bcache/journal.h
> @@ -149,11 +149,11 @@ struct journal_device {
> atomic_t discard_in_flight;
>
> struct work_struct discard_work;
> - struct bio discard_bio;
> + struct bio_hdr discard_bio;
> struct bio_vec discard_bv;
>
> /* Bio for journal reads/writes to this device */
> - struct bio bio;
> + struct bio_hdr bio;
> struct bio_vec bv[8];
> };
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index e42f1400cea9..cd1342355cf2 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -337,7 +337,7 @@ static CLOSURE_CALLBACK(bch_write_bdev_super_unlock)
> void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
> {
> struct closure *cl = &dc->sb_write;
> - struct bio *bio = &dc->sb_bio;
> + struct bio *bio = container_of(&dc->sb_bio, struct bio, __hdr);
>
> down(&dc->sb_write_mutex);
> closure_init(cl, parent);
> @@ -374,7 +374,7 @@ void bcache_write_super(struct cache_set *c)
> {
> struct closure *cl = &c->sb_write;
> struct cache *ca = c->cache;
> - struct bio *bio = &ca->sb_bio;
> + struct bio *bio = container_of(&ca->sb_bio, struct bio, __hdr);
> unsigned int version = BCACHE_SB_VERSION_CDEV_WITH_UUID;
>
> down(&c->sb_write_mutex);
> @@ -2230,7 +2230,9 @@ static int cache_alloc(struct cache *ca)
> __module_get(THIS_MODULE);
> kobject_init(&ca->kobj, &bch_cache_ktype);
>
> - bio_init(&ca->journal.bio, NULL, ca->journal.bio.bi_inline_vecs, 8, 0);
> + bio_init(container_of(&ca->journal.bio, struct bio, __hdr), NULL,
> + container_of(&ca->journal.bio, struct bio, __hdr)->bi_inline_vecs,
> + 8, 0);
>
> /*
> * when ca->sb.njournal_buckets is not zero, journal exists,
> --
> 2.43.0
>
--
Coly Li
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-24 14:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 10:01 ` [PATCH 8/8][next] bcache: Avoid " Gustavo A. R. Silva
2025-02-24 14:04 ` Coly Li
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).