public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Bernard Metzler <bernard.metzler@linux.dev>
To: Rosen Penev <rosenp@gmail.com>, linux-rdma@vger.kernel.org
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	open "list:KERNEL" HARDENING "(not" covered by other
	"areas):Keyword:b__counted_by(_le|_be)?b"
	<linux-hardening@vger.kernel.org>
Subject: Re: [PATCH] RDMA/siw: use kzalloc_flex
Date: Tue, 21 Apr 2026 21:08:58 +0200	[thread overview]
Message-ID: <62c87071-51ab-4449-bcef-9c21e03713ae@linux.dev> (raw)
In-Reply-To: <49794f9f-8a35-4e36-af19-26b68c89decd@linux.dev>

Hi Rosen, all,

thanks for your patch. As stated, I think we shall make a change
to it, which exchanges 'num_pages' with more appropriate
'num_chunks' logic. Since I haven't received a response to my
first reply yet, I'll send an RFC patch right away. I'll
restrict it to linux-rdma list and other individuals on cc
in your patch.

Thanks,
Bernard.

On 29.03.2026 15:21, Bernard Metzler wrote:
> On 27.03.2026 04:00, Rosen Penev wrote:
>> Simplifies allocations by using a flexible array member in this struct.
>>
>> Add __counted_by to get extra runtime analysis.
>>
>> Signed-off-by: Rosen Penev <rosenp@gmail.com>
>> ---
>>   drivers/infiniband/sw/siw/siw.h     |  2 +-
>>   drivers/infiniband/sw/siw/siw_mem.c | 12 +++---------
>>   2 files changed, 4 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/infiniband/sw/siw/siw.h b/drivers/infiniband/sw/siw/siw.h
>> index f5fd71717b80..2b327a899a1c 100644
>> --- a/drivers/infiniband/sw/siw/siw.h
>> +++ b/drivers/infiniband/sw/siw/siw.h
>> @@ -119,9 +119,9 @@ struct siw_page_chunk {
>>   struct siw_umem {
>>       struct ib_umem *base_mem;
>> -    struct siw_page_chunk *page_chunk;
>>       int num_pages;
> 
> Shouldn't we replace 'num_pages' by a 'num_chunks' and change
> memory allocation and release code accordingly?
> 
>>       u64 fp_addr; /* First page base address */
>> +    struct siw_page_chunk page_chunk[] __counted_by(num_pages);
>>   };
>>   struct siw_pble {
>> diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/siw/siw_mem.c
>> index 98c802b3ed72..08047fcf0df1 100644
>> --- a/drivers/infiniband/sw/siw/siw_mem.c
>> +++ b/drivers/infiniband/sw/siw/siw_mem.c
>> @@ -50,7 +50,6 @@ void siw_umem_release(struct siw_umem *umem)
>>           kfree(umem->page_chunk[i].plist);
>>           num_pages -= PAGES_PER_CHUNK;
>>       }
>> -    kfree(umem->page_chunk);
>>       kfree(umem);
>>   }
>> @@ -347,16 +346,12 @@ struct siw_umem *siw_umem_get(struct ib_device *base_dev, u64 start,
>>       num_pages = PAGE_ALIGN(start + len - first_page_va) >> PAGE_SHIFT;
>>       num_chunks = (num_pages >> CHUNK_SHIFT) + 1;
>> -    umem = kzalloc_obj(*umem);
>> +    umem = kzalloc_flex(*umem, page_chunk, num_chunks);
>>       if (!umem)
>>           return ERR_PTR(-ENOMEM);
>> -    umem->page_chunk =
>> -        kzalloc_objs(struct siw_page_chunk, num_chunks);
>> -    if (!umem->page_chunk) {
>> -        rv = -ENOMEM;
>> -        goto err_out;
>> -    }
>> +    umem->num_pages = num_pages;
>> +
>>       base_mem = ib_umem_get(base_dev, start, len, rights);
>>       if (IS_ERR(base_mem)) {
>>           rv = PTR_ERR(base_mem);
>> @@ -385,7 +380,6 @@ struct siw_umem *siw_umem_get(struct ib_device *base_dev, u64 start,
>>           umem->page_chunk[i].plist = plist;
>>           while (nents--) {
>>               *plist = sg_page_iter_page(&sg_iter);
>> -            umem->num_pages++;
>>               num_pages--;
>>               plist++;
>>               if (!__sg_page_iter_next(&sg_iter))
> 


      reply	other threads:[~2026-04-21 19:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27  3:00 [PATCH] RDMA/siw: use kzalloc_flex Rosen Penev
2026-03-29 13:21 ` Bernard Metzler
2026-04-21 19:08   ` Bernard Metzler [this message]

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=62c87071-51ab-4449-bcef-9c21e03713ae@linux.dev \
    --to=bernard.metzler@linux.dev \
    --cc=gustavoars@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=kees@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rosenp@gmail.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