From: "Arnd Bergmann" <arnd@arndb.de>
To: "Bradley Morgan" <brads@mainlining.org>,
"Andrew Morton" <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] compat: make compat_sysinfo() scale far enough to actually fit
Date: Thu, 05 Nov 2026 08:25:22 +0100 [thread overview]
Message-ID: <7e655d9c-d38d-49a6-bc51-73f4e65383c9@app.fastmail.com> (raw)
In-Reply-To: <20261105003129.3130709-4-brads@mainlining.org>
On Thu, Nov 5, 2026, at 01:31, Bradley Morgan wrote:
> compat_sysinfo() checks whether totalram or totalswap is too big for the
> compat struct and scales the values down to fit, but the loop stops as
> soon as s.mem_unit reaches PAGE_SIZE. That caps the compression at one
> page, 12 bits with 4K pages. On a 64 bit kernel do_sysinfo() always
> hands it values in bytes with mem_unit == 1, its own overflow math runs
> on unsigned long so it does not bail until 16 EiB, so the loop runs its
> 12 turns, the values come back out as a page count, and anything past
> 2^32 pages still does not fit. Storing that into the u32 field then
> just drops the top bits.
>
> So a 32 bit process on a box past 2^32 pages gets a wrapped number
> instead of a coarse one, with 4K pages that starts at 16 TiB:
>
> ram old new
> 8 TiB 2147483648 x 4096 unchanged
> 16 TiB 0 x 4096 2147483648 x 8192
> 17 TiB 268435456 x 4096 2281701376 x 8192
> 32 TiB 0 x 4096 2147483648 x 16384
>
> The 17 TiB row is the nasty one, a 32 bit process is told the box has
> 1 TiB of ram. Keep scaling until the values fit instead of until the
> unit reaches a page, the unit then says how coarse the number is, which
> is what mem_unit is for.
>
> Nothing that works today changes. I ran both loops side by side over
> ram from 1 MiB to 2^56 with 4K and 64K pages, they disagree on exactly
> the inputs where the old one dropped bits and agree on every one it got
> right.
>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
Makes sense, thanks for the fix!
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
prev parent reply other threads:[~2026-11-05 7:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 0:31 [PATCH 0/3] two small fixes out of kernel/sys.c Bradley Morgan
2026-11-05 0:31 ` [PATCH 1/3] tools: pass the unused prctl() args explicitly for PR_FUTEX_HASH Bradley Morgan
2026-11-05 0:31 ` [PATCH 2/3] futex: reject the unused PR_FUTEX_HASH arguments Bradley Morgan
2026-11-05 0:31 ` [PATCH 3/3] compat: make compat_sysinfo() scale far enough to actually fit Bradley Morgan
2026-11-05 7:25 ` Arnd Bergmann [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=7e655d9c-d38d-49a6-bc51-73f4e65383c9@app.fastmail.com \
--to=arnd@arndb.de \
--cc=akpm@linux-foundation.org \
--cc=brads@mainlining.org \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®