Re: include/linux/compiler_types.h:631:38: error: call to '__compiletime_assert_431' declared with attribute error: BUILD_BUG_ON failed: offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u)

From: Arnd Bergmann

Date: Tue Mar 03 2026 - 10:31:10 EST


On Tue, Mar 3, 2026, at 07:48, Finn Thain wrote:
>
> --- a/pahole.out
> +++ b/pahole.out
> @@ -1,16 +1,18 @@
> struct qla_tgt_sess_op {
> struct scsi_qla_host * vha; /* 0
> 4 */
> uint32_t chip_reset; /* 4
> 4 */
> - struct work_struct work; /* 8
> 16 */
> + struct work_struct work
> __attribute__((__aligned__(4))); /* 8 16 */
> struct list_head cmd_list; /* 24
> 8 */
> bool aborted; /* 32
> 1 */
>
> /* XXX 1 byte hole, try to pack */
>
> struct rsp_que * rsp; /* 34 4 */
> struct atio_from_isp atio; /* 38 64 */
>
> - /* size: 102, cachelines: 2, members: 7 */
> + /* size: 104, cachelines: 2, members: 7 */
> /* sum members: 101, holes: 1, sum holes: 1 */
> - /* last cacheline: 38 bytes */
> -};
> + /* padding: 2 */
> + /* forced alignments: 1 */
> + /* last cacheline: 40 bytes */
> +} __attribute__((__aligned__(4)));
>
>
> The BUILD_BUG_ON assertion checks the size of the struct, which doesn't
> seem right, because any padding at the end of the struct does not
> interfere with the subsequent kzalloc() and memcpy() in
> qlt_queue_unknown_atio().

As far as I can tell, the assertion is always true on all architectures
other than m68k because "struct rsp_que *rsp" is word-aligned and
"struct atio_from_isp atio" is either 64 bytes long. The intention
of the assertion is to ensure that nothing got added after atio,
though the way it is written does not take misaligned atio into
account.

> I suppose the assertion could be motivated by some code elsewhere but I
> haven't yet found it. So perhaps the assertion can simply be removed. An
> alternative solution could be to increase the 1 byte hole to 3 bytes, and
> prevent tail padding that way.

The simplest way would be to force atio itself to be aligned
regardless of the architecture, either by removing the __packed
attribute on the struct nack_from_isp definition, or by
adding alignment on the variable:

--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -844,7 +844,7 @@ struct qla_tgt_sess_op {
bool aborted;
struct rsp_que *rsp;

- struct atio_from_isp atio;
+ struct atio_from_isp atio __aligned(8);
/* DO NOT ADD ANYTHING ELSE HERE - atio must be last member */
};

In general, the use of __packed attributes in this file
seems a bit inconsistent, with outer structures being packed
but containing aligned inner structures like atio_from_isp
and nack_to_isp. It may be best to review all of them and
remove as much as possible, but that's not necessary as a bug
fix here.

Arnd