From nobody Sun May 19 10:14:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1582321634; cv=none; d=zohomail.com; s=zohoarc; b=EV4rBJ0b6neilfUeVoYbs8I6UeYubXu0B5KEP9Cy//sOhjRQpKRuzdCSM2eEt/gcchSeJqta6HqZHQdxDSs3jl1FcZvRpB21Yl+GkixSVs5ZHmtOHf+yxYBLm28LTgL8WG1qMGpYevjJfKFwQYI0O9g5o7x8E6cV8rSP1KdGBBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582321634; h=Content-Type:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=fi959EXaB76t7wi24tDnZlL6uaaa5akWttvkNwT+h64=; b=Cjz+omvaeGY5OLDG6/ifo6Y6X+Rmzq2JDZUaqndZIJnmJ28vjS09OjUMNT8D5qUgeKxELtuLHfy9WYxJLXjg8s2x6qYoY6kt1INM8aCH+e1QQ4NvDR96RE8Ni5jqfz/zrAlKk1FsrMdo7eo966RSmX0jwxX3LJzEB3nyaRLBu2M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582321634460404.6026278353861; Fri, 21 Feb 2020 13:47:14 -0800 (PST) Received: from localhost ([::1]:36568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5G8e-0005AV-RR for importer@patchew.org; Fri, 21 Feb 2020 16:47:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36480) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <3qk9QXgYKCoM51hu6pnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--yuanzi.bounces.google.com>) id 1j5G7q-0004id-0Q for qemu-devel@nongnu.org; Fri, 21 Feb 2020 16:46:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <3qk9QXgYKCoM51hu6pnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--yuanzi.bounces.google.com>) id 1j5G7o-0000xJ-PI for qemu-devel@nongnu.org; Fri, 21 Feb 2020 16:46:21 -0500 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]:43768) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <3qk9QXgYKCoM51hu6pnvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--yuanzi.bounces.google.com>) id 1j5G7o-0000wU-GO for qemu-devel@nongnu.org; Fri, 21 Feb 2020 16:46:20 -0500 Received: by mail-pj1-x104a.google.com with SMTP id i3so1733584pjx.8 for ; Fri, 21 Feb 2020 13:46:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=fi959EXaB76t7wi24tDnZlL6uaaa5akWttvkNwT+h64=; b=DAUH0UAMT1iFtOKftRl9dIIFU218ii2cFaDaBwGaurXqo/naafK7HPqtXRAQ7jaL5x tukWZUUfuQlA5y/fNpsRhy5ezbQ6zT9yTQycLrulKUgOxpPpH9K17qKBDV11qSw7Ec2Y YpiWuyxAiEpAgvennsi7+2UtZaMKlzgnuOfqeqa4qWgNXAJy9TF7hKKgL7ygzNge3Rzq l9LVwQnzi6Fnx0YeRyi2GaWT3IVijmZPcPZghtEC24NasI7xoIOo0hCLpotl/9yLq9i+ GwP+cGbPUsuw7inllupyYYQP5088JS+Iy4FqIeobtfe+Pc9IQL2oaKpeu+yUDb/o+oJf Ke7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=fi959EXaB76t7wi24tDnZlL6uaaa5akWttvkNwT+h64=; b=OYrfdxtiavw6IpKE8suzjiUXyGyRg/SOZGoKyG1+AnCjIjJb95+uibtZ5YreACkVAI /hsNCUxbcFqCvWzwcef9iK6tJbnq0KGmD4+PJ/bN+GNuvvDpzFywO6OSFwBeo6sS8R/q wpCMiC5tbeH+gfSIrTDvgO4fGAGVvOvUtg3bezOyr9Ym4yGX56LAVYnRQZ/Cq7u7wjvV k3saCXuOzgcb5Xxdz+7jr0NtKgxoT56hGN18xYED9ofYsgyqBWR4FdESliF5EyTP0eqw uaTqTjlVZjwUyWr2LL8Uo8300R89C09bmZTKGPzMf0Y7NXYWHjSvB0tPFhVwJEkby/BB EdRQ== X-Gm-Message-State: APjAAAWHDA6Qh1E2LKMXQyLgrAoLU1HLi3Xpqy223Oz4OFPutRMqKcMi swyUWALTsIzSfSslyl8lKk7I970VJQh7uRoRdOrCo3m68NyDlu0+TPWqCNRkzTD9HnE1T6oXvaV EldLyCy2Mqr+kpQhAw66yCK989teJ9u2ZL/GrjnSljzDx5v1mgUG4gmJVaglF X-Google-Smtp-Source: APXvYqyvFZLNhABUFu6QYlAbvf/POMbpw5g8kvYFpbfqu7tcHhqT80U27HqP+e/ADSd1G/VbNQjDQRcBCog= X-Received: by 2002:a65:5c44:: with SMTP id v4mr42131361pgr.340.1582321578537; Fri, 21 Feb 2020 13:46:18 -0800 (PST) Date: Fri, 21 Feb 2020 13:46:14 -0800 Message-Id: <20200221214614.165338-1-yuanzi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH] linux-user: Add an argument QEMU_MMAP_BASE to set custom mmap base address in qemu user mode From: Lirong Yuan To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Cc: Lirong Yuan , Riku Voipio , Laurent Vivier X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::104a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 specif= ic boundary definitions for memory mappings on different platforms: https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/t= san_platform.h Signed-off-by: Lirong Yuan --- 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..dfcd867399 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 =3D 1; } =20 +static void handle_arg_mmap_base(const char *arg) +{ + mmap_base =3D strtoul(arg, NULL, 0); + if (mmap_base =3D=3D 0) { + fprintf(stderr, "Invalid mmap_base: %s\n", arg); + exit(EXIT_FAILURE); + } + mmap_next_start =3D mmap_base; +} + static void handle_arg_reserved_va(const char *arg) { char *p; @@ -440,6 +450,8 @@ static const struct qemu_argument arg_table[] =3D { "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 =3D TASK_UNMAPPED_BASE; +abi_ulong mmap_base =3D TASK_UNMAPPED_BASE; =20 unsigned long last_brk; =20 @@ -299,7 +300,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size= , abi_ulong align) =20 if ((addr & (align - 1)) =3D=3D 0) { /* Success. */ - if (start =3D=3D mmap_next_start && addr >=3D TASK_UNMAPPE= D_BASE) { + if (start =3D=3D mmap_next_start && addr >=3D mmap_base) { mmap_next_start =3D 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 gu= est + * pages will be allocated at this (guest) address or higher addresses. + */ +extern abi_ulong mmap_base; =20 /* ??? See if we can avoid exposing so much of the loader internals. */ =20 --=20 2.25.0.265.gbab2e86ba0-goog