From: hapter@420blaze.it
To: mingo@redhat.com
Cc: tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org
Subject: arch/x86/kernel/sys_x86_64.c: rationale for 0x40000000 for MAP_32BIT's start address?
Date: Sun, 11 Feb 2024 08:52:45 +0000 [thread overview]
Message-ID: <a5c2f06ba401cdf13bc87749341b1605@420blaze.it> (raw)
I've found that passing in MAP_32BIT for mmap() will always return an
address above 0x40000000. The problem seems to lie in
arch/x86/kernek/sys_x86_64.c, where the following comment is the only
thing close to a hint(Line 100):
/* This is usually used needed to map code in small
model, so it needs to be in the first 31bit. Limit
it to that. This means we need to move the
unmapped base down for this case. This can give
conflicts with the heap, but we assume that glibc
malloc knows how to fall back to mmap. Give it 1GB
of playground for now. -AK */
Unfortunately this does not supply a rationale for starting from
0x40000000, which seems very arbitrary, and the git commit has been
there since the beginning of time (i.e. as far the the git history
goes), so the git blame has not helped much to clarify it. I was also
not able to find who "AK" was.
I have found another operating system that provides MAP_32BIT, FreeBSD,
to not exhibit the same behavior and not cause any execution problems
for RWX pages allocated below 0x40000000, so it does not seem a
technical rationale exists either.
mmap will happily return 0x10000 (which seems like the lowest address
the kernel will map when you supply it as a hint, so I do not see any
reason not to start the find from 0x10000, or something that isn't as
big as 0x40000000, which is big enough to impose a significant handicap
for applications using MAP_32BIT (e.g. JITs that want to use CALL rel32
at all times).
I will happily await for any clarifications on this matter.
- hapter
next reply other threads:[~2024-02-11 9:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-11 8:52 hapter [this message]
2024-02-12 2:43 ` Bagas Sanjaya
2024-02-12 2:48 ` Bagas Sanjaya
2024-02-12 7:07 ` Andi Kleen
2024-02-12 2:53 ` H. Peter Anvin
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=a5c2f06ba401cdf13bc87749341b1605@420blaze.it \
--to=hapter@420blaze.it \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@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®