Re: [PATCH v2 1/1] scsi: qla2xxx: replace non-standard flexible array purex_item.iocb

Gustavo A. R. Silva
2025-07-30T20:55:33Z

On 30/07/25 09:43, Bryan Gurney wrote:
> Hi Gustavo,
>
> Yes, it passes. When I test this on top of the NVMe FPIN link
> integrity v9 patchset, I only see the "kernel: qla2xxx... : FPIN ELS"
> event.
>
> Tested-by: Bryan Gurney <bgurney@redhat.com>

Awesome. :)

Thanks!
-Gustavo

>
>
> Thanks,
>
> Bryan
>
> On Tue, Jul 29, 2025 at 11:45 PM Gustavo A. R. Silva
> <gustavo@embeddedor.com> wrote:
>>
>> Hi Bryan,
>>
>> I wonder if you could run your tests on the patch below and let me
>> know if it passes. If it does, I'll go ahead and submit it as a
>> proper patch (including your Tested-by tag) to the SCSI list.
>>
>> Thank you!
>> -Gustavo
>>
>>>
>>> The (untested) patch below avoids the use of `struct_group_tagged()`
>>> and the casts to `struct purex_item *`:
>>>
>>> diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
>>> index cb95b7b12051..4bdf8adf04ed 100644
>>> --- a/drivers/scsi/qla2xxx/qla_def.h
>>> +++ b/drivers/scsi/qla2xxx/qla_def.h
>>> @@ -4890,9 +4890,7 @@ struct purex_item {
>>> struct purex_item *pkt);
>>> atomic_t in_use;
>>> uint16_t size;
>>> - struct {
>>> - uint8_t iocb[64];
>>> - } iocb;
>>> + uint8_t iocb[] __counted_by(size);
>>> };
>>>
>>> #include "qla_edif.h"
>>> @@ -5101,7 +5099,6 @@ typedef struct scsi_qla_host {
>>> struct list_head head;
>>> spinlock_t lock;
>>> } purex_list;
>>> - struct purex_item default_item;
>>>
>>> struct name_list_extended gnl;
>>> /* Count of active session/fcport */
>>> @@ -5130,6 +5127,10 @@ typedef struct scsi_qla_host {
>>> #define DPORT_DIAG_IN_PROGRESS BIT_0
>>> #define DPORT_DIAG_CHIP_RESET_IN_PROGRESS BIT_1
>>> uint16_t dport_status;
>>> +
>>> + TRAILING_OVERLAP(struct purex_item, default_item, iocb,
>>> + uint8_t __default_item_iocb[QLA_DEFAULT_PAYLOAD_SIZE];
>>> + );
>>> } scsi_qla_host_t;
>>>
>>> struct qla27xx_image_status {
>>> diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
>>> index c4c6b5c6658c..4559b490614d 100644
>>> --- a/drivers/scsi/qla2xxx/qla_isr.c
>>> +++ b/drivers/scsi/qla2xxx/qla_isr.c
>>> @@ -1077,17 +1077,17 @@ static struct purex_item *
>>> qla24xx_alloc_purex_item(scsi_qla_host_t *vha, uint16_t size)
>>> {
>>> struct purex_item *item = NULL;
>>> - uint8_t item_hdr_size = sizeof(*item);
>>>
>>> if (size > QLA_DEFAULT_PAYLOAD_SIZE) {
>>> - item = kzalloc(item_hdr_size +
>>> - (size - QLA_DEFAULT_PAYLOAD_SIZE), GFP_ATOMIC);
>>> + item = kzalloc(struct_size(item, iocb, size), GFP_ATOMIC);
>>> } else {
>>> if (atomic_inc_return(&vha->default_item.in_use) == 1) {
>>> item = &vha->default_item;
>>> goto initialize_purex_header;
>>> } else {
>>> - item = kzalloc(item_hdr_size, GFP_ATOMIC);
>>> + item = kzalloc(
>>> + struct_size(item, iocb, QLA_DEFAULT_PAYLOAD_SIZE),
>>> + GFP_ATOMIC);
>>> }
>>> }
>>> if (!item) {
>>> @@ -1127,17 +1127,16 @@ qla24xx_queue_purex_item(scsi_qla_host_t *vha, struct purex_item *pkt,
>>> * @vha: SCSI driver HA context
>>> * @pkt: ELS packet
>>> */
>>> -static struct purex_item
>>> -*qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
>>> +static struct purex_item *
>>> +qla24xx_copy_std_pkt(struct scsi_qla_host *vha, void *pkt)
>>> {
>>> struct purex_item *item;
>>>
>>> - item = qla24xx_alloc_purex_item(vha,
>>> - QLA_DEFAULT_PAYLOAD_SIZE);
>>> + item = qla24xx_alloc_purex_item(vha, QLA_DEFAULT_PAYLOAD_SIZE);
>>> if (!item)
>>> return item;
>>>
>>> - memcpy(&item->iocb, pkt, sizeof(item->iocb));
>>> + memcpy(&item->iocb, pkt, QLA_DEFAULT_PAYLOAD_SIZE);
>>> return item;
>>> }
>>>
>>> diff --git a/drivers/scsi/qla2xxx/qla_nvme.c b/drivers/scsi/qla2xxx/qla_nvme.c
>>> index 8ee2e337c9e1..92488890bc04 100644
>>> --- a/drivers/scsi/qla2xxx/qla_nvme.c
>>> +++ b/drivers/scsi/qla2xxx/qla_nvme.c
>>> @@ -1308,7 +1308,7 @@ void qla2xxx_process_purls_iocb(void **pkt, struct rsp_que **rsp)
>>>
>>> ql_dbg(ql_dbg_unsol, vha, 0x2121,
>>> "PURLS OP[%01x] size %d xchg addr 0x%x portid %06x\n",
>>> - item->iocb.iocb[3], item->size, uctx->exchange_address,
>>> + item->iocb[3], item->size, uctx->exchange_address,
>>> fcport->d_id.b24);
>>> /* +48 0 1 2 3 4 5 6 7 8 9 A B C D E F
>>> * ----- -----------------------------------------------
>>> diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
>>> index d4b484c0fd9d..253f802605d6 100644
>>> --- a/drivers/scsi/qla2xxx/qla_os.c
>>> +++ b/drivers/scsi/qla2xxx/qla_os.c
>>> @@ -6459,9 +6459,10 @@ void qla24xx_process_purex_rdp(struct scsi_qla_host *vha,
>>> void
>>> qla24xx_free_purex_item(struct purex_item *item)
>>> {
>>> - if (item == &item->vha->default_item)
>>> + if (item == &item->vha->default_item) {
>>> memset(&item->vha->default_item, 0, sizeof(struct purex_item));
>>> - else
>>> + memset(&item->vha->__default_item_iocb, 0, QLA_DEFAULT_PAYLOAD_SIZE);
>>> + } else
>>> kfree(item);
>>>
>>> Thanks
>>> -Gustavo
>>
>