qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Richard Henderson <richard.henderson@linaro.org>,
	Laurent Vivier <laurent@vivier.eu>,
	Michael Tokarev <mjt@tls.msk.ru>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] linux-user: Tolerate CONFIG_LSM_MMAP_MIN_ADDR
Date: Tue, 22 Oct 2024 11:50:30 +0200	[thread overview]
Message-ID: <5a6ec294c6da14a2a65d3669ac4dcdc79934c452.camel@linux.ibm.com> (raw)
In-Reply-To: <38ff2ca7-7156-4ad8-b777-dab689043ecc@linaro.org>

On Mon, 2024-10-21 at 19:34 -0700, Richard Henderson wrote:
> On 10/21/24 05:17, Ilya Leoshkevich wrote:
> > Running qemu-i386 on a system running with SELinux in enforcing
> > mode
> > fails with:
> > 
> >      qemu-i386: tests/tcg/i386-linux-user/sigreturn-sigmask: Unable
> > to find a guest_base to satisfy all guest address mapping
> > requirements
> >        00000000-ffffffff
> > 
> > The reason is that main() determines mmap_min_addr from
> > /proc/sys/vm/mmap_min_addr, but SELinux additionally defines
> > CONFIG_LSM_MMAP_MIN_ADDR, which is normally larger: 32K or 64K,
> > but,
> > in general, can be anything. There is no portable way to query its
> > value: /boot/config, /proc/config and /proc/config.gz are distro-
> > and
> > environment-specific.
> > 
> > For maximum compatibility, probing is required. Use
> > pgb_find_fallback()
> > for this purpose. The downside of this approach is that
> > mmap_min_addr
> > remains incorrect, but there don't seem to be any practical
> > consequences from this. If a correct mmap_min_addr will be required
> > in
> > the future, probing will need to be moved to linux-user main().
> > 
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >   linux-user/elfload.c | 4 ++++
> >   1 file changed, 4 insertions(+)
> 
> This is
> 
>      https://gitlab.com/qemu-project/qemu/-/issues/2598
> 
> which we closed as a system configuration / kernel bug.
> 
> I'm open to working around the issue, because I can see it coming up
> again and again.
> 
> In pgb_find_fallback, we use a skip value of 4M or 4G, using that
> skip as the base at 
> which to begin the search.  I think it might be better to use this as
> the initial start 
> point in pgb_find_itree as well, rather than mmap_min_addr.
> 
> Since I never had a setup in which this triggered, would you be
> willing to test such a change?
> 
> 
> r~

The environment is a trixie container running on Fedora 40.

The following works, I can send a v2 if that's the preferred way to go:

--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2898,7 +2898,7 @@ static uintptr_t pgb_try_itree(const PGBAddrs
*ga, uintptr_t base,
 static uintptr_t pgb_find_itree(const PGBAddrs *ga, IntervalTreeRoot
*root,
                                 uintptr_t align, uintptr_t brk)
 {
-    uintptr_t last = mmap_min_addr;
+    uintptr_t last = sizeof(uintptr_t) == 4 ? MiB : GiB;
     uintptr_t base, skip;
 
     while (true) {

But just for my understanding, what is wrong with the current approach?
The intention here is to fix the weird case without affecting the happy
path. It also looks natural to try the fallback once the normal
handling fails.


  reply	other threads:[~2024-10-22  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 12:17 [PATCH] linux-user: Tolerate CONFIG_LSM_MMAP_MIN_ADDR Ilya Leoshkevich
2024-10-22  2:34 ` Richard Henderson
2024-10-22  9:50   ` Ilya Leoshkevich [this message]
2024-10-22 14:33     ` Richard Henderson

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=5a6ec294c6da14a2a65d3669ac4dcdc79934c452.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=laurent@vivier.eu \
    --cc=mjt@tls.msk.ru \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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;
as well as URLs for NNTP newsgroup(s).