linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ananda Badmaev <a.badmaev@clicknet.pro>
To: Matthew Wilcox <willy@infradead.org>, Dan Carpenter <error27@gmail.com>
Cc: linux-mm@kvack.org
Subject: Re: [bug report] mm: add zblock - new allocator for use via zpool API
Date: Tue, 22 Nov 2022 07:33:32 +0300	[thread overview]
Message-ID: <91bf2b07-55ff-96b7-67f3-660398d8a595@clicknet.pro> (raw)
In-Reply-To: <Y3xCGiNNO0LTbP8s@casper.infradead.org>

22.11.2022 06:29, Matthew Wilcox пишет:
> On Fri, Nov 18, 2022 at 03:20:32PM +0300, Dan Carpenter wrote:
>> Hello Ananda,
>>
>> The patch 9097e28c25c8: "mm: add zblock - new allocator for use via
>> zpool API" from Nov 4, 2022, leads to the following Smatch static
>> checker warning:
>>
>> mm/zblock.c:341 zblock_alloc() error: buffer overflow 'block_desc' 29 <= 29 (assuming for loop doesn't break)
>> mm/zblock.c:165 cache_insert_block() error: uninitialized symbol 'min_index'.
>> mm/zblock.c:412 zblock_reclaim_block() warn: always true condition '(block_type >= 0) => (0-u64max >= 0)'
>>
>> mm/zblock.c
>>      297 static int zblock_alloc(struct zblock_pool *pool, size_t size, gfp_t gfp,
>>      298                         unsigned long *handle)
>>      299 {
>>      300         unsigned int block_type, slot;
>>      301         struct zblock_block *block;
>>      302         struct block_list *list;
>>      303
>>      304         if (!size)
>>      305                 return -EINVAL;
>>      306
>>      307         if (size > PAGE_SIZE)
>>      308                 return -ENOSPC;
>>      309
>>      310         /* find basic block type with suitable slot size */
>>      311         for (block_type = 0; block_type < ARRAY_SIZE(block_desc); block_type++) {
>>      312                 if (size <= block_desc[block_type].slot_size)
>>      313                         break;
>>      314         }
>>
>> "size" is always <= PAGE_SIZE.  Is PAGE_SIZE always 4k?  If so then this
>> code is fine.  Smatch is bad at handling arrays.
> 
> PAGE_SIZE is 8kB on SPARC/Alpha.  It can be 64kB on PPC and ARM.  It can
> even be 256kB on one of the weirdo architectures (but, honestly, it's
> OK if that breaks; it's not well-tested)..

The block_desc table uses fractions of PAGE_SIZE, so with larger 
PAGE_SIZE, the size of slots will also increase. Should work fine with a 
page size of 8, 64, 256k.


      reply	other threads:[~2022-11-22  4:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 12:20 Dan Carpenter
2022-11-22  3:29 ` Matthew Wilcox
2022-11-22  4:33   ` Ananda Badmaev [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=91bf2b07-55ff-96b7-67f3-660398d8a595@clicknet.pro \
    --to=a.badmaev@clicknet.pro \
    --cc=error27@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /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