linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: David Matlack <dmatlack@google.com>
Cc: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net,
	 graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
	masahiroy@kernel.org,  ojeda@kernel.org, pratyush@kernel.org,
	rdunlap@infradead.org, rppt@kernel.org,  tj@kernel.org,
	jasonmiu@google.com, skhawaja@google.com
Subject: Re: [PATCH v3 2/3] liveupdate: kho: Increase metadata bitmap size to PAGE_SIZE
Date: Mon, 27 Oct 2025 20:03:13 -0400	[thread overview]
Message-ID: <CA+CK2bAKjU8PmfuwGJwwOyj3U5bYaterE_KQa9uVu+mmmLmmew@mail.gmail.com> (raw)
In-Reply-To: <CALzav=fD47OCZRMNqDmHs798qpZzeU6eHHuNA+wyhmZ19aJ9vA@mail.gmail.com>

On Mon, Oct 27, 2025 at 7:02 PM David Matlack <dmatlack@google.com> wrote:
>
> On Mon, Oct 27, 2025 at 3:56 PM David Matlack <dmatlack@google.com> wrote:
> >
> > On Mon, Oct 20, 2025 at 5:09 PM Pasha Tatashin
> > <pasha.tatashin@soleen.com> wrote:
> >
> > > -static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size_t sz)
> > > +static void *xa_load_or_alloc(struct xarray *xa, unsigned long index)
> > >  {
> > >         void *res = xa_load(xa, index);
> > >
> > >         if (res)
> > >                 return res;
> > >
> > > -       void *elm __free(kfree) = kzalloc(sz, GFP_KERNEL);
> > > +       void *elm __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
> > >
> > >         if (!elm)
> > >                 return ERR_PTR(-ENOMEM);
> > >
> > > -       if (WARN_ON(kho_scratch_overlap(virt_to_phys(elm), sz)))
> > > +       if (WARN_ON(kho_scratch_overlap(virt_to_phys(elm), PAGE_SIZE)))
> > >                 return ERR_PTR(-EINVAL);
> >
> > Reading xa_load_or_alloc() is a bit confusing now.
> >
> > It seems very generic (returns a void *) but now hard-codes a size
> > (PAGE_SIZE). You have to look at the caller to see it is allocating
> > for a struct kho_mem_phys_bits, and then at the definition of struct
> > kho_mem_phys_bits to see the static_assert() that this struct is
> > always PAGE_SIZE.
> >
> > I would either keep letting the caller passing in size (if you think
> > this code is going to be re-used) or just commit to making
> > xa_load_or_alloc() specific to kho_mem_phys_bits. e.g. Change the
> > return type to struct kho_mem_phys_bits * and use sizeof() instead of
> > PAGE_SIZE.
>
> I see that you replace kzalloc() with get_zeroed_page() in the next
> patch. So the latter option is probably better, and maybe move static
> assert down here and use BUILD_BUG_ON()? That way readers can easily
> see that we are allocating for struct kho_mem_phys_bits *and* that
> that struct is guaranteed to be PAGE_SIZE'd.

The size is verified at build time via:
+static_assert(sizeof(struct kho_mem_phys_bits) == PAGE_SIZE);


  reply	other threads:[~2025-10-28  0:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-21  0:08 [PATCH v3 0/3] KHO: kfence + KHO memory corruption fix Pasha Tatashin
2025-10-21  0:08 ` [PATCH v3 1/3] liveupdate: kho: warn and fail on metadata or preserved memory in scratch area Pasha Tatashin
2025-10-22 10:22   ` Pratyush Yadav
2025-10-27 22:29   ` David Matlack
2025-10-28  0:01     ` Pasha Tatashin
2025-10-29 16:09       ` Jason Gunthorpe
2025-10-29  8:48   ` Mike Rapoport
2025-10-29 22:22     ` Pasha Tatashin
2025-10-29 22:35       ` Andrew Morton
2025-10-21  0:08 ` [PATCH v3 2/3] liveupdate: kho: Increase metadata bitmap size to PAGE_SIZE Pasha Tatashin
2025-10-22 10:25   ` Pratyush Yadav
2025-10-27 22:44   ` David Matlack
2025-10-27 22:56   ` David Matlack
2025-10-27 23:01     ` David Matlack
2025-10-28  0:03       ` Pasha Tatashin [this message]
2025-10-21  0:08 ` [PATCH v3 3/3] liveupdate: kho: allocate metadata directly from the buddy allocator Pasha Tatashin
2025-10-27 23:04   ` David Matlack
2025-10-28  0:03     ` Pasha Tatashin
2025-10-21  6:00 ` [PATCH v3 0/3] KHO: kfence + KHO memory corruption fix Mike Rapoport
2025-10-21 16:04   ` Pasha Tatashin
2025-10-21 20:53     ` Andrew Morton
2025-10-22  0:15       ` Pasha Tatashin
2025-10-22  5:48         ` Mike Rapoport
2025-10-22 18:24           ` Andrew Morton
2025-10-23  2:45         ` Andrew Morton

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=CA+CK2bAKjU8PmfuwGJwwOyj3U5bYaterE_KQa9uVu+mmmLmmew@mail.gmail.com \
    --to=pasha.tatashin@soleen.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dmatlack@google.com \
    --cc=graf@amazon.com \
    --cc=jasonmiu@google.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=masahiroy@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=skhawaja@google.com \
    --cc=tj@kernel.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