From patchwork Mon Feb 24 09:55:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987700 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D73624A070; Mon, 24 Feb 2025 09:55:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740390913; cv=none; b=D7vtUUDqSyRSw2Q2lTSncOJK02QyNBDoBAYuAaVLaMAbL9bi904VyQGcEOKQkuCGoZuO8mU86OG5hXJP6g0FWhUuDrRuHvSvXscMLopEcPzfhRSHOOhSDbenY+vq18v9IUwGByQoFt6cLZZeM3LmqW3prf4wn4NlEr2GVtW1jgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740390913; c=relaxed/simple; bh=byIhktOyiyjAT4tz5qNe5uSyIyc4GSH4aaX66A2Opd8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GglxrGZ2cV005dA/aFvVritQqdqSeVfJXlEDwTihbTwBFxC2wuPH8VLaAmxMD00FR6OBMFjE4mz1ojf5JLnJd4nJ2UpFnDkKCECr47SCGZYBfGd4FwtGGGX1yVV2miEtHz2JJY9lJEd10ew1Fe9/S0MYr4c6ZKVp1wYKGEmgbCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S5Q0fC/g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S5Q0fC/g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80D3CC4CEE6; Mon, 24 Feb 2025 09:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740390912; bh=byIhktOyiyjAT4tz5qNe5uSyIyc4GSH4aaX66A2Opd8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S5Q0fC/gA7kzvRu6w33dKn2qtGQ4PIrfEeniWR6yVVJrhZno+oR71sMIy1kLJ5zqf /nJ4QoO73WIjis/PRRRwbyPqhJ0gLn6dN512THTJipWnmMYhs8xGJU0OAnVW9CaRau wU0t2rAMbOURzOgMojHHQiBPqROIUvGnZZLcXeUW4jmEfS3T4Is19ZfQ++sJprqIyk lH1l+aYD62ROqxOF6H0bw3DzeOFKMgsRi/6PMdQi6OnGYcO922UA63Ap2nah09nbvn Wzeisb1uP2IDGXpkJpCdk5c7TWmISfI6oV8b6QQZbiw0D2hVCrOHBQB6iytZOo6nBa FdPKh46w0A/pA== Date: Mon, 24 Feb 2025 20:25:08 +1030 From: "Gustavo A. R. Silva" To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 1/8][next] block: blk_types.h: Use struct_group_tagged() in flex struct bio Message-ID: References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 --- 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) From patchwork Mon Feb 24 09:56:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987728 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 503F124A054; Mon, 24 Feb 2025 09:57:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391025; cv=none; b=I2c9rq7r0z7+ckwP8lfb9kGl9NbzmbPHWDuDnNhmgIheDS9IkYtQkTgweUI2KapQkMdI12xFBlq/nQACydOfjXK8VEmEVPFkZDQmOa9K2YeNy2rBZ+yBNOrGBB0pMYB8CflOGE5C5A2Dwy8BP0+RdjRKA3iJIT9TeyqTa0XBmDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391025; c=relaxed/simple; bh=w0YgVKrRrqyq3WB5LJqdCy80y+/4l0zZSSmJeq9kY8E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BKhyB2WERuiioUWfxY55HJKP7B5P6CrxsjlHOaOMMfnjwwhEF7O1boqYRMESVln5D8mRH5bMHgwj3KlIOFl8lTuRvFcFgcgKBSm4WAcbok+joLwFEZWxAS8UFCPIOA0a4ir612nqJoLgLLLEHtpCHC3Z0ZWrRAfbjOvyk2tL+AI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S/374Pze; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S/374Pze" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F968C4CEE6; Mon, 24 Feb 2025 09:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391024; bh=w0YgVKrRrqyq3WB5LJqdCy80y+/4l0zZSSmJeq9kY8E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S/374PzejpKI2vR+hDuN/rtJADsNlL7nQUGK4fk1OPZeOhCf+7pNb0lCkbzgAOuWC 2uDpUBuSfyhYUKuCBN6Boie5H2szyaz9a2uzBKot3hZ7OPEG13hmFWawORMCAxB+1p SEHoRB/gubJwzIb7S9n5dHM7MVSEC6Ay+bsTJl0mTUqLSkJKOXSWWxKDDW+fIo27Zt AKDIiB3dVGVuvYDj8xsOI+fQEAEr2+ETaS5+5543B+SGExhG8gCUN27SwK4VLUj3RO 9DYHggMuReFIjwvZi1EV8sFV8em3oKZpNgs+MEh5pdZs/AM8oY2+iph05lvFyRRtD/ 5zl2lI5zO6MUw== Date: Mon, 24 Feb 2025 20:26:59 +1030 From: "Gustavo A. R. Silva" To: Song Liu , Yu Kuai Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 2/8][next] md/raid5-ppl: Avoid -Wflex-array-member-not-at-end warning Message-ID: <7ceee2968cd7efa74c6a39147b14bb1b3bc3928c.1739957534.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 member 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 the following warning: drivers/md/raid5-ppl.c:153:20: 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 --- drivers/md/raid5-ppl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c index c0fb335311aa..f4333c644b67 100644 --- a/drivers/md/raid5-ppl.c +++ b/drivers/md/raid5-ppl.c @@ -150,7 +150,7 @@ struct ppl_io_unit { bool submitted; /* true if write to log started */ /* inline bio and its biovec for submitting the iounit */ - struct bio bio; + struct bio_hdr bio; struct bio_vec biovec[PPL_IO_INLINE_BVECS]; }; @@ -250,8 +250,8 @@ static struct ppl_io_unit *ppl_new_iounit(struct ppl_log *log, INIT_LIST_HEAD(&io->stripe_list); atomic_set(&io->pending_stripes, 0); atomic_set(&io->pending_flushes, 0); - bio_init(&io->bio, log->rdev->bdev, io->biovec, PPL_IO_INLINE_BVECS, - REQ_OP_WRITE | REQ_FUA); + bio_init(container_of(&io->bio, struct bio, __hdr), log->rdev->bdev, + io->biovec, PPL_IO_INLINE_BVECS, REQ_OP_WRITE | REQ_FUA); pplhdr = page_address(io->header_page); clear_page(pplhdr); @@ -430,7 +430,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io) struct ppl_log *log = io->log; struct ppl_conf *ppl_conf = log->ppl_conf; struct ppl_header *pplhdr = page_address(io->header_page); - struct bio *bio = &io->bio; + struct bio *bio = container_of(&io->bio, struct bio, __hdr); struct stripe_head *sh; int i; From patchwork Mon Feb 24 09:57:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987729 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 344C02505B7; Mon, 24 Feb 2025 09:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391069; cv=none; b=CDCDTddcGNurCPJPVW39XktWLeKCncBY/F5a2pciUXu0ivNvYLdSS63GnV9klJtp8WE6zs2fCY0TMCUMmAafNDE8SzH3yrsaAbHXaRdNDU6C8WFvANd2lMxdwQxY+9FuZ/xfHgi0sT55l1e9urNszhoWW084Zzy5sdoXmwEJw7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391069; c=relaxed/simple; bh=iE537x/MELrUY0Qtk8aCd5YLeWWHG15hTl09B9wGRWM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SQF99Ogla2XncNWI19M3IJU952sY2Oey+5XltVQ7vkN7+I0Do/BBp+tqJ9JQjaMRn+JicHHiANkrohn5T4rmeG7Er1/IShdy6lCoBzoc8Gqu52HuXiqZTtljeIf6hgMFBWb3gNVpGcf3atH/z7GLLBQh3RDsEUd+R6IEMYZtGr8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TfIFXDJe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TfIFXDJe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 098C3C4CEE8; Mon, 24 Feb 2025 09:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391068; bh=iE537x/MELrUY0Qtk8aCd5YLeWWHG15hTl09B9wGRWM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TfIFXDJen3mMesTjG7OhjLyO68Lu9krViqA7VC3vhkwnLojy4G3CBiTdUmL3na5zf ey2d8msVYSk18M5THfX+RJdtV/35HTBjjiieiPT1B9lKgRxUblNdrLhnR090a4dUDp FkP/7/PnwOILK+QWx4uFaUo67l3z3VqYe5pzZuknUTsNQ5E5UX2KyDSU5kOlq4JXSs Z1Bwr4k9KLgdBR37JAv6X9l6o/j1iGueZhQVbXva5c1h8hjI9PZAm1jeoz8P9C78du Upp41f6hNuhj6KQ/6UrooNmrkqTQr4K66zIME/NA1If65Ly8AwVuuEYnio7f84sn8m j8jH/pA1AvlLQ== Date: Mon, 24 Feb 2025 20:27:44 +1030 From: "Gustavo A. R. Silva" To: Carlos Maiolino , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 3/8][next] xfs: Avoid -Wflex-array-member-not-at-end warnings Message-ID: References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 27 of the following warnings: fs/xfs/xfs_log_priv.h:208: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 --- fs/xfs/xfs_log.c | 15 +++++++++------ fs/xfs/xfs_log_priv.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index f8851ff835de..7e8b71f64a46 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -1245,7 +1245,7 @@ xlog_ioend_work( } xlog_state_done_syncing(iclog); - bio_uninit(&iclog->ic_bio); + bio_uninit(container_of(&iclog->ic_bio, struct bio, __hdr)); /* * Drop the lock to signal that we are done. Nothing references the @@ -1663,7 +1663,8 @@ xlog_write_iclog( * writeback throttle from throttling log writes behind background * metadata writeback and causing priority inversions. */ - bio_init(&iclog->ic_bio, log->l_targ->bt_bdev, iclog->ic_bvec, + bio_init(container_of(&iclog->ic_bio, struct bio, __hdr), + log->l_targ->bt_bdev, iclog->ic_bvec, howmany(count, PAGE_SIZE), REQ_OP_WRITE | REQ_META | REQ_SYNC | REQ_IDLE); iclog->ic_bio.bi_iter.bi_sector = log->l_logBBstart + bno; @@ -1692,7 +1693,8 @@ xlog_write_iclog( iclog->ic_flags &= ~(XLOG_ICL_NEED_FLUSH | XLOG_ICL_NEED_FUA); - if (xlog_map_iclog_data(&iclog->ic_bio, iclog->ic_data, count)) + if (xlog_map_iclog_data(container_of(&iclog->ic_bio, struct bio, __hdr), + iclog->ic_data, count)) goto shutdown; if (is_vmalloc_addr(iclog->ic_data)) @@ -1705,16 +1707,17 @@ xlog_write_iclog( if (bno + BTOBB(count) > log->l_logBBsize) { struct bio *split; - split = bio_split(&iclog->ic_bio, log->l_logBBsize - bno, + split = bio_split(container_of(&iclog->ic_bio, struct bio, __hdr), + log->l_logBBsize - bno, GFP_NOIO, &fs_bio_set); - bio_chain(split, &iclog->ic_bio); + bio_chain(split, container_of(&iclog->ic_bio, struct bio, __hdr)); submit_bio(split); /* restart at logical offset zero for the remainder */ iclog->ic_bio.bi_iter.bi_sector = log->l_logBBstart; } - submit_bio(&iclog->ic_bio); + submit_bio(container_of(&iclog->ic_bio, struct bio, __hdr)); return; shutdown: xlog_force_shutdown(log, SHUTDOWN_LOG_IO_ERROR); diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index f3d78869e5e5..32abc48aef24 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h @@ -205,7 +205,7 @@ typedef struct xlog_in_core { #endif struct semaphore ic_sema; struct work_struct ic_end_io_work; - struct bio ic_bio; + struct bio_hdr ic_bio; struct bio_vec ic_bvec[]; } xlog_in_core_t; From patchwork Mon Feb 24 09:58:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987730 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07599241CA6; Mon, 24 Feb 2025 09:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391129; cv=none; b=qIG7AI5gDE7jtAZN9+Tm/VMkhR5UYCIsZG0njnajUGMRAQvUrmyVr7GEjZeshKDFFBTgXbkHhMS9tUaLyxz46K6FpieRdDG9mrBaasSXadbK5YDwfZCD8Dp1KEXtLrvNRScUwmHgr5XcM9k38hhZ4OQIDogfvGRcB9fOluSFWuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391129; c=relaxed/simple; bh=ZjDnXrksprqcdBpDIG/amfeXKgB6c4lJruai5qe5AhA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kRezzpmoXdHAjcx5ptw32YSazg4kDJ0ZZ8GzFMwNqKjkYeaAw7BNnepEuGjxr+a+7KqNYdIor2KycJDuqcWke6ICuNTWk7c/aaVPLx5LUapAbf5ZfXeGN0R9qcH/Rb6P2/MLT7uPudfLhaRlDzOJ5dbTGa0Nw6g+O55MPLQvZXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PO1llj0k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PO1llj0k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30C03C4CED6; Mon, 24 Feb 2025 09:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391128; bh=ZjDnXrksprqcdBpDIG/amfeXKgB6c4lJruai5qe5AhA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PO1llj0k12h5/Jb8CQuV57BkdgYfH/eqbVrzvtMdBv4G6bGDgxunu7xzsOu2NcAHI PlCedtu+UkUKI2UZXTaIRl0ltFlFDeBPxRC83CzYSEPFqd9bp3ovwjLYLSljJxTagn oQMHZa4qstKk4u3mvru+7XQSTjUiTQk13D5PzzBJChsWn2qBBphPqTK7QToFd0sa+8 1ke1OxIH4CQChKZDNFzuPV765Og8okFL3psFARQzGAGcWXX7OWRgBsLkFUxf0X+hBS nkPPO3ctYZmqfgdFMDw2V+50D0ky4xivMPA1a1rP4V7OeKV3G3ikmsJPkHkS3frsB8 HeGzCJ72wsshw== Date: Mon, 24 Feb 2025 20:28:43 +1030 From: "Gustavo A. R. Silva" To: Gao Xiang , Chao Yu , Yue Hu , Jeffle Xu , Sandeep Dhavale Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 4/8][next] erofs: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <334f60e884cc0314ef98731e60a1b419e462e2d2.1739957534.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 member 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 the following warnings: fs/erofs/fileio.c:10:20: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] fs/erofs/fscache.c:179:20: 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 --- fs/erofs/fileio.c | 25 +++++++++++++++---------- fs/erofs/fscache.c | 13 +++++++------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/fs/erofs/fileio.c b/fs/erofs/fileio.c index 0ffd1c63beeb..3080963caf78 100644 --- a/fs/erofs/fileio.c +++ b/fs/erofs/fileio.c @@ -7,7 +7,7 @@ struct erofs_fileio_rq { struct bio_vec bvecs[16]; - struct bio bio; + struct bio_hdr bio; struct kiocb iocb; struct super_block *sb; }; @@ -26,20 +26,21 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret) if (ret > 0) { if (ret != rq->bio.bi_iter.bi_size) { - bio_advance(&rq->bio, ret); - zero_fill_bio(&rq->bio); + bio_advance(container_of(&rq->bio, struct bio, __hdr), + ret); + zero_fill_bio(container_of(&rq->bio, struct bio, __hdr)); } ret = 0; } if (rq->bio.bi_end_io) { - rq->bio.bi_end_io(&rq->bio); + rq->bio.bi_end_io(container_of(&rq->bio, struct bio, __hdr)); } else { - bio_for_each_folio_all(fi, &rq->bio) { + bio_for_each_folio_all(fi, container_of(&rq->bio, struct bio, __hdr)) { DBG_BUGON(folio_test_uptodate(fi.folio)); erofs_onlinefolio_end(fi.folio, ret); } } - bio_uninit(&rq->bio); + bio_uninit(container_of(&rq->bio, struct bio, __hdr)); kfree(rq); } @@ -68,7 +69,8 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev) struct erofs_fileio_rq *rq = kzalloc(sizeof(*rq), GFP_KERNEL | __GFP_NOFAIL); - bio_init(&rq->bio, NULL, rq->bvecs, ARRAY_SIZE(rq->bvecs), REQ_OP_READ); + bio_init(container_of(&rq->bio, struct bio, __hdr), NULL, rq->bvecs, + ARRAY_SIZE(rq->bvecs), REQ_OP_READ); rq->iocb.ki_filp = mdev->m_dif->file; rq->sb = mdev->m_sb; return rq; @@ -76,12 +78,13 @@ static struct erofs_fileio_rq *erofs_fileio_rq_alloc(struct erofs_map_dev *mdev) struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev) { - return &erofs_fileio_rq_alloc(mdev)->bio; + return container_of(&erofs_fileio_rq_alloc(mdev)->bio, struct bio, __hdr); } void erofs_fileio_submit_bio(struct bio *bio) { - return erofs_fileio_rq_submit(container_of(bio, struct erofs_fileio_rq, + return erofs_fileio_rq_submit(container_of(&bio->__hdr, + struct erofs_fileio_rq, bio)); } @@ -150,7 +153,9 @@ static int erofs_fileio_scan_folio(struct erofs_fileio *io, struct folio *folio) } if (!attached++) erofs_onlinefolio_split(folio); - if (!bio_add_folio(&io->rq->bio, folio, len, cur)) + if (!bio_add_folio(container_of(&io->rq->bio, + struct bio, __hdr), + folio, len, cur)) goto io_retry; io->dev.m_pa += len; } diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index ce3d8737df85..719ec96c8f22 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -176,7 +176,7 @@ static int erofs_fscache_read_io_async(struct fscache_cookie *cookie, struct erofs_fscache_bio { struct erofs_fscache_io io; - struct bio bio; /* w/o bdev to share bio_add_page/endio() */ + struct bio_hdr bio; /* w/o bdev to share bio_add_page/endio() */ struct bio_vec bvecs[BIO_MAX_VECS]; }; @@ -187,7 +187,7 @@ static void erofs_fscache_bio_endio(void *priv, if (IS_ERR_VALUE(transferred_or_error)) io->bio.bi_status = errno_to_blk_status(transferred_or_error); - io->bio.bi_end_io(&io->bio); + io->bio.bi_end_io(container_of(&io->bio, struct bio, __hdr)); BUILD_BUG_ON(offsetof(struct erofs_fscache_bio, io) != 0); erofs_fscache_io_put(&io->io); } @@ -197,17 +197,18 @@ struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) struct erofs_fscache_bio *io; io = kmalloc(sizeof(*io), GFP_KERNEL | __GFP_NOFAIL); - bio_init(&io->bio, NULL, io->bvecs, BIO_MAX_VECS, REQ_OP_READ); + bio_init(container_of(&io->bio, struct bio, __hdr), NULL, io->bvecs, + BIO_MAX_VECS, REQ_OP_READ); io->io.private = mdev->m_dif->fscache->cookie; io->io.end_io = erofs_fscache_bio_endio; refcount_set(&io->io.ref, 1); - return &io->bio; + return container_of(&io->bio, struct bio, __hdr); } void erofs_fscache_submit_bio(struct bio *bio) { - struct erofs_fscache_bio *io = container_of(bio, - struct erofs_fscache_bio, bio); + struct erofs_fscache_bio *io = + container_of(&bio->__hdr, struct erofs_fscache_bio, bio); int ret; iov_iter_bvec(&io->io.iter, ITER_DEST, io->bvecs, bio->bi_vcnt, From patchwork Mon Feb 24 09:59:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987731 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F33F724A055; Mon, 24 Feb 2025 09:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391179; cv=none; b=cAprZK2UqoD+1BPejFidxX5I2FH5u/tiCjfOuP6pklcPhPzUDtlEzS3GZThGBXeBGefwmDFX3qrY2id/pIhAsQxm53mLZpi3PX+ntAV9Fy5mna852FDfe3xvA0H1bSdB/bdPieBPxo9pqaIN3Mt0br4SMVCV0PSfGkuev44or2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391179; c=relaxed/simple; bh=JD9u2n4cKf6e0QtZVKFcf81ujOiCIVUWgua9u8tSrsQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lQy6iA77gmatYXXSMYtpSuvNCd/rVzXhxhbUYVmsz2WIIwaqJ7M45F+/7TJZg20Zwc+DO9nOZTvLqbsDqWznxtWZvBeBXb1PyYwE48PAqgtg9DK9uO1YHgj49NkCJbdmG8k/sG3qKeT/ebyPnGa2V2gLio64CnX22/Fvtw1zaq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mt7VpsZ5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mt7VpsZ5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A77ACC4CED6; Mon, 24 Feb 2025 09:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391178; bh=JD9u2n4cKf6e0QtZVKFcf81ujOiCIVUWgua9u8tSrsQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mt7VpsZ5j8y+PBbwYsYxpNA4RJWvvA86wI3pBKKsFN2p1OtYFIX/WL9KHHGPTlQLY 52pWQBBd//obrDtblygqoNbJ9zWGZh+bW2P1aL6wyviMk2W91vb2d6eRo42mzF0cqy c7UPaq+v+OFLs4wE1I+yiRco7x+9KcA6Ocg9imKZEa0eYR4Cl+tkp951nM4+DzRDOF E2JuLn1T5gLz6S4AIzUSn0o1kHXJfT0dh70kthXcYxSFs+D0duQg5bLOXzpyEnFfGu i7WsqbU00Q9+o5EErsXfrjKIHtnyx0+zb3WyCHthc7BRF02j6tnTaDmM35BDGzSPae cJ2eHlShHxx9Q== Date: Mon, 24 Feb 2025 20:29:34 +1030 From: "Gustavo A. R. Silva" To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 5/8][next] btrfs: Avoid -Wflex-array-member-not-at-end warnings Message-ID: <3c3310a23caf3d78ae62c85c9476d5dfe4a1f871.1739957534.git.gustavoars@kernel.org> References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 member 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 32 of the following warnings: fs/btrfs/volumes.h:178:20: 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 --- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/volumes.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f09db62e61a1..2fbaaa9ab3e3 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3963,7 +3963,7 @@ static void btrfs_end_empty_barrier(struct bio *bio) */ static void write_dev_flush(struct btrfs_device *device) { - struct bio *bio = &device->flush_bio; + struct bio *bio = container_of(&device->flush_bio, struct bio, __hdr); device->last_flush_error = BLK_STS_OK; @@ -3982,7 +3982,7 @@ static void write_dev_flush(struct btrfs_device *device) */ static bool wait_dev_flush(struct btrfs_device *device) { - struct bio *bio = &device->flush_bio; + struct bio *bio = container_of(&device->flush_bio, struct bio, __hdr); if (!test_and_clear_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state)) return false; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 120f65e21eeb..6eb55103b3d1 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -175,7 +175,7 @@ struct btrfs_device { u64 commit_bytes_used; /* Bio used for flushing device barriers */ - struct bio flush_bio; + struct bio_hdr flush_bio; struct completion flush_wait; /* per-device scrub information */ From patchwork Mon Feb 24 10:00:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987732 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A7A224BC13; Mon, 24 Feb 2025 10:00:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391217; cv=none; b=ehVOq1gEmuNYoG39Use/e0gkLtnTnAM+hJMWyYd5AlrrRmzHcWhEdzTLWXhvp2k6KzCCtzwstBz6xs/b7qCX7EuD/fmWpfUNHGuoLWd7pFTlLbM1LxS03qJxEJhEUpBUOgxeD/VZEA+jdI62ITVmuZ+6F2zJ59De0nIqgUgpsgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391217; c=relaxed/simple; bh=A9uQN4pgxmAPTKbOEg1GKq42g3z8N6rW3R0Aq49Zw20=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eKAmEnuZjBdVmTQMq6MkPJlUljoizkE5YmAypqO+XN1tv7xTK1Z9UBegzHisRAZr9Ua3d+1dwcuzSFCjjKBT+dE9Y2TppuMostP3hZwZJpxxWDK0u8oFm7+R+AVHPt1YywFmS7i59uod9tykJYBfV+wzw/hRcBee1yoGg9zYkZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kviluAb3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kviluAb3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25EFCC4CEE6; Mon, 24 Feb 2025 10:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391215; bh=A9uQN4pgxmAPTKbOEg1GKq42g3z8N6rW3R0Aq49Zw20=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kviluAb3twh1PVkiWcvpyCDARNe8MqrrYLW2h9yUrUrTn0pZuxFzbRasUoA7YNfA+ 4NcigM7MZHIHxgohf/pvmh8bTMswk+qy+cOjP+09JtX31wZJkMQ8kMLtOZSYgVb5YE yZpKlXTIPXdd/x02BnXhFBbk3h1dGL+4kFp02pRiWpnUKOOerGvOt5QOjAe77KMWEn beuBiIkJcxm+hsnXQfArXZv46IR/pOLedE/n26LtuWcQ+cvBDssv6gQR9xy3NuVCYw jUrfb/X/mdPaEXSPtWPfweAz/V0LFd636YsbjCo2Rs3g8ng5NW/j9fe2FoB7ULeX3x 7Msv0TPr4OQfw== Date: Mon, 24 Feb 2025 20:30:10 +1030 From: "Gustavo A. R. Silva" To: Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 6/8][next] nvme: target: Avoid -Wflex-array-member-not-at-end warnings Message-ID: References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 38 of the following warnings: drivers/nvme/target/nvmet.h:455:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/nvme/target/nvmet.h:462:49: 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 --- drivers/nvme/target/nvmet.h | 4 ++-- drivers/nvme/target/passthru.c | 2 +- drivers/nvme/target/zns.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 4be8d22d2d8d..13ee8026d3d8 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -452,14 +452,14 @@ struct nvmet_req { struct work_struct work; } f; struct { - struct bio inline_bio; + struct bio_hdr inline_bio; struct request *rq; struct work_struct work; bool use_workqueue; } p; #ifdef CONFIG_BLK_DEV_ZONED struct { - struct bio inline_bio; + struct bio_hdr inline_bio; struct work_struct zmgmt_work; } z; #endif /* CONFIG_BLK_DEV_ZONED */ diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index 26e2907ce8bb..bff52252ffb9 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -268,7 +268,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq) return -EINVAL; if (nvmet_use_inline_bvec(req)) { - bio = &req->p.inline_bio; + bio = container_of(&req->p.inline_bio, struct bio, __hdr); bio_init(bio, NULL, req->inline_bvec, ARRAY_SIZE(req->inline_bvec), req_op(rq)); } else { diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 29a60fabfcc8..afedbd984d39 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -570,7 +570,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) } if (nvmet_use_inline_bvec(req)) { - bio = &req->z.inline_bio; + bio = container_of(&req->z.inline_bio, struct bio, __hdr); bio_init(bio, req->ns->bdev, req->inline_bvec, ARRAY_SIZE(req->inline_bvec), opf); } else { From patchwork Mon Feb 24 10:00:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987733 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EE69241CA6; Mon, 24 Feb 2025 10:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391249; cv=none; b=gBmHVAenkxEB4umqnao7VTp9AFzRl5zyo6nCU2DvzTXdmAt1MZRca6j6dxkj/uy2r3f0UbUPAH1hugByX2hIVkgUUc551Gtj0GHryCUDpfRdgo17RBkt1nFnJmDu/1/w1HaP0eQFTs709rqEX/T1R7JypfmZopsck5+RQAbJKG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391249; c=relaxed/simple; bh=nChE4LK8cNgAKNxmzM/m4plG3ZITdbtg/Hk1Zy69K6I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ch4VyRifY+FaKIvcR5ZCEseop4ljCBw08YWWHiXL99rb+8duROh0D4wIaW+f2EPK86TwlTB5aeENV5734Q5qgrED4A2niFHE9ZBFN2nDu2zIiAKzhpe2yDvjZ3EqHMdqOPkhEyTe27QwCU2gdPrELb62IYjDCRnCaelgNJw/IUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tNpwqWye; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tNpwqWye" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E5F9C4CED6; Mon, 24 Feb 2025 10:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391248; bh=nChE4LK8cNgAKNxmzM/m4plG3ZITdbtg/Hk1Zy69K6I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tNpwqWyeOKSIcvnb2sWn6XJZqaAc3ytto3eXEQHMclnQYXGJD5BS9/tQHe49QPRGv It8jRM4GUVBE9mzxY1SfL4KF3WWkKz9OFmo3Tfu0qAPPbCK+UQuEBP/ebkduQdu96w GCdJHPnG6pgU8cj//rnP9GANvn2Q0B0FLl59XLbXBtgf+LTzmpJvMgWROsn2ZxnEeE GBnVf8A612NKaE2Q1/Y3CNf3YrgvFGFDynlSGKI51VKCbwQvEJvg1xE5lnW3DOf1r5 4KTmC3UrA+JFgJ5uqtiSeQ//wUPj9engBAZc2R9AldwJjpgZAd5gC/jaVEKMNkCqZd zmbwIjLcSMBBw== Date: Mon, 24 Feb 2025 20:30:45 +1030 From: "Gustavo A. R. Silva" To: Song Liu , Yu Kuai Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 7/8][next] md/raid5: Avoid -Wflex-array-member-not-at-end warnings Message-ID: References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 10 of the following warnings: drivers/md/raid5.h:262:33: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] drivers/md/raid5.h:262:38: 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 --- drivers/md/raid5.c | 10 +++++----- drivers/md/raid5.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 5c79429acc64..76981d8cbc5d 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -1178,8 +1178,8 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) again: dev = &sh->dev[i]; - bi = &dev->req; - rbi = &dev->rreq; /* For writing to replacement */ + bi = container_of(&dev->req, struct bio, __hdr); + rbi = container_of(&dev->rreq, struct bio, __hdr); /* For writing to replacement */ rdev = conf->disks[i].rdev; rrdev = conf->disks[i].replacement; @@ -2720,7 +2720,7 @@ static void raid5_end_read_request(struct bio * bi) sector_t s; for (i=0 ; idev[i].req) + if (bi == container_of(&sh->dev[i].req, struct bio, __hdr)) break; pr_debug("end_read_request %llu/%d, count: %d, error %d.\n", @@ -2848,11 +2848,11 @@ static void raid5_end_write_request(struct bio *bi) int replacement = 0; for (i = 0 ; i < disks; i++) { - if (bi == &sh->dev[i].req) { + if (bi == container_of(&sh->dev[i].req, struct bio, __hdr)) { rdev = conf->disks[i].rdev; break; } - if (bi == &sh->dev[i].rreq) { + if (bi == container_of(&sh->dev[i].rreq, struct bio, __hdr)) { rdev = conf->disks[i].replacement; if (rdev) replacement = 1; diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index eafc6e9ed6ee..3df59302e953 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -259,7 +259,7 @@ struct stripe_head { /* rreq and rvec are used for the replacement device when * writing data to both devices. */ - struct bio req, rreq; + struct bio_hdr req, rreq; struct bio_vec vec, rvec; struct page *page, *orig_page; unsigned int offset; /* offset of the page */ From patchwork Mon Feb 24 10:01:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13987753 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0F36253B64; Mon, 24 Feb 2025 10:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391290; cv=none; b=urz0i0vAJuIvYVRWhNfErBtNqrIaZ3VsLutQ6TJCdYB+BHvxoNRuohoUzqzHb6PXn2XOBmDJgASmpOt6plrflaGm1WV4fAU3Kh5nvKIylACjCTpWOaTAZJgEBjZdctcrUlNvVmDsa79D+3wKbEMAAO7KwRkyuZG8Qcniur4hNvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740391290; c=relaxed/simple; bh=Enp3Zb8nzXxEkwvMAjUB6rg1iQahYbSwBGgW+v2Giuw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I/XZMK1D0GCvIMki3/dqftvbtcZYxYPvHauci2tMqTwV+NeNd1bn+kB+VA3eE8cy7nfpa5QCdzX/2OaXwQIbNGl1paXQF+bcX7i1elwDx34gt2csvSjg/zIpzsuuE/rFl4axWqu31L3BuWYkPt5uxwGenltQIxFCvFa+V7pwJBE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VqD2Dozx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VqD2Dozx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5C2AC4CEE6; Mon, 24 Feb 2025 10:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740391289; bh=Enp3Zb8nzXxEkwvMAjUB6rg1iQahYbSwBGgW+v2Giuw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VqD2DozxGOkrHVQIsobsGCZ2nE6oH/nofMiU9yF8e/R+bboQE5R4zG3QPdTpZJ77i l8DmXlsNEJUFZl9DOR43gsjJM/mrB7Uz5HUUY76bRPXNU5w3R3bg5dvmtun3UZf9JH toesJTUvnYW3mYt58Ecwo+e7hZpuE3aPYQK4IY6l7rL7l6tcq+wPJBRQvH8TZXTqhP mgh44a15AR8lugpYTekF+UUAWrPzxKjFGXN/yuofnbG4oG+YAmLU+wWC7ysFsSD/gP 6ApKOJkIoYbEgFYnWfDSXPQ21I8r8YjPeCKng5//dR9N+TPugTdtYHw7eJDJrxvWkk Wtkm3rlFubUzw== Date: Mon, 24 Feb 2025 20:31:26 +1030 From: "Gustavo A. R. Silva" To: Coly Li , Kent Overstreet Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 8/8][next] bcache: Avoid -Wflex-array-member-not-at-end warnings Message-ID: References: Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: -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 --- 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,