mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Finn Thain <fthain@linux-m68k.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>
Cc: kernel test robot <lkp@intel.com>,
	oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Linux Memory Management List <linux-mm@kvack.org>,
	Arnd Bergmann <arnd@arndb.de>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	scsi <linux-scsi@vger.kernel.org>
Subject: Re: include/linux/compiler_types.h:631:45: error: call to '__compiletime_assert_433' declared with attribute error: BUILD_BUG_ON failed: offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u)
Date: Mon, 23 Nov 2026 15:37:11 -0800	[thread overview]
Message-ID: <8a0f78e3-5483-42a2-ae27-473bbb6de915@acm.org> (raw)
In-Reply-To: <669b9ce8-bb33-f7ee-1087-88c1e9d3b610@linux-m68k.org>

On 11/23/26 3:05 PM, Finn Thain wrote:
> Yes, two alternative solutions were submitted in March (either remove the
> assertion or rework it). The build bot reported the problem again in
> September so I resubmitted the "rework" alternative. Sashiko-bot didn't
> have much praise for that*, so now I'm leaning towards the "remove"
> alternative. I have been advised to keep re-submitting, and I will do so
> after a suitable back-off in retry rate i.e. 2027 or 2028.
> 
> *
> https://lore.kernel.org/r/93e35f60-e465-7f76-0043-f997fe2ec8c7@linux-m68k.org

What an LLM came up with after I asked it to fix
https://lore.kernel.org/lkml/202603030747.VX0v4otS-lkp@intel.com/ can be
found below. One of the comments of the LLM is "This is essentially Finn
Thain's "Rework BUILD_BUG_ON() assertion" patch with your two review 
comments from this morning applied". Sashiko reports "No issues found"
for the patch below. No Signed-off-by from me because I think Finn
should be credited for his work instead of I.

Bart.

     scsi: qla2xxx: Fix the qla_tgt_sess_op layout assertion

     qlt_queue_unknown_atio() allocates a struct qla_tgt_sess_op followed by
     add_cdb_len bytes and copies an ATIO plus its additional CDB bytes into
     the 'atio' member. Hence no other member may follow 'atio'. The
     BUILD_BUG_ON() that is supposed to verify this compares the end of
     'atio' with sizeof(struct qla_tgt_sess_op). That is wrong because it
     also triggers if the compiler adds tail padding. This is what 
happens on
     m68k since atomic_t is aligned on a four byte boundary: 'atio' ends at
     offset 102 and the structure size is 104 bytes. This breaks the build
     for CONFIG_COLDFIRE=y and CONFIG_SCSI_QLA_FC=y:

       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)

     Additionally, the BUILD_BUG_ON() does not detect all members that could
     be added after 'atio', e.g. a zero-length array.

     Fix this by adding a flexible array member after 'atio' that represents
     the additional CDB bytes. The compiler rejects any member that is added
     after a flexible array member. Assert that the flexible array member
     follows 'atio' immediately instead of making assumptions about the
     structure size. Use kzalloc_flex() to allocate the structure. This does
     not change the allocation size.

     This patch is based on a patch from Finn Thain and on a suggestion from
     Tony Battersby.

     Do not modify the memcpy() call in qlt_queue_unknown_atio(), which
     still writes past the end of the 'atio' member.

     Compile-tested only, for m68k (Coldfire) and x86_64.

     Reported-by: kernel test robot <lkp@intel.com>
     Closes: 
https://lore.kernel.org/oe-kbuild-all/202603030747.VX0v4otS-lkp@intel.com/
     Closes: 
https://lore.kernel.org/oe-kbuild-all/202609301230.CauIUXCF-lkp@intel.com/
     Link: 
https://lore.kernel.org/all/4808a5dc1a71528ffa3360868561009744277450.1791502886.git.fthain@linux-m68k.org/
     Fixes: 091719c21d5a ("scsi: qla2xxx: target: Fix invalid memory 
access with big CDBs")
     Fixes: e428b013d9df ("atomic: specify alignment for atomic_t and 
atomic64_t")

diff --git a/drivers/scsi/qla2xxx/qla_target.c 
b/drivers/scsi/qla2xxx/qla_target.c
index 5a7caff61b16..afa96551c13c 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -212,9 +212,6 @@ static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
  	unsigned long flags;
  	unsigned int add_cdb_len = 0;

-	/* atio must be the last member of qla_tgt_sess_op for add_cdb_len */
-	BUILD_BUG_ON(offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) 
!= sizeof(*u));
-
  	if (tgt->tgt_stop) {
  		ql_dbg(ql_dbg_async, vha, 0x502c,
  		    "qla_target(%d): dropping unknown ATIO_TYPE7, because tgt is 
being stopped",
@@ -227,7 +224,7 @@ static void qlt_queue_unknown_atio(scsi_qla_host_t *vha,
  		add_cdb_len =
  			((unsigned int) atio->u.isp24.fcp_cmnd.add_cdb_len) * 4;

-	u = kzalloc(sizeof(*u) + add_cdb_len, GFP_ATOMIC);
+	u = kzalloc_flex(*u, extra_cdb, add_cdb_len, GFP_ATOMIC);
  	if (u == NULL)
  		goto out_term;

diff --git a/drivers/scsi/qla2xxx/qla_target.h 
b/drivers/scsi/qla2xxx/qla_target.h
index 71bc1affb1bc..c1559f034f85 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -845,9 +845,16 @@ struct qla_tgt_sess_op {
  	struct rsp_que *rsp;

  	struct atio_from_isp atio;
-	/* DO NOT ADD ANYTHING ELSE HERE - atio must be last member */
+	/*
+	 * The part of atio.u.isp24.fcp_cmnd.add_cdb[] that extends past the
+	 * end of atio. Must follow atio immediately.
+	 */
+	uint8_t extra_cdb[];
  };

+static_assert(offsetofend(struct qla_tgt_sess_op, atio) ==
+	      offsetof(struct qla_tgt_sess_op, extra_cdb));
+
  enum trace_flags {
  	TRC_NEW_CMD = BIT_0,
  	TRC_DO_WORK = BIT_1,


  reply	other threads:[~2026-11-23 23:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21  2:49 kernel test robot
2026-11-21  4:10 ` Finn Thain
2026-11-23  9:48   ` Geert Uytterhoeven
2026-11-23 23:05     ` Finn Thain
2026-11-23 23:37       ` Bart Van Assche [this message]
2026-11-24  3:31         ` Finn Thain

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=8a0f78e3-5483-42a2-ae27-473bbb6de915@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=fthain@linux-m68k.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=mkp@kernel.org \
    --cc=oe-kbuild-all@lists.linux.dev \
    /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®