Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kiarash Azarnia <kiarash.azarnia@gmail.com>
To: rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org
Cc: graf@amazon.com, kexec@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kho: fix signed shift UB in kho_preserved_memory_reserve()
Date: Sun, 16 Aug 2026 12:55:34 +0330	[thread overview]
Message-ID: <20260816092534.3333563-1-kiarash.azarnia@gmail.com> (raw)
In-Reply-To: <20260816090038.3117276-1-kiarash.azarnia@gmail.com>

Here is how I reproduced this, in case it is useful for review.

Minimal reproducer (prints what the function computes, both ways):

  #include <stdio.h>
  #define PAGE_SHIFT 12

  int main(void)
  {
          int order;

          for (order = 18; order <= 20; order++) {
                  unsigned long long before = 1 << (order + PAGE_SHIFT);
                  unsigned long long after = (unsigned long long)1 << (order + PAGE_SHIFT);
                  printf("order=%2d before=0x%llx after=0x%llx\n", order, before, after);
          }
          return 0;
  }

prints:

  order=18 before=0x40000000 after=0x40000000
  order=19 before=0xffffffff80000000 after=0x80000000
  order=20 before=0x1 after=0x100000000

Order 19 is a 2 GiB region, reachable from a reserve_mem=2G boot.

It also shows on a real boot: with CONFIG_KEXEC_HANDOVER=y, CONFIG_LIVEUPDATE=y,
CONFIG_UBSAN unset, and

  reserve_mem=2G:2G:khotest kho_scratch=128M,128M,128M kho=on liveupdate=on
  kexec -l -s --reuse-cmdline --append=" luo_stage=2"

stage 2 warned in memblock_add_range and lost ~820 MB (MemTotal 5181908 kB vs
6004928 kB in stage 1); after the fix, no WARN, MemTotal 6004884 kB.


  reply	other threads:[~2026-08-16  9:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-16  9:00 [PATCH] kho: fix signed shift UB in kho_preserved_memory_reserve() Kiarash Azarnia
2026-08-16  9:25 ` Kiarash Azarnia [this message]
2026-08-17  5:51 ` Mike Rapoport

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=20260816092534.3333563-1-kiarash.azarnia@gmail.com \
    --to=kiarash.azarnia@gmail.com \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@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