qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>
Cc: Riku Voipio <riku.voipio@iki.fi>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH] linux-user/elfload: use MAP_FIXED in pgb_reserved_va
Date: Thu, 2 Jul 2020 12:52:58 -0700	[thread overview]
Message-ID: <09e88ba9-25ff-6f03-c216-2ce9e52abf04@linaro.org> (raw)
In-Reply-To: <87y2o4r4zc.fsf@linaro.org>

On 6/30/20 7:41 AM, Alex Bennée wrote:
> 
> Peter Maydell <peter.maydell@linaro.org> writes:
> 
>> On Tue, 30 Jun 2020 at 11:36, Alex Bennée <alex.bennee@linaro.org> wrote:
>>>
>>> Given we assert the requested address matches what we asked we should
>>> also make that clear in the mmap flags. Otherwise we see failures in
>>> the GitLab environment for some currently unknown but allowable
>>> reason.
>>
>> Adding MAP_FIXED will mean that instead of failing if there's
>> something else already at that address, the kernel will now
>> silently blow that away in favour of the new mapping. Is
>> that definitely what we want here ?
> 
> Hmm maybe not.

Definitely not.

> But hey I just noticed that we have MAP_FIXED_NOREPLACE
> (since Linux 4.17) which says:
> 
>    This flag provides behavior that is similar  to  MAP_FIXED  with
>    respect   to   the   addr   enforcement,  but  differs  in  that
>    MAP_FIXED_NOREPLACE never clobbers a preexisting  mapped  range.
>    If  the  requested range would collide with an existing mapping,
>    then this call fails with  the  error  EEXIST.   This  flag  can
>    therefore  be used as a way to atomically (with respect to other
>    threads) attempt to map an address range: one thread  will  suc‐
>    ceed; all others will report failure.
> 
>    Note   that   older   kernels   which   do   not  recognize  the
>    MAP_FIXED_NOREPLACE flag will typically (upon detecting a colli‐
>    sion  with a preexisting mapping) fall back to a "non-MAP_FIXED"
>    type of behavior: they will return an address that is  different
>    from  the  requested  address.   Therefore,  backward-compatible
>    software should check the returned address against the requested
>    address.
> 
> So maybe that is what we should do?

Yes, that would be better, because those are the exact semantics that we want.
 Though it would be Really Nice to know what's up with gitlab...

> Now you've pointed that out I wonder if we need to fix
> pgd_find_hole_fallback as well?

Yes, that could benefit from MAP_FIXED_NOREPLACE.

I do think there's a way we could streamline the 32-on-64 case.  At present we
are groveling through /proc/self/maps, or mmaping+unmaping, and then mmaping.
Whereas we could just mmap once and be done -- it's the 32-on-32 case that
requires the song and dance.


r~


      reply	other threads:[~2020-07-02 19:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 10:34 [PATCH] linux-user/elfload: use MAP_FIXED in pgb_reserved_va Alex Bennée
2020-06-30 13:10 ` Peter Maydell
2020-06-30 14:41   ` Alex Bennée
2020-07-02 19:52     ` Richard Henderson [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=09e88ba9-25ff-6f03-c216-2ce9e52abf04@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).