qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Lirong Yuan <yuanzi@google.com>,
	qemu-devel@nongnu.org, qemu-trivial@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH] linux-user: Add an argument QEMU_MMAP_BASE to set custom mmap base address in qemu user mode
Date: Mon, 2 Mar 2020 15:56:32 +0100	[thread overview]
Message-ID: <553af2a0-2092-fe7f-ad7a-3b7ecebbe0a5@vivier.eu> (raw)
In-Reply-To: <CADjx4CKoSuu2zWn7BRhpxLL3TaimR7fX99u_r41egctwA1LVTQ@mail.gmail.com>

Le 29/02/2020 à 01:43, Lirong Yuan a écrit :
> On Fri, Feb 21, 2020 at 5:09 PM Lirong Yuan <yuanzi@google.com> wrote:
>>
>> This change allows us to set custom base address for guest programs. It is needed to allow qemu to work with Thread Sanitizer (TSan), which has specific boundary definitions for memory mappings on different platforms:
>> https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_platform.h

Could you give more details and some examples?

Thanks,
Laurent

>> Signed-off-by: Lirong Yuan <yuanzi@google.com>
>> ---
>>  linux-user/main.c | 12 ++++++++++++
>>  linux-user/mmap.c |  3 ++-
>>  linux-user/qemu.h |  5 +++++
>>  3 files changed, 19 insertions(+), 1 deletion(-)
>>
>> diff --git a/linux-user/main.c b/linux-user/main.c
>> index fba833aac9..c01af6bfee 100644
>> --- a/linux-user/main.c
>> +++ b/linux-user/main.c
>> @@ -336,6 +336,16 @@ static void handle_arg_guest_base(const char *arg)
>>      have_guest_base = 1;
>>  }
>>
>> +static void handle_arg_mmap_base(const char *arg)
>> +{
>> +    int err = qemu_strtoul(arg, NULL, 0, &mmap_base);
>> +    if (err) {
>> +        fprintf(stderr, "Invalid mmap_base: %s, err: %d\n", arg, err);
>> +        exit(EXIT_FAILURE);
>> +    }
>> +    mmap_next_start = mmap_base;
>> +}
>> +
>>  static void handle_arg_reserved_va(const char *arg)
>>  {
>>      char *p;
>> @@ -440,6 +450,8 @@ static const struct qemu_argument arg_table[] = {
>>       "uname",      "set qemu uname release string to 'uname'"},
>>      {"B",          "QEMU_GUEST_BASE",  true,  handle_arg_guest_base,
>>       "address",    "set guest_base address to 'address'"},
>> +    {"mmap_base",  "QEMU_MMAP_BASE",   true,  handle_arg_mmap_base,
>> +     "",           "begin allocating guest pages at this host address"},
>>      {"R",          "QEMU_RESERVED_VA", true,  handle_arg_reserved_va,
>>       "size",       "reserve 'size' bytes for guest virtual address space"},
>>      {"d",          "QEMU_LOG",         true,  handle_arg_log,
>> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
>> index 8685f02e7e..3f35543acf 100644
>> --- a/linux-user/mmap.c
>> +++ b/linux-user/mmap.c
>> @@ -189,6 +189,7 @@ static int mmap_frag(abi_ulong real_start,
>>  # define TASK_UNMAPPED_BASE  0x40000000
>>  #endif
>>  abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
>> +abi_ulong mmap_base = TASK_UNMAPPED_BASE;
>>
>>  unsigned long last_brk;
>>
>> @@ -299,7 +300,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
>>
>>              if ((addr & (align - 1)) == 0) {
>>                  /* Success.  */
>> -                if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) {
>> +                if (start == mmap_next_start && addr >= mmap_base) {
>>                      mmap_next_start = addr + size;
>>                  }
>>                  return addr;
>> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
>> index 560a68090e..83c00cfea2 100644
>> --- a/linux-user/qemu.h
>> +++ b/linux-user/qemu.h
>> @@ -161,6 +161,11 @@ void task_settid(TaskState *);
>>  void stop_all_tasks(void);
>>  extern const char *qemu_uname_release;
>>  extern unsigned long mmap_min_addr;
>> +/*
>> + * mmap_base is minimum address to use when allocating guest pages. All guest
>> + * pages will be allocated at this (guest) address or higher addresses.
>> + */
>> +extern abi_ulong mmap_base;
>>
>>  /* ??? See if we can avoid exposing so much of the loader internals.  */
>>
>> --
>> 2.25.0.265.gbab2e86ba0-goog
>>
> 
> Friendly ping~
> 
> Link to the page for the patch on patchwork:
> http://patchwork.ozlabs.org/patch/1242370/
> 



  reply	other threads:[~2020-03-02 14:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-22  1:09 [PATCH] linux-user: Add an argument QEMU_MMAP_BASE to set custom mmap base address in qemu user mode Lirong Yuan
2020-02-29  0:43 ` Lirong Yuan
2020-03-02 14:56   ` Laurent Vivier [this message]
2020-03-02 17:53     ` Lirong Yuan
2020-03-02 18:38       ` Laurent Vivier
2020-03-02 19:51         ` Lirong Yuan
2020-03-09 18:07           ` Lirong Yuan
2020-03-12  8:42             ` Laurent Vivier
2020-03-12 22:35               ` Lirong Yuan
  -- strict thread matches above, loose matches on Subject: below --
2020-02-21 21:46 Lirong Yuan
2020-02-21 23:34 ` no-reply

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=553af2a0-2092-fe7f-ad7a-3b7ecebbe0a5@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=riku.voipio@iki.fi \
    --cc=yuanzi@google.com \
    /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).