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)
Subsystems (3)
kernel test robot
build botHi Finn,
FYI, the error/warning still remains.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 5f22fb20497f4983094131f00a734362300d22d2 commit: e428b013d9dff30f7a65509e33047ba975cce8ba atomic: specify alignment for atomic_t and atomic64_t date: 10 months ago config: m68k-randconfig-2000-20261121 (https://download.01.org/0day-ci/archive/20261121/[email protected]/config) compiler: m68k-linux-gcc (GCC) 13.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261121/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Fixes: e428b013d9df ("atomic: specify alignment for atomic_t and atomic64_t")
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
In file included from <command-line>:
In function 'qlt_queue_unknown_atio',
inlined from 'qlt_24xx_atio_pkt_all_vps.isra' at drivers/scsi/qla2xxx/qla_target.c:331:4:
>> 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)
631 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:612:25: note: in definition of macro '__compiletime_assert'
612 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:631:9: note: in expansion of macro '_compiletime_assert'
631 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
drivers/scsi/qla2xxx/qla_target.c:216:9: note: in expansion of macro 'BUILD_BUG_ON'
216 | BUILD_BUG_ON(offsetof(struct qla_tgt_sess_op, atio) + sizeof(u->atio) != sizeof(*u));
| ^~~~~~~~~~~~vim +/__compiletime_assert_433 +631 include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 617 eb5c2d4b45e3d2 Will Deacon 2020-07-21 618 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 619 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 620 eb5c2d4b45e3d2 Will Deacon 2020-07-21 621 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 622 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 623 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 624 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 625 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 626 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 627 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 628 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 629 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 630 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @631 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 632
:::::: The code at line 631 was first introduced by commit
:::::: eb5c2d4b45e3d2d5d052ea6b8f1463976b1020d5 compiler.h: Move compiletime_assert() macros into compiler_types.h
:::::: TO: Will Deacon <[email protected]>
:::::: CC: Will Deacon <[email protected]>
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 2 lines · kernel test robot
FYI, the error/warning still remains.
That's because the qla2xxx maintainers at Marvell did not respond to any of the three fixes I sent. I'm not a paying customer so all bets are off.
Hi Finn,
CC scsi
Quoted 5 lines · Finn Thain
Quoted 1 line · kernel test robot
FYI, the error/warning still remains.
That's because the qla2xxx maintainers at Marvell did not respond to any of the three fixes I sent. I'm not a paying customer so all bets are off.
That's "[PATCH] scsi: qla2xxx: Rework BUILD_BUG_ON() assertion", first submittted in March, right?
https://lore.kernel.org/all/4808a5dc1a71528ffa3360868561009744277450.1791502886.git.fthain@linux-m68k.org
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 6 lines · Geert Uytterhoeven
Hi Finn,
CC scsi
Quoted 1 line · Finn Thain
On Sat, 21 Nov 2026, kernel test robot wrote:
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
FYI, the error/warning still remains.
That's because the qla2xxx maintainers at Marvell did not respond to any of the three fixes I sent. I'm not a paying customer so all bets are off.
That's "[PATCH] scsi: qla2xxx: Rework
BUILD_BUG_ON()assertion", first submittted in March, right?
https://lore.kernel.org/all/4808a5dc1a71528ffa3360868561009744277450.1791502886.git.fthain@linux-m68k.org
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.
Quoted 9 lines · Finn Thain
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.
What an LLM came up with after I asked it to fix
https://lore.kernel.org/lkml/[email protected]/ 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.
Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/
Closes:
https://lore.kernel.org/oe-kbuild-all/[email protected]/
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")
atomic64_t")
drivers/scsi/qla2xxx/qla_target.c +0 -3
@@ -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;
drivers/scsi/qla2xxx/qla_target.h +8 -1
@@ -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 ,
Quoted 11 lines · Bart Van Assche
Quoted 9 lines · Finn Thain
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.
Quoted 8 lines
What an LLM came up with after I asked it to fix
https://lore.kernel.org/lkml/[email protected]/ can be found below. One of the comments of the LLM is "This is essentially Finn Thain's "ReworkBUILD_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.
Thanks, Bart. I'll take that as a vote for "rework". There is an associated risk though: I can't test the patch as I don't have access to suitable hardware. (Perhaps someone with such access will volunteer.)
Whereas, the "remove" alternative doesn't require testing as it doesn't risk a regression.
I have a question for your LLM. Sashiko-bot said, in response to my patch:
Similarly, get_datalen_for_atio() accesses the array out-of-bounds
when len > 0:
drivers/scsi/qla2xxx/qla_target.h:get_datalen_for_atio() {
...
return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]);
...
}I don't understand why the patch from your LLM did not raise the same OOB access concerns.
Adding a flex array to struct qla_tgt_sess_op can prevent new struct members being added in the wrong spot in that struct but can't prevent new struct members being added to struct atio7_fcp_cmnd. Neither does the assertion. So the "remove" alternative doesn't have all the disadvantages that you might expect.
Quoted 40 lines · Finn Thain
Quoted 11 lines · Bart Van Assche
Quoted 9 lines · Finn Thain
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.
Quoted 8 lines
What an LLM came up with after I asked it to fix
https://lore.kernel.org/lkml/[email protected]/ can be found below. One of the comments of the LLM is "This is essentially Finn Thain's "ReworkBUILD_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.Thanks, Bart. I'll take that as a vote for "rework". There is an associated risk though: I can't test the patch as I don't have access to suitable hardware. (Perhaps someone with such access will volunteer.)
Whereas, the "remove" alternative doesn't require testing as it doesn't risk a regression.
I have a question for your LLM. Sashiko-bot said, in response to my patch:
Similarly, get_datalen_for_atio() accesses the array out-of-bounds when len > 0: drivers/scsi/qla2xxx/qla_target.h:get_datalen_for_atio() { ... return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]); ... }
Quoted 2 lines
I don't understand why the patch from your LLM did not raise the same OOB access concerns.
I suspect that is just from Bart specifically calling it out in the changelog already as a known limitation "Do not modify the memcpy() call in qlt_queue_unknown_atio(), which still writes past the end of the 'atio' member.".
Quoted 5 lines
Adding a flex array to struct
qla_tgt_sess_opcan prevent new struct members being added in the wrong spot in that struct but can't prevent new struct members being added to structatio7_fcp_cmnd. Neither does the assertion. So the "remove" alternative doesn't have all the disadvantages that you might expect.
This is probably just a difference in perception: atio_from_isp and everything inside is clearly marked as a hardware structure that is meant to align exactly to the 64 byte cacheline, so it would not make any sense to change its layout and add more members here. qla_tgt_sess_op on the other hand is clearly not a hardware structure but an in-kernel one, so it is quite unexpected that one of its members extends past the end, especially when the other three instances of atio_from_isp in data structures don't seem to do that.
Quoted 8 lines
Review static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, · line 229
Quoted 8 lines
(quoted diff) +1
-1@@ -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;
While this does make the current implementation more correct by having the correct length, I'm worried that it just ends up establishing the complexity more in the sense that extra_cdb extends both into the padding and beyond qla_tgt_sess_op.
If the driver is still actively maintained, it would be nice to reduce the complexity instead, in one of two ways:
a) make atio_from_isp naturally aligned by dropping the bogus __packed attribute, so it is actually at the end of qla_tgt_sess_op as the driver was written to expect. Note that having the outer structure as __packed but the union and the inner structs as aligned is itself problematic and can lead to undefined behavior, if some code ever takes a pointer to one of the inner aggregates and expects it to be aligned. The only effect that I see from the __packed annotation is that it forces expensive byte access on dma-coherent memory despite it being fully aligned.
b) rework the driver more broadly to never actually do any accesses beyond a struct boundary and make it work with sanitizers enabled. One way to do this would be to have a separate isp24 atio structure that is not in the union but that encloses the actual maximum length. Not sure how this would actually be done, but it appears that the current design keeps causing problems, see e.g. 091719c21d5a ("scsi: qla2xxx: target: Fix invalid memory access with big CDBs") which adds more complexity around keeping an extra copy for it.
Arnd
[Cc qla2xxx maintainers]
Quoted 14 lines · Arnd Bergmann
Quoted 13 lines · Finn Thain
On Mon, 23 Nov 2026, Bart Van Assche wrote:
Sashiko-bot said, in response to my patch:
Similarly, get_datalen_for_atio() accesses the array out-of-bounds when len > 0: drivers/scsi/qla2xxx/qla_target.h:get_datalen_for_atio() { ... return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]); ... }
Quoted 8 lines
Quoted 2 lines
I don't understand why the patch from your LLM did not raise the same OOB access concerns.
I suspect that is just from Bart specifically calling it out in the changelog already as a known limitation "Do not modify the
memcpy()call inqlt_queue_unknown_atio(), which still writes past the end of the 'atio' member.".
OK, so Bart's LLM has made a suggestion that doesn't improve upon my patch except for contributing some modernization i.e. the preferred flex array style. I'm not sure that's appropriate for a bug fix that is to be backported.
Quoted 10 lines
Quoted 5 lines
Adding a flex array to struct
qla_tgt_sess_opcan prevent new struct members being added in the wrong spot in that struct but can't prevent new struct members being added to structatio7_fcp_cmnd. Neither does the assertion. So the "remove" alternative doesn't have all the disadvantages that you might expect.This is probably just a difference in perception:
atio_from_ispand everything inside is clearly marked as a hardware structure that is meant to align exactly to the 64 byte cacheline, so it would not make any sense to change its layout and add more members here.
If this driver is for x86_64 only, as you seem to be implying, then the right fix for this build failure would seem to be Kconfig:
drivers/scsi/qla2xxx/Kconfig +1 -0
@@ -29,6 +29,7 @@ config SCSI_QLA_FC config TCM_QLA2XXX tristate "TCM_QLA2XXX fabric module for QLogic 24xx+ series target mode HBAs" + depends on X86_64 depends on SCSI_QLA_FC && TARGET_CORE depends on LIBFC select BTREE
I wonder whether the driver maintainers would like to comment on this possibility.
Quoted 19 lines
qla_tgt_sess_opon the other hand is clearly not a hardware structure but an in-kernel one so it is quite unexpected that one of its members extends past the end, especially when the other three instances ofatio_from_ispin data structures don't seem to do that.Quoted 8 lines
Review static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, · line 229
Quoted 8 lines
(quoted diff) +1
-1@@ -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;While this does make the current implementation more correct by having the correct length, I'm worried that it just ends up establishing the complexity more in the sense that
extra_cdbextends both into the padding and beyondqla_tgt_sess_op.
Quoted 5 lines
If the driver is still actively maintained, it would be nice to reduce the complexity instead, in one of two ways:
a) make
atio_from_ispnaturally aligned by dropping the bogus__packedattribute,
I don't think I follow. "Natural" alignment would be at integer multiples of the struct size, right? Moreover, the correct alignment for a hardware struct is a question for the hardware vendor, isn't it?
Quoted 2 lines
so it is actually at the end of
qla_tgt_sess_opas the driver was written to expect.
FWIW, I think __packed on a hardware struct is at least as desirable as portable drivers are.
If the host ABI places padding after the hardware struct, that's a non-issue -- unless, of course, there is a bogus BUILD_BUG_ON that trips over the padding, which is exactly the bogosity causing the issue.
Quoted 9 lines
Note that having the
outer structure as__packedbut the union and the inner structs as aligned is itself problematic and can lead to undefined behavior, if some code ever takes a pointer to one of the inner aggregates and expects it to be aligned. The only effect that I see from the__packedannotation is that it forces expensive byte access on dma-coherent memory despite it being fully aligned.
Quoted 11 lines
b) rework the driver more broadly to never actually do any accesses beyond a struct boundary and make it work with sanitizers enabled. One way to do this would be to have a separate isp24 atio structure that is not in the union but that encloses the actual maximum length. Not sure how this would actually be done, but it appears that the current design keeps causing problems, see e.g.
091719c21d5a("scsi: qla2xxx: target: Fix invalid memory access with big CDBs") which adds more complexity around keeping an extra copy for it.
It's not clear to me that UBSAN and FORTIFY can actually do what this static_assert() does. Maybe that's another "difference in perception".
I agree that sanitizers are worthwhile but I fear that this horse has already bolted. Surely worth considering for new code though.
Quoted 10 lines · Finn Thain
[Cc qla2xxx maintainers]
Quoted 8 lines · Arnd Bergmann
Quoted 6 lines · Finn Thain
On Mon, 23 Nov 2026, Bart Van Assche wrote:
Adding a flex array to structqla_tgt_sess_opcan prevent new struct members being added in the wrong spot in that struct but can't prevent new struct members being added to structatio7_fcp_cmnd. Neither does the assertion. So the "remove" alternative doesn't have all the disadvantages that you might expect.
Quoted 8 lines
Quoted 4 lines
This is probably just a difference in perception:
atio_from_ispand everything inside is clearly marked as a hardware structure that is meant to align exactly to the 64 byte cacheline, so it would not make any sense to change its layout and add more members here.If this driver is for
x86_64only, as you seem to be implying, then the right fix for this build failure would seem to beKconfig:
I did not say or imply that.
Quoted 22 lines
Quoted 22 lines
qla_tgt_sess_opon the other hand is clearly not a hardware structure but an in-kernel one so it is quite unexpected that one of its members extends past the end, especially when the other three instances ofatio_from_ispin data structures don't seem to do that.Quoted 8 lines
Review static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, · line 229
Quoted 8 lines
(quoted diff) +1
-1@@ -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;While this does make the current implementation more correct by having the correct length, I'm worried that it just ends up establishing the complexity more in the sense that
extra_cdbextends both into the padding and beyondqla_tgt_sess_op.If the driver is still actively maintained, it would be nice to reduce the complexity instead, in one of two ways:
Quoted 6 lines
Quoted 2 lines
a) make
atio_from_ispnaturally aligned by dropping the bogus__packedattribute,I don't think I follow. "Natural" alignment would be at integer multiples of the struct size, right? Moreover, the correct alignment for a hardware struct is a question for the hardware vendor, isn't it?
I should have been clearer here, I meant having it aligned to the highest alignment of any of its members, in this case alignof(u64), which would avoid both the warning and the slow byte-at-a-time access.
Quoted 5 lines
Quoted 2 lines
so it is actually at the end of
qla_tgt_sess_opas the driver was written to expect.FWIW, I think
__packedon a hardware struct is at least as desirable as portable drivers are.
I can certainly see an argument for marking the inner structures "__packed __aligned(8)" or similar, to ensure that the members are tightly packed but can still be accessed worth multi-byte load/store instructures.
The way the __packed it written on the outer struct, it only causes problems but does not actually enforce packing of the inner struct.
Arnd
Quoted 34 lines · Arnd Bergmann
Quoted 17 lines
Quoted 17 lines
Quoted 8 lines
Review static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, · line 229
Quoted 8 lines
(quoted diff) +1
-1@@ -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;While this does make the current implementation more correct by having the correct length, I'm worried that it just ends up establishing the complexity more in the sense that
extra_cdbextends both into the padding and beyondqla_tgt_sess_op.If the driver is still actively maintained, it would be nice to reduce the complexity instead, in one of two ways:
Quoted 6 lines
Quoted 2 lines
a) make
atio_from_ispnaturally aligned by dropping the bogus__packedattribute,I don't think I follow. "Natural" alignment would be at integer multiples of the struct size, right? Moreover, the correct alignment for a hardware struct is a question for the hardware vendor, isn't it?
I should have been clearer here, I meant having it aligned to the highest alignment of any of its members, in this case alignof(u64), which would avoid both the warning and the slow byte-at-a-time access.
Quoted 5 lines
Quoted 2 lines
so it is actually at the end of
qla_tgt_sess_opas the driver was written to expect.FWIW, I think
__packedon a hardware struct is at least as desirable as portable drivers are.
Quoted 8 lines
I can certainly see an argument for marking the inner structures "
__packed__aligned(8)" or similar, to ensure that the members are tightly packed but can still be accessed worth multi-byte load/store instructures.The way the
__packedit written on the outer struct, it only causes problems but does not actually enforce packing of the inner struct.
Perhaps there is a way to alter the struct layouts in a portable way (so as to avoid the build failure) but it's simply not worth it.
There is no actual bug here, that affects actual users, to justify the churn, or the complexity, or the regression testing effort, or the fruitless discussion to-date.
If there was a maintainer who cared about this issue, perhaps that would put a different light on it. Maybe.
As I pointed out in March, there is already a comment in the driver to make the bogus BUILD_BUG_ON() effectively redundant. So, at some point in the future, when I can get interested again, I will re-send the same untested yet risk-free patch that I sent back in March, to remove it.
Quoted 4 lines · On Wed, 25 Nov 2026, I wrote:
Perhaps there is a way to alter the struct layouts in a portable way (so as to avoid the build failure) but it's simply not worth it.
To be fair, your rework suggestion might have similarly negligible risk to my "remove" patch, if you could obtain your desired struct layout without altering object code...
Quoted 4 lines
There is no actual bug here, that affects actual users, to justify the churn, or the complexity, or the regression testing effort, or the fruitless discussion to-date.
Quoted 8 lines
If there was a maintainer who cared about this issue, perhaps that would put a different light on it. Maybe.
As I pointed out in March, there is already a comment in the driver to make the bogus
BUILD_BUG_ON()effectively redundant. So, at some point in the future, when I can get interested again, I will re-send the same untested yet risk-free patch that I sent back in March, to remove it.
One reason I'm against reworking this assertion is that it never did what it claimed to do, so it's probably worthless.
Also, the kind of bug that could be caught this way could be detected using automated testing, so it's probably redundant.
Finally, wouldn't it be better to feed the hardware design to an LLM and validate the actual constraint that way? Guessing at all of the ways in which actual constraints might be violated (i.e. new struct member in the wrong place) seems likely to miss what matters and check what doesn't.
Since the vendor probably won't allow us to see the hardware design, why not use the (existing) natural language commentary in the same way, instead of translating the comments into assertions or tests?
Quoted 68 lines · On Tue, 24 Nov 2026 11:18:19 +0100 "Arnd Bergmann" <[email protected]> wrote:
Quoted 40 lines · Finn Thain
Quoted 11 lines · Bart Van Assche
Quoted 9 lines · Finn Thain
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.
Quoted 8 lines
What an LLM came up with after I asked it to fix
https://lore.kernel.org/lkml/[email protected]/ can be found below. One of the comments of the LLM is "This is essentially Finn Thain's "ReworkBUILD_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.Thanks, Bart. I'll take that as a vote for "rework". There is an associated risk though: I can't test the patch as I don't have access to suitable hardware. (Perhaps someone with such access will volunteer.)
Whereas, the "remove" alternative doesn't require testing as it doesn't risk a regression.
I have a question for your LLM. Sashiko-bot said, in response to my patch:
Similarly, get_datalen_for_atio() accesses the array out-of-bounds when len > 0: drivers/scsi/qla2xxx/qla_target.h:get_datalen_for_atio() { ... return get_unaligned_be32(&atio->u.isp24.fcp_cmnd.add_cdb[len * 4]); ... }Quoted 2 lines
I don't understand why the patch from your LLM did not raise the same OOB access concerns.
I suspect that is just from Bart specifically calling it out in the changelog already as a known limitation "Do not modify the
memcpy()call inqlt_queue_unknown_atio(), which still writes past the end of the 'atio' member.".Quoted 5 lines
Adding a flex array to struct
qla_tgt_sess_opcan prevent new struct members being added in the wrong spot in that struct but can't prevent new struct members being added to structatio7_fcp_cmnd. Neither does the assertion. So the "remove" alternative doesn't have all the disadvantages that you might expect.This is probably just a difference in perception:
atio_from_ispand everything inside is clearly marked as a hardware structure that is meant to align exactly to the 64 byte cacheline, so it would not make any sense to change its layout and add more members here.qla_tgt_sess_opon the other hand is clearly not a hardware structure but an in-kernel one, so it is quite unexpected that one of its members extends past the end, especially when the other three instances ofatio_from_ispin data structures don't seem to do that.Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -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;
Quoted 9 lines
Quoted 4 lines
Review static void qlt_queue_unknown_atio(scsi_qla_host_t *vha, · line 229
Quoted 4 lines
(quoted diff) +1
-1- 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;While this does make the current implementation more correct by having the correct length, I'm worried that it just ends up establishing the complexity more in the sense that
extra_cdbextends both into the padding and beyondqla_tgt_sess_op.
Isn't the struct also embedded in the middle of other structures so can't end in a flex array?
Quoted 13 lines
If the driver is still actively maintained, it would be nice to reduce the complexity instead, in one of two ways:
a) make
atio_from_ispnaturally aligned by dropping the bogus__packedattribute, so it is actually at the end ofqla_tgt_sess_opas the driver was written to expect. Note that having the outer structure as__packedbut the union and the inner structs as aligned is itself problematic and can lead to undefined behavior, if some code ever takes a pointer to one of the inner aggregates and expects it to be aligned. The only effect that I see from the__packedannotation is that it forces expensive byte access on dma-coherent memory despite it being fully aligned.
It looks to me like almost all of the __packed in that header are bogus - there is one on an le64 member which could easily be on an odd 32bit boundary.
What it really wants is an 'error if any padding' flag. (And maybe a compile-time check on the longer structures.)
If the hardware does dma onto those structures then you really don't want them misaligned either.
Bag of worms :-)
David
Quoted 14 lines
b) rework the driver more broadly to never actually do any accesses beyond a struct boundary and make it work with sanitizers enabled. One way to do this would be to have a separate isp24 atio structure that is not in the union but that encloses the actual maximum length. Not sure how this would actually be done, but it appears that the current design keeps causing problems, see e.g.
091719c21d5a("scsi: qla2xxx: target: Fix invalid memory access with big CDBs") which adds more complexity around keeping an extra copy for it.Arnd