From: Chris Leech <cleech@redhat.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: linux-scsi@vger.kernel.org, Nilesh Javali <njavali@marvell.com>,
Kees Cook <kees@kernel.org>, Bryan Gurney <bgurney@redhat.com>,
"Gustavo A . R . Silva" <gustavoars@kernel.org>,
John Meneghini <jmeneghi@redhat.com>
Subject: Re: [PATCH v2 1/1] scsi: qla2xxx: replace non-standard flexible array purex_item.iocb
Date: Mon, 28 Jul 2025 16:52:51 -0700 [thread overview]
Message-ID: <aIgNUw8IfNGOz3tl@my-developer-toolbox-latest> (raw)
In-Reply-To: <98ef5001-2ad4-4f2c-946e-57251cd264c4@embeddedor.com>
On Mon, Jul 28, 2025 at 04:55:12PM -0600, Gustavo A. R. Silva wrote:
>
>
> On 28/07/25 15:15, Chris Leech wrote:
> > On Mon, Jul 28, 2025 at 01:43:10PM -0600, Gustavo A. R. Silva wrote:
> > > On 28/07/25 12:57, Chris Leech wrote:
> > > > diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
> > > > index fe98c76e9be32..a00c06a9898ec 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);
> > >
> > > With the inclusion of `counted_by`, I think `item->size` should be updated
> > > here:
> > > item->size = size;
> > >
> > > > } else {
> > > > if (atomic_inc_return(&vha->default_item.in_use) == 1) {
> > > > - item = &vha->default_item;
> > > > + item = (struct purex_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);
> > >
> > > ...and here:
> > > item->size = QLA_DEFAULT_PAYLOAD_SIZE;
> > >
> > > Then remove `item->size = size;` just before `return item;`
> >
> > Hmm, I don't think I agree with that. The single assignment before
> > returning just keeps the allocation failure check in one place.
> > The conditional nesting in this function is a little odd, but I don't
> > want to start reworking it completly for this.
> >
> > Is there a problem with the size referenced by counted_by potentially
> > being smaller than the allocation? That looks possible in the case of
> > using the single pre-allocated default_item, but not needing to use the
> > entire 64-bytes (I don't know if that happens).
>
> But if both allocations for `struct purex_item *item` fail, then
> you'd end up with a flexible-array member of size 0, and `item->size`
> potentially being greater than zero, since `default_item` doesn't
> contain `uint8_t iocb[64];` anymore (it was turned into flex-array
> member `uint8_t iocb[] __counted_by(size);`)... unless I'm missing
> something?
This might be confusing to see as a diff; qla24xx_alloc_purex_item is
either allocating a new heap item with a flexible array size, or if the
size is small enough and there is only one in use at a time it's
returning default_item.
If the allocation fails, then the driver is already not using
default_item for this call and returns NULL.
static struct purex_item *
qla24xx_alloc_purex_item(scsi_qla_host_t *vha, uint16_t size)
{
struct purex_item *item = NULL;
if (size > QLA_DEFAULT_PAYLOAD_SIZE) {
item = kzalloc(struct_size(item, iocb, size), GFP_ATOMIC);
} else {
if (atomic_inc_return(&vha->default_item.in_use) == 1) {
item = (struct purex_item *)&vha->default_item;
goto initialize_purex_header;
} else {
item = kzalloc(
struct_size(item, iocb, QLA_DEFAULT_PAYLOAD_SIZE),
GFP_ATOMIC);
}
}
if (!item) {
ql_log(ql_log_warn, vha, 0x5092,
">> Failed allocate purex list item.\n");
return NULL;
}
initialize_purex_header:
item->vha = vha;
item->size = size;
return item;
}
default item was replaced with the header and a static sized array,
cast to a purex_item * when returned through the alloc function
- struct purex_item default_item;
+ struct purex_item_hdr default_item;
+ uint8_t __default_item_iocb[QLA_DEFAULT_PAYLOAD_SIZE];
- Chris
next prev parent reply other threads:[~2025-07-28 23:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-25 21:27 [PATCH 0/2] scsi: qla2xxx: flexible array / field-spanning write issue Chris Leech
2025-07-25 21:27 ` [PATCH 1/2] scsi: qla2xxx: replace non-standard flexible array purex_item.iocb Chris Leech
2025-07-25 21:54 ` Kees Cook
2025-07-28 18:57 ` [PATCH v2 1/1] " Chris Leech
2025-07-28 19:43 ` Gustavo A. R. Silva
2025-07-28 19:54 ` Gustavo A. R. Silva
2025-07-28 21:15 ` Chris Leech
2025-07-28 22:55 ` Gustavo A. R. Silva
2025-07-28 23:52 ` Chris Leech [this message]
2025-07-29 1:37 ` Gustavo A. R. Silva
2025-07-29 2:20 ` Gustavo A. R. Silva
2025-07-30 0:04 ` Chris Leech
2025-07-30 1:33 ` Gustavo A. R. Silva
2025-07-30 3:44 ` Gustavo A. R. Silva
2025-07-30 15:43 ` Bryan Gurney
2025-07-30 20:55 ` Gustavo A. R. Silva
2025-07-25 21:27 ` [PATCH 2/2] scsi: qla2xxx: unwrap purex_item.iocb.iocb so that __counted_by can be used Chris Leech
2025-07-25 21:56 ` Kees Cook
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=aIgNUw8IfNGOz3tl@my-developer-toolbox-latest \
--to=cleech@redhat.com \
--cc=bgurney@redhat.com \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=jmeneghi@redhat.com \
--cc=kees@kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=njavali@marvell.com \
/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