From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345500; cv=none; d=zohomail.com; s=zohoarc; b=Y7S7wdf05zNR1WqnfKAdae2gBS67Mmpiqy72TBr4mNWAZ6r/Pjg+rR92RjwvDasiH1z22QNcMwiOO1BkO7n33JwzCETxXGDmLHMZku9rarR6Dhkr9zjrJKDww/ZOAMuzQ74iMF6Gw66aEpv7curbjP/AZB5Yc+noSCgBY6u4YNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345500; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=R+sf6X8cAIIXCbMbS10GOsmkzI4QGsf9SG4MZf79bWg=; b=TiH9cwt62ladeCAiess2F/rm+YDPNmglbVwPkjadX2OGd9w2J3tUJ2fhtVvV020IuOh6ZT5pk0tw/OumxgAfNnR0exet3UWES0cVfZhtD1u+LnTEY9iOTcxmkCe5uJulgwMLwZ4/WMngLMK7f+tcZau3JnTbolHeDxhB/wOL31U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345500170982.1691153782032; Fri, 1 May 2020 08:05:00 -0700 (PDT) Received: from localhost ([::1]:43496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXDm-00075S-Gz for importer@patchew.org; Fri, 01 May 2020 11:04:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34276) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7O-0004s6-13 for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6N-0007rS-KE for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:21 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:45597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6N-0007r5-5s for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:19 -0400 Received: by mail-wr1-x42b.google.com with SMTP id o27so6484320wra.12 for ; Fri, 01 May 2020 07:57:18 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u3sm4494332wrt.93.2020.05.01.07.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 29E161FF87; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R+sf6X8cAIIXCbMbS10GOsmkzI4QGsf9SG4MZf79bWg=; b=qmWVgnvP+umpzS7rBh8/JhG0/MIEgL05FpGO/lTOIwU18npyFa0H6VciG2emU0puC2 94B76iZ4i2A9Ot3XCHeoAuiOpXBK0OxnsuqZ77HOrkHSslnD2OHIw7PuyTBL7pGT66r8 i0G/zYJPR2NLkbqqnHjwutYmxEEbvHx4u9RnEc9bSyH3cjocGIFiGwSJKOycEB6ChMKT l46mPGVPhz5tHjrC+Q6PK6v0W4rVdLhIkjpiSKV1lHV75wZkcJkpmzBZvbDVAJ4FpJAL t0p/25B3KOIHve9IYjJCZStCDxiVg2L+XwDzbq/5LYE1bSyyJFCzz0329w+Tk+x5HEYX 3poQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R+sf6X8cAIIXCbMbS10GOsmkzI4QGsf9SG4MZf79bWg=; b=e28I8MbBKBQvH53YFr3bsL7JOjpMd9SPz4O1Yna3D1HHSCtpc8s/vHV8f5CteAuORY iWz3sTALmUHLc6SDecGpcf0qX2tP7O0k5qHnB5uNFeZ16TIfooVcT/FM2FhpjPY5dKVp XENQGC8KJO7PpA5f/JzCgOq/usdUtVrknxgT1Yu8vvnGyLY41XxgaLkTUN3zeM1UN6Pj kE3a5f6oTXTkUkyPvhmBMkJgxQ4F6x9mCr6Bx+wNK6jSTl9sE7hz1EWh+jkYwlQmrenQ 6kfcUlyzGd3CMmPQXwVIGM93zzoKy00nPMSBGs6HeJDXpeBks5OUrDUd9MF1Fr+5aUQ8 SVPQ== X-Gm-Message-State: AGi0PuZLHh3tjAzAujqYZ5+6O2gRGSUxAwEQfDjhlssmreCaIc+JUn0V BmeqOCwsj/sZZhNhT6IXwxIqKQ== X-Google-Smtp-Source: APiQypKrlbofLLZFXw4ftMBA8yTmQdE22ae9P0EMOrVsODJ5b6q9zmjpj395vyLoN5U770K1Bc0UcA== X-Received: by 2002:a5d:694a:: with SMTP id r10mr4610677wrw.228.1588345037241; Fri, 01 May 2020 07:57:17 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 1/7] linux-user: completely re-write init_guest_space Date: Fri, 1 May 2020 15:57:06 +0100 Message-Id: <20200501145713.19822-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::42b 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: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) First we ensure all guest space initialisation logic comes through probe_guest_base once we understand the nature of the binary we are loading. The convoluted init_guest_space routine is removed and replaced with a number of pgb_* helpers which are called depending on what requirements we have when loading the binary. We first try to do what is requested by the host. Failing that we try and satisfy the guest requested base address. If all those options fail we fall back to finding a space in the memory map using our recently written read_self_maps() helper. There are some additional complications we try and take into account when looking for holes in the address space. We try not to go directly after the system brk() space so there is space for a little growth. We also don't want to have to use negative offsets which would result in slightly less efficient code on x86 when it's unable to use the segment offset register. Less mind-binding gotos and hopefully clearer logic throughout. Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier --- v3 - include rth updates that - split probe_guest_base into multiple functions - more heuristics on gap finding v4 - whitespace fix --- linux-user/qemu.h | 31 ++- linux-user/elfload.c | 503 +++++++++++++++++++++--------------------- linux-user/flatload.c | 6 + linux-user/main.c | 23 +- 4 files changed, 277 insertions(+), 286 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 792c74290f..ce902f5132 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -219,18 +219,27 @@ void init_qemu_uname_release(void); void fork_start(void); void fork_end(int child); =20 -/* Creates the initial guest address space in the host memory space using - * the given host start address hint and size. The guest_start parameter - * specifies the start address of the guest space. guest_base will be the - * difference between the host start address computed by this function and - * guest_start. If fixed is specified, then the mapped address space must - * start at host_start. The real start address of the mapped memory space= is - * returned or -1 if there was an error. +/** + * probe_guest_base: + * @image_name: the executable being loaded + * @loaddr: the lowest fixed address in the executable + * @hiaddr: the highest fixed address in the executable + * + * Creates the initial guest address space in the host memory space. + * + * If @loaddr =3D=3D 0, then no address in the executable is fixed, + * i.e. it is fully relocatable. In that case @hiaddr is the size + * of the executable. + * + * This function will not return if a valid value for guest_base + * cannot be chosen. On return, the executable loader can expect + * + * target_mmap(loaddr, hiaddr - loaddr, ...) + * + * to succeed. */ -unsigned long init_guest_space(unsigned long host_start, - unsigned long host_size, - unsigned long guest_start, - bool fixed); +void probe_guest_base(const char *image_name, + abi_ulong loaddr, abi_ulong hiaddr); =20 #include "qemu/log.h" =20 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 619c054cc4..01a9323a63 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -11,6 +11,7 @@ #include "qemu/queue.h" #include "qemu/guest-random.h" #include "qemu/units.h" +#include "qemu/selfmap.h" =20 #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -382,68 +383,30 @@ enum { =20 /* The commpage only exists for 32 bit kernels */ =20 -/* Return 1 if the proposed guest space is suitable for the guest. - * Return 0 if the proposed guest space isn't suitable, but another - * address space should be tried. - * Return -1 if there is no way the proposed guest space can be - * valid regardless of the base. - * The guest code may leave a page mapped and populate it if the - * address is suitable. - */ -static int init_guest_commpage(unsigned long guest_base, - unsigned long guest_size) -{ - unsigned long real_start, test_page_addr; - - /* We need to check that we can force a fault on access to the - * commpage at 0xffff0fxx - */ - test_page_addr =3D guest_base + (0xffff0f00 & qemu_host_page_mask); - - /* If the commpage lies within the already allocated guest space, - * then there is no way we can allocate it. - * - * You may be thinking that that this check is redundant because - * we already validated the guest size against MAX_RESERVED_VA; - * but if qemu_host_page_mask is unusually large, then - * test_page_addr may be lower. - */ - if (test_page_addr >=3D guest_base - && test_page_addr < (guest_base + guest_size)) { - return -1; - } +#define ARM_COMMPAGE (intptr_t)0xffff0f00u =20 - /* Note it needs to be writeable to let us initialise it */ - real_start =3D (unsigned long) - mmap((void *)test_page_addr, qemu_host_page_size, - PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +static bool init_guest_commpage(void) +{ + void *want =3D g2h(ARM_COMMPAGE & -qemu_host_page_size); + void *addr =3D mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); =20 - /* If we can't map it then try another address */ - if (real_start =3D=3D -1ul) { - return 0; + if (addr =3D=3D MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); } - - if (real_start !=3D test_page_addr) { - /* OS didn't put the page where we asked - unmap and reject */ - munmap((void *)real_start, qemu_host_page_size); - return 0; + if (addr !=3D want) { + return false; } =20 - /* Leave the page mapped - * Populate it (mmap should have left it all 0'd) - */ - - /* Kernel helper versions */ - __put_user(5, (uint32_t *)g2h(0xffff0ffcul)); + /* Set kernel helper versions; rest of page is 0. */ + __put_user(5, (uint32_t *)g2h(0xffff0ffcu)); =20 - /* Now it's populated make it RO */ - if (mprotect((void *)test_page_addr, qemu_host_page_size, PROT_READ)) { + if (mprotect(addr, qemu_host_page_size, PROT_READ)) { perror("Protecting guest commpage"); - exit(-1); + exit(EXIT_FAILURE); } - - return 1; /* All good */ + return true; } =20 #define ELF_HWCAP get_elf_hwcap() @@ -2075,239 +2038,267 @@ static abi_ulong create_elf_tables(abi_ulong p, i= nt argc, int envc, return sp; } =20 -unsigned long init_guest_space(unsigned long host_start, - unsigned long host_size, - unsigned long guest_start, - bool fixed) -{ - /* In order to use host shmat, we must be able to honor SHMLBA. */ - unsigned long align =3D MAX(SHMLBA, qemu_host_page_size); - unsigned long current_start, aligned_start; - int flags; - - assert(host_start || host_size); - - /* If just a starting address is given, then just verify that - * address. */ - if (host_start && !host_size) { -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - if (init_guest_commpage(host_start, host_size) !=3D 1) { - return (unsigned long)-1; - } +#ifndef ARM_COMMPAGE +#define ARM_COMMPAGE 0 +#define init_guest_commpage() true #endif - return host_start; - } =20 - /* Setup the initial flags and start address. */ - current_start =3D host_start & -align; - flags =3D MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; - if (fixed) { - flags |=3D MAP_FIXED; - } +static void pgb_fail_in_use(const char *image_name) +{ + error_report("%s: requires virtual address space that is in use " + "(omit the -B option or choose a different value)", + image_name); + exit(EXIT_FAILURE); +} =20 - /* Otherwise, a non-zero size region of memory needs to be mapped - * and validated. */ +static void pgb_have_guest_base(const char *image_name, abi_ulong guest_lo= addr, + abi_ulong guest_hiaddr, long align) +{ + const int flags =3D MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; + void *addr, *test; =20 -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - /* On 32-bit ARM, we need to map not just the usable memory, but - * also the commpage. Try to find a suitable place by allocating - * a big chunk for all of it. If host_start, then the naive - * strategy probably does good enough. - */ - if (!host_start) { - unsigned long guest_full_size, host_full_size, real_start; - - guest_full_size =3D - (0xffff0f00 & qemu_host_page_mask) + qemu_host_page_size; - host_full_size =3D guest_full_size - guest_start; - real_start =3D (unsigned long) - mmap(NULL, host_full_size, PROT_NONE, flags, -1, 0); - if (real_start =3D=3D (unsigned long)-1) { - if (host_size < host_full_size - qemu_host_page_size) { - /* We failed to map a continous segment, but we're - * allowed to have a gap between the usable memory and - * the commpage where other things can be mapped. - * This sparseness gives us more flexibility to find - * an address range. - */ - goto naive; - } - return (unsigned long)-1; + if (!QEMU_IS_ALIGNED(guest_base, align)) { + fprintf(stderr, "Requested guest base 0x%lx does not satisfy " + "host minimum alignment (0x%lx)\n", + guest_base, align); + exit(EXIT_FAILURE); + } + + /* Sanity check the guest binary. */ + if (reserved_va) { + if (guest_hiaddr > reserved_va) { + error_report("%s: requires more than reserved virtual " + "address space (0x%" PRIx64 " > 0x%lx)", + image_name, (uint64_t)guest_hiaddr, reserved_va); + exit(EXIT_FAILURE); } - munmap((void *)real_start, host_full_size); - if (real_start & (align - 1)) { - /* The same thing again, but with extra - * so that we can shift around alignment. - */ - unsigned long real_size =3D host_full_size + qemu_host_page_si= ze; - real_start =3D (unsigned long) - mmap(NULL, real_size, PROT_NONE, flags, -1, 0); - if (real_start =3D=3D (unsigned long)-1) { - if (host_size < host_full_size - qemu_host_page_size) { - goto naive; - } - return (unsigned long)-1; - } - munmap((void *)real_start, real_size); - real_start =3D ROUND_UP(real_start, align); + } else { + if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) { + error_report("%s: requires more virtual address space " + "than the host can provide (0x%" PRIx64 ")", + image_name, (uint64_t)guest_hiaddr - guest_base); + exit(EXIT_FAILURE); } - current_start =3D real_start; } - naive: -#endif =20 - while (1) { - unsigned long real_start, real_size, aligned_size; - aligned_size =3D real_size =3D host_size; + /* + * Expand the allocation to the entire reserved_va. + * Exclude the mmap_min_addr hole. + */ + if (reserved_va) { + guest_loaddr =3D (guest_base >=3D mmap_min_addr ? 0 + : mmap_min_addr - guest_base); + guest_hiaddr =3D reserved_va; + } =20 - /* Do not use mmap_find_vma here because that is limited to the - * guest address space. We are going to make the - * guest address space fit whatever we're given. - */ - real_start =3D (unsigned long) - mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0= ); - if (real_start =3D=3D (unsigned long)-1) { - return (unsigned long)-1; - } + /* Reserve the address space for the binary, or reserved_va. */ + test =3D g2h(guest_loaddr); + addr =3D mmap(test, guest_hiaddr - guest_loaddr, PROT_NONE, flags, -1,= 0); + if (test !=3D addr) { + pgb_fail_in_use(image_name); + } +} =20 - /* Check to see if the address is valid. */ - if (host_start && real_start !=3D current_start) { - qemu_log_mask(CPU_LOG_PAGE, "invalid %lx && %lx !=3D %lx\n", - host_start, real_start, current_start); - goto try_again; +/* Return value for guest_base, or -1 if no hole found. */ +static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_siz= e, + long align) +{ + GSList *maps, *iter; + uintptr_t this_start, this_end, next_start, brk; + intptr_t ret =3D -1; + + assert(QEMU_IS_ALIGNED(guest_loaddr, align)); + + maps =3D read_self_maps(); + + /* Read brk after we've read the maps, which will malloc. */ + brk =3D (uintptr_t)sbrk(0); + + /* The first hole is before the first map entry. */ + this_start =3D mmap_min_addr; + + for (iter =3D maps; iter; + this_start =3D next_start, iter =3D g_slist_next(iter)) { + uintptr_t align_start, hole_size; + + this_end =3D ((MapInfo *)iter->data)->start; + next_start =3D ((MapInfo *)iter->data)->end; + align_start =3D ROUND_UP(this_start, align); + + /* Skip holes that are too small. */ + if (align_start >=3D this_end) { + continue; + } + hole_size =3D this_end - align_start; + if (hole_size < guest_size) { + continue; } =20 - /* Ensure the address is properly aligned. */ - if (real_start & (align - 1)) { - /* Ideally, we adjust like - * - * pages: [ ][ ][ ][ ][ ] - * old: [ real ] - * [ aligned ] - * new: [ real ] - * [ aligned ] - * - * But if there is something else mapped right after it, - * then obviously it won't have room to grow, and the - * kernel will put the new larger real someplace else with - * unknown alignment (if we made it to here, then - * fixed=3Dfalse). Which is why we grow real by a full page - * size, instead of by part of one; so that even if we get - * moved, we can still guarantee alignment. But this does - * mean that there is a padding of < 1 page both before - * and after the aligned range; the "after" could could - * cause problems for ARM emulation where it could butt in - * to where we need to put the commpage. - */ - munmap((void *)real_start, host_size); - real_size =3D aligned_size + align; - real_start =3D (unsigned long) - mmap((void *)real_start, real_size, PROT_NONE, flags, -1, = 0); - if (real_start =3D=3D (unsigned long)-1) { - return (unsigned long)-1; + /* If this hole contains brk, give ourselves some room to grow. */ + if (this_start <=3D brk && brk < this_end) { + hole_size -=3D guest_size; + if (sizeof(uintptr_t) =3D=3D 8 && hole_size >=3D 1 * GiB) { + align_start +=3D 1 * GiB; + } else if (hole_size >=3D 16 * MiB) { + align_start +=3D 16 * MiB; + } else { + align_start =3D (this_end - guest_size) & -align; + if (align_start < this_start) { + continue; + } } - aligned_start =3D ROUND_UP(real_start, align); - } else { - aligned_start =3D real_start; } =20 -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - /* On 32-bit ARM, we need to also be able to map the commpage. */ - int valid =3D init_guest_commpage(aligned_start - guest_start, - aligned_size + guest_start); - if (valid =3D=3D -1) { - munmap((void *)real_start, real_size); - return (unsigned long)-1; - } else if (valid =3D=3D 0) { - goto try_again; + /* Record the lowest successful match. */ + if (ret < 0) { + ret =3D align_start - guest_loaddr; } -#endif - - /* If nothing has said `return -1` or `goto try_again` yet, - * then the address we have is good. - */ - break; - - try_again: - /* That address didn't work. Unmap and try a different one. - * The address the host picked because is typically right at - * the top of the host address space and leaves the guest with - * no usable address space. Resort to a linear search. We - * already compensated for mmap_min_addr, so this should not - * happen often. Probably means we got unlucky and host - * address space randomization put a shared library somewhere - * inconvenient. - * - * This is probably a good strategy if host_start, but is - * probably a bad strategy if not, which means we got here - * because of trouble with ARM commpage setup. - */ - if (munmap((void *)real_start, real_size) !=3D 0) { - error_report("%s: failed to unmap %lx:%lx (%s)", __func__, - real_start, real_size, strerror(errno)); - abort(); + /* If this hole contains the identity map, select it. */ + if (align_start <=3D guest_loaddr && + guest_loaddr + guest_size <=3D this_end) { + ret =3D 0; } - current_start +=3D align; - if (host_start =3D=3D current_start) { - /* Theoretically possible if host doesn't have any suitably - * aligned areas. Normally the first mmap will fail. - */ - return (unsigned long)-1; + /* If this hole ends above the identity map, stop looking. */ + if (this_end >=3D guest_loaddr) { + break; } } + free_self_maps(maps); =20 - qemu_log_mask(CPU_LOG_PAGE, "Reserved 0x%lx bytes of guest address spa= ce\n", host_size); - - return aligned_start; + return ret; } =20 -static void probe_guest_base(const char *image_name, - abi_ulong loaddr, abi_ulong hiaddr) +static void pgb_static(const char *image_name, abi_ulong orig_loaddr, + abi_ulong orig_hiaddr, long align) { - /* Probe for a suitable guest base address, if the user has not set - * it explicitly, and set guest_base appropriately. - * In case of error we will print a suitable message and exit. - */ - const char *errmsg; - if (!have_guest_base && !reserved_va) { - unsigned long host_start, real_start, host_size; + uintptr_t loaddr =3D orig_loaddr; + uintptr_t hiaddr =3D orig_hiaddr; + uintptr_t addr; =20 - /* Round addresses to page boundaries. */ - loaddr &=3D qemu_host_page_mask; - hiaddr =3D HOST_PAGE_ALIGN(hiaddr); + if (hiaddr !=3D orig_hiaddr) { + error_report("%s: requires virtual address space that the " + "host cannot provide (0x%" PRIx64 ")", + image_name, (uint64_t)orig_hiaddr); + exit(EXIT_FAILURE); + } =20 - if (loaddr < mmap_min_addr) { - host_start =3D HOST_PAGE_ALIGN(mmap_min_addr); + loaddr &=3D -align; + if (ARM_COMMPAGE) { + /* + * Extend the allocation to include the commpage. + * For a 64-bit host, this is just 4GiB; for a 32-bit host, + * the address arithmetic will wrap around, but the difference + * will produce the correct allocation size. + */ + if (sizeof(uintptr_t) =3D=3D 8 || loaddr >=3D 0x80000000u) { + hiaddr =3D (uintptr_t)4 << 30; } else { - host_start =3D loaddr; - if (host_start !=3D loaddr) { - errmsg =3D "Address overflow loading ELF binary"; - goto exit_errmsg; - } + loaddr =3D ARM_COMMPAGE & -align; } - host_size =3D hiaddr - loaddr; + } =20 - /* Setup the initial guest memory space with ranges gleaned from - * the ELF image that is being loaded. + addr =3D pgb_find_hole(loaddr, hiaddr - loaddr, align); + if (addr =3D=3D -1) { + /* + * If ARM_COMMPAGE, there *might* be a non-consecutive allocation + * that can satisfy both. But as the normal arm32 link base addre= ss + * is ~32k, and we extend down to include the commpage, making the + * overhead only ~96k, this is unlikely. */ - real_start =3D init_guest_space(host_start, host_size, loaddr, fal= se); - if (real_start =3D=3D (unsigned long)-1) { - errmsg =3D "Unable to find space for application"; - goto exit_errmsg; - } - guest_base =3D real_start - loaddr; + error_report("%s: Unable to allocate %#zx bytes of " + "virtual address space", image_name, + (size_t)(hiaddr - loaddr)); + exit(EXIT_FAILURE); + } + + guest_base =3D addr; +} + +static void pgb_dynamic(const char *image_name, long align) +{ + /* + * The executable is dynamic and does not require a fixed address. + * All we need is a commpage that satisfies align. + * If we do not need a commpage, leave guest_base =3D=3D 0. + */ + if (ARM_COMMPAGE) { + uintptr_t addr, commpage; =20 - qemu_log_mask(CPU_LOG_PAGE, "Relocating guest address space from 0= x" - TARGET_ABI_FMT_lx " to 0x%lx\n", - loaddr, real_start); + /* 64-bit hosts should have used reserved_va. */ + assert(sizeof(uintptr_t) =3D=3D 4); + + /* + * By putting the commpage at the first hole, that puts guest_base + * just above that, and maximises the positive guest addresses. + */ + commpage =3D ARM_COMMPAGE & -align; + addr =3D pgb_find_hole(commpage, -commpage, align); + assert(addr !=3D -1); + guest_base =3D addr; } - return; +} =20 -exit_errmsg: - fprintf(stderr, "%s: %s\n", image_name, errmsg); - exit(-1); +static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr, + abi_ulong guest_hiaddr, long align) +{ + const int flags =3D MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; + void *addr, *test; + + if (guest_hiaddr > reserved_va) { + error_report("%s: requires more than reserved virtual " + "address space (0x%" PRIx64 " > 0x%lx)", + image_name, (uint64_t)guest_hiaddr, reserved_va); + exit(EXIT_FAILURE); + } + + /* Widen the "image" to the entire reserved address space. */ + pgb_static(image_name, 0, reserved_va, align); + + /* Reserve the memory on the host. */ + assert(guest_base !=3D 0); + test =3D g2h(0); + addr =3D mmap(test, reserved_va, PROT_NONE, flags, -1, 0); + if (addr =3D=3D MAP_FAILED) { + error_report("Unable to reserve 0x%lx bytes of virtual address " + "space for use as guest address space (check your " + "virtual memory ulimit setting or reserve less " + "using -R option)", reserved_va); + exit(EXIT_FAILURE); + } + assert(addr =3D=3D test); } =20 +void probe_guest_base(const char *image_name, abi_ulong guest_loaddr, + abi_ulong guest_hiaddr) +{ + /* In order to use host shmat, we must be able to honor SHMLBA. */ + uintptr_t align =3D MAX(SHMLBA, qemu_host_page_size); + + if (have_guest_base) { + pgb_have_guest_base(image_name, guest_loaddr, guest_hiaddr, align); + } else if (reserved_va) { + pgb_reserved_va(image_name, guest_loaddr, guest_hiaddr, align); + } else if (guest_loaddr) { + pgb_static(image_name, guest_loaddr, guest_hiaddr, align); + } else { + pgb_dynamic(image_name, align); + } + + /* Reserve and initialize the commpage. */ + if (!init_guest_commpage()) { + /* + * With have_guest_base, the user has selected the address and + * we are trying to work with that. Otherwise, we have selected + * free space and init_guest_commpage must succeeded. + */ + assert(have_guest_base); + pgb_fail_in_use(image_name); + } + + assert(QEMU_IS_ALIGNED(guest_base, align)); + qemu_log_mask(CPU_LOG_PAGE, "Locating guest address space " + "@ 0x%" PRIx64 "\n", (uint64_t)guest_base); +} =20 /* Load an ELF image into the address space. =20 @@ -2399,6 +2390,12 @@ static void load_elf_image(const char *image_name, i= nt image_fd, * MMAP_MIN_ADDR or the QEMU application itself. */ probe_guest_base(image_name, loaddr, hiaddr); + } else { + /* + * The binary is dynamic, but we still need to + * select guest_base. In this case we pass a size. + */ + probe_guest_base(image_name, 0, hiaddr - loaddr); } } =20 diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 66901f39cc..8fb448f0bf 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -441,6 +441,12 @@ static int load_flat_file(struct linux_binprm * bprm, indx_len =3D MAX_SHARED_LIBS * sizeof(abi_ulong); indx_len =3D (indx_len + 15) & ~(abi_ulong)15; =20 + /* + * Alloate the address space. + */ + probe_guest_base(bprm->filename, 0, + text_len + data_len + extra + indx_len); + /* * there are a couple of cases here, the separate code/data * case, and then the fully copied to RAM case which lumps diff --git a/linux-user/main.c b/linux-user/main.c index 22578b1633..1d20a83d4e 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -24,6 +24,7 @@ #include "qemu-version.h" #include #include +#include =20 #include "qapi/error.h" #include "qemu.h" @@ -747,28 +748,6 @@ int main(int argc, char **argv, char **envp) target_environ =3D envlist_to_environ(envlist, NULL); envlist_free(envlist); =20 - /* - * Now that page sizes are configured in tcg_exec_init() we can do - * proper page alignment for guest_base. - */ - guest_base =3D HOST_PAGE_ALIGN(guest_base); - - if (reserved_va || have_guest_base) { - guest_base =3D init_guest_space(guest_base, reserved_va, 0, - have_guest_base); - if (guest_base =3D=3D (unsigned long)-1) { - fprintf(stderr, "Unable to reserve 0x%lx bytes of virtual addr= ess " - "space for use as guest address space (check your virt= ual " - "memory ulimit setting or reserve less using -R option= )\n", - reserved_va); - exit(EXIT_FAILURE); - } - - if (reserved_va) { - mmap_next_start =3D reserved_va; - } - } - /* * Read in mmap_min_addr kernel parameter. This value is used * When loading the ELF image to determine whether guest_base --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345326; cv=none; d=zohomail.com; s=zohoarc; b=nwGW5TwyfvGhZe/C9Kt4E3LFduSzDi5EjJqsTw1dEmgsUBZMnk/+66ZmD59nlQ2nqoszftw8j4zuT8HH2V26QlB/2agKt6q4IH9pXeSqoHa4BMx/2ADjklU0rcCNunCHVGGI/eNL3VwIrtE0QKHGCFSoyfEQsX73ETpgnnMsMCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345326; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rec4lCI7C2I9ftVXhw3jnhwwniJ/OyIiNlpjw4I33hQ=; b=cX83Ar6v2hs7hAaIuqzvBB6N9OFd7eT9jOtMHpV8JQIjYYNVrYMfvN1Ut6IWurEAYOv7DhYTlJ1yumgA1cFvcoxBr8bNkWjsY1FxCYO3MJae0/sy7hIoC8CsqLZDE3ThuZ+3EalieCN8p/4sDyehquKWQ3nX87Y/iUsoV14lXlU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345326295376.07287167948675; Fri, 1 May 2020 08:02:06 -0700 (PDT) Received: from localhost ([::1]:35648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXAx-00005G-RN for importer@patchew.org; Fri, 01 May 2020 11:02:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34244) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7M-0004rv-1A for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6M-0007qX-7Q for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:19 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:40392) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6L-0007nv-Pl for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:17 -0400 Received: by mail-wm1-x343.google.com with SMTP id u16so6573200wmc.5 for ; Fri, 01 May 2020 07:57:17 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id s24sm4421887wmj.28.2020.05.01.07.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 41F371FF8C; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Rec4lCI7C2I9ftVXhw3jnhwwniJ/OyIiNlpjw4I33hQ=; b=QCBzWTKIZ6i1bqEUk+0sAgo+cfTpLNxKV3RzrG+1hwaJXmxcirgXUoE+RwsLgTHHgw jEKvHtZPIbyFLMXu2Wgdm5pAJPLvp8CuAS51BI4OWqcECJEI7ab50iriC5iBaM5IQVxi oLQvvaxh4xcNKgEhFUghRmSZUUkezF7Rfv9EK+4IujEWt8yFy93eY/EPvt5ZY8qrJpL5 A12BmGdnRoA/3xmzTwkb/NHWdpRPUnEbcF4UEky+cayhthHayWGraIYAhuW+eC1JBTqR rurZ5RW7VmXApbl/+KjnrrDnICO1FT0tge8XueNq95J0SKitSHZN8Rc3MgpYydikvdrf NX2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Rec4lCI7C2I9ftVXhw3jnhwwniJ/OyIiNlpjw4I33hQ=; b=XwaX8y6XWKsYQm+gQceT5qj/b2GYdL/4vuGlMZ0PufOhc/GkBjeTyam9fK19czEWsj LHTS9ONOxinQ5JjernsUiehWFNzFI9cQTAcSZlb4Dx8XVkGaxCQaSux1tEDsaPPAS3wx lzMryblT13h/G4suZ9PNm07tdqnGhLpG1Ji/Sp9CGizLA2JoBJpPGsOOKMhrVTLkjBgz JwKfF/lhX38jDbNv015ykFjl0tc4xGGJVLouHReDp073axGrA9x1q+xD/CdwMZFCUk6g LL+GTtltC7HY5tpnnKzaCtKBodN1ssXh8Aaj864TPbT+pPgqOFT7pqPeZ/e7n/1SnEHJ S1uA== X-Gm-Message-State: AGi0PuYNBzSZPqYKoGPpME9Py1hP0rcvSqqPNbA7GZrYjRa/dXUBR6De LK06cdTgY5V9EWXFhkzFRthkaQ== X-Google-Smtp-Source: APiQypKiOZjO2OZxQQ0eX+zopzygmB7gNx/d7cXGxg5GN6KkiOT5GXmEjaoOiunsl6k+tp2zZ3qDsw== X-Received: by 2002:a1c:2392:: with SMTP id j140mr4339640wmj.136.1588345036002; Fri, 01 May 2020 07:57:16 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 2/7] exec/cpu-all: Use bool for have_guest_base Date: Fri, 1 May 2020 15:57:07 +0100 Message-Id: <20200501145713.19822-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::343 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: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Richard Henderson Signed-off-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by's ;-) Acked-by: Laurent Vivier --- include/exec/cpu-all.h | 2 +- bsd-user/main.c | 4 ++-- linux-user/main.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 49384bb66a..b4fb5832c4 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -159,7 +159,7 @@ static inline void tswap64s(uint64_t *s) * This allows the guest address space to be offset to a convenient locati= on. */ extern unsigned long guest_base; -extern int have_guest_base; +extern bool have_guest_base; extern unsigned long reserved_va; =20 #if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS diff --git a/bsd-user/main.c b/bsd-user/main.c index 770c2b267a..aef5531628 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -42,7 +42,7 @@ int singlestep; unsigned long mmap_min_addr; unsigned long guest_base; -int have_guest_base; +bool have_guest_base; unsigned long reserved_va; =20 static const char *interp_prefix =3D CONFIG_QEMU_INTERP_PREFIX; @@ -828,7 +828,7 @@ int main(int argc, char **argv) } } else if (!strcmp(r, "B")) { guest_base =3D strtol(argv[optind++], NULL, 0); - have_guest_base =3D 1; + have_guest_base =3D true; } else if (!strcmp(r, "drop-ld-preload")) { (void) envlist_unsetenv(envlist, "LD_PRELOAD"); } else if (!strcmp(r, "bsd")) { diff --git a/linux-user/main.c b/linux-user/main.c index 1d20a83d4e..90ad365b43 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -59,7 +59,7 @@ static const char *cpu_type; static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; -int have_guest_base; +bool have_guest_base; =20 /* * Used to implement backwards-compatibility for the `-strace`, and @@ -334,7 +334,7 @@ static void handle_arg_cpu(const char *arg) static void handle_arg_guest_base(const char *arg) { guest_base =3D strtol(arg, NULL, 0); - have_guest_base =3D 1; + have_guest_base =3D true; } =20 static void handle_arg_reserved_va(const char *arg) --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345394; cv=none; d=zohomail.com; s=zohoarc; b=nxy//YSiAUr2KtJJoBVr+En7LFk1WfN94+pleniw8xXeqBYQL90fmmRis47FurnHDnPBrC4oSVwOcl3A6OhMoJGRZ6nVPchQF3/VRQOH/RJDvf1yqmDmSD9cXPjxexsN1Jmo37GYsJAzeWJTC/AvwDViWlfB+ZWMiw+gU3hEUZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345394; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MFeUu7n29OkmLx3VOPHwfUTxtnGWYTEH/6SkTF3jvtE=; b=KpzvZy8s4WtYUL7htXTksmZIx6BZDfZ/jBCMfxAf7p+R7HZZ3impQmzJf1KaOINEJFoCUDaImkKUd0o+6D+K3BcpGW38QSc/ax6A9HNaD9LjBE2Lu+RfDDsZK2c6BtiEW9zOSE8/1Qfv+pT4fR/wh17Tg2nJXs/8V6wPMFwAk8g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345394778967.6415277939349; Fri, 1 May 2020 08:03:14 -0700 (PDT) Received: from localhost ([::1]:38906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXC5-0001uY-05 for importer@patchew.org; Fri, 01 May 2020 11:03:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34294) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7P-0004sD-Gq for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6O-0007sQ-IN for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:23 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:36928) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6O-0007rI-3u for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:20 -0400 Received: by mail-wm1-x342.google.com with SMTP id z6so6589401wml.2 for ; Fri, 01 May 2020 07:57:19 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a24sm4205310wmb.24.2020.05.01.07.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5A1021FF8F; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MFeUu7n29OkmLx3VOPHwfUTxtnGWYTEH/6SkTF3jvtE=; b=G/8vJ+3680SoxtPPfHBr+2VaNajKx5Bxk43ljx5CodSAsrpf33L5CIbLadzh0hxOqk 5hOprQe3XmRQUNQr6sMTSWHQcF39Uve0k+217ibeFPUl0s3ytIknBjjL+Et4d9xFBhiJ SXlSoh28U4AVofe9rqAsokz8gsecWNd6JpS/Fp9rI/LsM+aSEe79SGFYf4P4gs6aqS2n AZRMD3kR9mojDaMe88Zjs7esB+/ToI5MhwfsqCp9mEsYC/3UTBDZ4LX0hBa72dEG4Hoy XMASd+zInYZbqLoIEZeZxpepxRpEqGLMvzy/ricP6DCV2X4iMUucWOXBHFUzi728fbQG KpjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MFeUu7n29OkmLx3VOPHwfUTxtnGWYTEH/6SkTF3jvtE=; b=IIVBbahRKiZ0QlV+3zbxWFqHs3HYrnwR6UHigC3kodg8LJLzxwqTZNDPQL4rQLjfv7 g3Ejr/Qz1CtrgBSK4oZhVrRUvahskeGrTSbKBOSayNCoeXp6awX/NgYO/d2l+01BpEmY Z963qORqelb3Voq52IVqKwqO6L4IheLOhNkG/n4paks1xzEcL/6B0/2o8tn9SM/VPZuV vZRB5iDAvnSSEksvlWPHAbG1Cb2a0jcB4167hkhcojPY4Jt3Y9w5Yqxy+YtnhgQKcEsq PtwUWpnj8AInXMCXgGuVbihautLrDWEo0FSgQ+eaTnhAvxqPJ/2V9sSGPm//XiPya4VZ ON+A== X-Gm-Message-State: AGi0PuaGG8JvOW2TnVaTI8Yu5gHs3jfwj4Z0iGj9fZX7czryQCzymppH 8J9etpeljFpju2CLop9dm357BhzPJg8= X-Google-Smtp-Source: APiQypI2qym2ogkk22IBIL14S395KWL3lJC1ZD/6kLpEwMG4qvspZ6EsSMNKpu0LSUCLlRZHAx9P0w== X-Received: by 2002:a1c:4186:: with SMTP id o128mr4335971wma.21.1588345038478; Fri, 01 May 2020 07:57:18 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 3/7] accel/tcg: Relax va restrictions on 64-bit guests Date: Fri, 1 May 2020 15:57:08 +0100 Message-Id: <20200501145713.19822-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::342 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: , Cc: riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Richard Henderson We cannot at present limit a 64-bit guest to a virtual address space smaller than the host. It will mostly work to ignore this limitation, except if the guest uses high bits of the address space for tags. But it will certainly work better, as presently we can wind up failing to allocate the guest stack. Widen our user-only page tree to the host or abi pointer width. Remove the workaround for this problem from target/alpha. Always validate guest addresses vs reserved_va, as there we control allocation ourselves. Signed-off-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier --- vN - shutup checkpatch on ~0ul --- include/exec/cpu-all.h | 23 +++++++++++++++++++---- target/alpha/cpu-param.h | 15 ++------------- accel/tcg/translate-all.c | 15 +++++++++------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index b4fb5832c4..9598564f2a 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -162,12 +162,27 @@ extern unsigned long guest_base; extern bool have_guest_base; extern unsigned long reserved_va; =20 -#if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS -#define GUEST_ADDR_MAX (~0ul) +/* + * Limit the guest addresses as best we can. + * + * When not using -R reserved_va, we cannot really limit the guest + * to less address space than the host. For 32-bit guests, this + * acts as a sanity check that we're not giving the guest an address + * that it cannot even represent. For 64-bit guests... the address + * might not be what the real kernel would give, but it is at least + * representable in the guest. + * + * TODO: Improve address allocation to avoid this problem, and to + * avoid setting bits at the top of guest addresses that might need + * to be used for tags. + */ +#if MIN(TARGET_VIRT_ADDR_SPACE_BITS, TARGET_ABI_BITS) <=3D 32 +# define GUEST_ADDR_MAX_ UINT32_MAX #else -#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \ - (1ul << TARGET_VIRT_ADDR_SPACE_BITS) -= 1) +# define GUEST_ADDR_MAX_ (~0ul) #endif +#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : GUEST_ADDR_MAX_) + #else =20 #include "exec/hwaddr.h" diff --git a/target/alpha/cpu-param.h b/target/alpha/cpu-param.h index 692aee27ca..1153992e42 100644 --- a/target/alpha/cpu-param.h +++ b/target/alpha/cpu-param.h @@ -10,22 +10,11 @@ =20 #define TARGET_LONG_BITS 64 #define TARGET_PAGE_BITS 13 -#ifdef CONFIG_USER_ONLY -/* - * ??? The kernel likes to give addresses in high memory. If the host has - * more virtual address space than the guest, this can lead to impossible - * allocations. Honor the long-standing assumption that only kernel addrs - * are negative, but otherwise allow allocations anywhere. This could lead - * to tricky emulation problems for programs doing tagged addressing, but - * that's far fewer than encounter the impossible allocation problem. - */ -#define TARGET_PHYS_ADDR_SPACE_BITS 63 -#define TARGET_VIRT_ADDR_SPACE_BITS 63 -#else + /* ??? EV4 has 34 phys addr bits, EV5 has 40, EV6 has 44. */ #define TARGET_PHYS_ADDR_SPACE_BITS 44 #define TARGET_VIRT_ADDR_SPACE_BITS (30 + TARGET_PAGE_BITS) -#endif + #define NB_MMU_MODES 3 =20 #endif diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 9924e66d1f..e4f703a7e6 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -173,8 +173,13 @@ struct page_collection { #define TB_FOR_EACH_JMP(head_tb, tb, n) \ TB_FOR_EACH_TAGGED((head_tb)->jmp_list_head, tb, n, jmp_list_next) =20 -/* In system mode we want L1_MAP to be based on ram offsets, - while in user mode we want it to be based on virtual addresses. */ +/* + * In system mode we want L1_MAP to be based on ram offsets, + * while in user mode we want it to be based on virtual addresses. + * + * TODO: For user mode, see the caveat re host vs guest virtual + * address spaces near GUEST_ADDR_MAX. + */ #if !defined(CONFIG_USER_ONLY) #if HOST_LONG_BITS < TARGET_PHYS_ADDR_SPACE_BITS # define L1_MAP_ADDR_SPACE_BITS HOST_LONG_BITS @@ -182,7 +187,7 @@ struct page_collection { # define L1_MAP_ADDR_SPACE_BITS TARGET_PHYS_ADDR_SPACE_BITS #endif #else -# define L1_MAP_ADDR_SPACE_BITS TARGET_VIRT_ADDR_SPACE_BITS +# define L1_MAP_ADDR_SPACE_BITS MIN(HOST_LONG_BITS, TARGET_ABI_BITS) #endif =20 /* Size of the L2 (and L3, etc) page tables. */ @@ -2497,9 +2502,7 @@ void page_set_flags(target_ulong start, target_ulong = end, int flags) /* This function should never be called with addresses outside the guest address space. If this assert fires, it probably indicates a missing call to h2g_valid. */ -#if TARGET_ABI_BITS > L1_MAP_ADDR_SPACE_BITS - assert(end <=3D ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)); -#endif + assert(end - 1 <=3D GUEST_ADDR_MAX); assert(start < end); assert_memory_lock(); =20 --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345476; cv=none; d=zohomail.com; s=zohoarc; b=Uow+JhXkgeOXBuFEg4/EAWphKTqOZmszv58h8P/D90RZELDQMBT2NuFDYGkuUNKxPw3tFWAPik0N7FnornOq5+bcZCriQvSPXMN50WPvpZ3cQzD1felzfp3pN8xppRumtDytHxLHEJIF/8uo+Xd1ei158SM1XpjOBwm8uigylxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345476; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YNX+/fnT88Z/wFzIjWWLDF8jEJXh9RNje7+wEwFPi9I=; b=ctsLti9Y+kFqJ05aGXGnD4Q2QBOsHP4TyZ0rMk3pC0oO5V+oTPqizd3TG5H0zH5W28XZMsepUSpJqLVNmB2J8C9j8DuH04Y6Ia0VrlxLaOoSXYtOpCTrQgq0PwN0mx9ijCRwhvgJMxOl3m7wsWIMemmA/yVlnouHw9IUmwNxW60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345476737287.5417558386007; Fri, 1 May 2020 08:04:36 -0700 (PDT) Received: from localhost ([::1]:42164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXDO-0005uv-Tp for importer@patchew.org; Fri, 01 May 2020 11:04:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34260) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7N-0004s2-6m for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6P-0007sc-Dv for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:21 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:50335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6P-0007rq-1C for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:21 -0400 Received: by mail-wm1-x341.google.com with SMTP id x25so6196790wmc.0 for ; Fri, 01 May 2020 07:57:20 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z16sm5103214wrl.0.2020.05.01.07.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6DCF61FF90; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YNX+/fnT88Z/wFzIjWWLDF8jEJXh9RNje7+wEwFPi9I=; b=Q3iTwHzAY60My2NsA7gGW+zj0hgk2I9AFDcg02zXyCWclGkvZ0/5P4uqtJb23g2NNs wWd2sfB3C2K6ccvAkc6WhsrJhgoHdTozpmjrwN0/i5oO6gswCpAdoptaX+xga8Hw3xy7 lJ2t2RJNGr4vTsRxyisRkaQcREPdHGaP4UNKhzAgjoWvQzIljC2g1goJM7b9tOZrtMQ1 +jB+u0qVzI5RHLWBAnnZXgLXMBqQ+btiEsepTEucnH802klgEmuk2tfI9uz7osr4LUev Qbo38bW60zh2uIjDhKP0YAX3jgfaeADNcWgGcEGow5Vkm4eYl7p0zRqXpjqX8mby6S/F EVBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YNX+/fnT88Z/wFzIjWWLDF8jEJXh9RNje7+wEwFPi9I=; b=gq3xzDE3l034DrXp8J5tC9p/6BdlomhAPsyiVjvksQisU4YoqvWABLKqzXMVLWza8n mbOgBq+jwHnxVQHwm6nsNBKXgVLDnLSDfiP/iwRUUWaRzynCGk7mneL8JqrCVu3mq9eF 6pyYun73cE5efN0AVo4VbU6fiqzswpNEgZyv4Z8lVG7tl5To8q+vjCoAPLQQAnBGYa+t uPJ1ioNqSgUGmZWB/CUrMrFGagjGGAWYLpJ2jRDiz8kxG4lHxKWcu9YcTNumIF3xDX69 gzhgdYbOJ59p22utgnDkrXbIohwsD8iOKGLBKilHu2/GLozS1i6SQx42xo4Q/Qnk89TP BncQ== X-Gm-Message-State: AGi0Pua4OsdAVa6MGqI3zpenb49o/AK2nDS2qGuLRO5Mm60j5F+r85gW ZKeT0udTDCl52E7fxLOh589uvM+bOyY= X-Google-Smtp-Source: APiQypK426Gb29HWddBA1GkB7fDbydTvEX/jkzHGGih6hNZdyDZotRlEsEwMXFY4Ur2bDpYDXXrdzA== X-Received: by 2002:a1c:80c3:: with SMTP id b186mr4731563wmd.117.1588345039647; Fri, 01 May 2020 07:57:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 4/7] accel/tcg: don't disable exec_tb trace events Date: Fri, 1 May 2020 15:57:09 +0100 Message-Id: <20200501145713.19822-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::341 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: , Cc: riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) I doubt the well predicted trace event check is particularly special in the grand context of TCG code execution. Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- accel/tcg/trace-events | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/accel/tcg/trace-events b/accel/tcg/trace-events index 01852217a6..385b9f749b 100644 --- a/accel/tcg/trace-events +++ b/accel/tcg/trace-events @@ -1,10 +1,10 @@ # See docs/devel/tracing.txt for syntax documentation. =20 -# TCG related tracing (mostly disabled by default) +# TCG related tracing # cpu-exec.c -disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=3D0x%"PRIxPTR -disable exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=3D0x%"PRIxPTR -disable exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=3D0x%= x" +exec_tb(void *tb, uintptr_t pc) "tb:%p pc=3D0x%"PRIxPTR +exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=3D0x%"PRIxPTR +exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=3D0x%x" =20 # translate-all.c translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"P= RIxPTR", tb_code:%p" --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345329; cv=none; d=zohomail.com; s=zohoarc; b=UqUdSb+9WkmgR7jEFlldwC9KAIi/cVRqEb151jt1hKAwvwlbp/MOtkp/dH6bNv0u+H2/sz3wn5iGDqdgHn8bKOHZWkPSU0OYq/5aUWSMoGYxgK8Jy2r8SKKFG1iFDqbFwLbsTQFN5kmTdGnp7Axz0EHWjMJ3u157yFhm4pY1ijU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345329; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=avj+urXq7iXuKPR7WdlISyEaRr0xyzjqnDBQFi5kr/A=; b=T4QoZY7jh+YhMjqBf7Omy3R+CsNXOPqHwymtBIkvfhzwjBvMztbSpyjXnSFl0OFgf+HQWHNEsAs2q8NMh/QVKwX0Lw8I9S9uS7Qgk9EckPprsGsY57q4Of5vH5gZ1SucNicsF0xeVGMtdjhoZOaM1AGVL3xIjepdcd79jyj5BKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345329483279.3571026512824; Fri, 1 May 2020 08:02:09 -0700 (PDT) Received: from localhost ([::1]:35794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXB1-000098-Ib for importer@patchew.org; Fri, 01 May 2020 11:02:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34286) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7O-0004sA-Qe for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6R-0007uo-B8 for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:22 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35963) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6Q-0007t6-TT for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:22 -0400 Received: by mail-wr1-x443.google.com with SMTP id d15so11819924wrx.3 for ; Fri, 01 May 2020 07:57:22 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id p16sm4515094wro.21.2020.05.01.07.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:19 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8A0FD1FF91; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=avj+urXq7iXuKPR7WdlISyEaRr0xyzjqnDBQFi5kr/A=; b=eEb6ItxXFXgxkidL4QFHPp6ifbbdrypqpVe6SuPj8qz8pNjIFbAIZbjwMcjpkt0biS dHb7LFcf5vQpXR6q31ZnZYgVPh6W9S/oABThXS3qFHuEq7qVuSX5ylRC9qGJgzHwbTZd tebDjQgx3eFY+swhhpUUdsgc52jBSFrJyYnfa7hpHf1ClMge5vJlnGL+XdxPjP4CPF2H Q0dUFUqF3PB6Zksb3Cg2oFeTESEJ3alK5XOGdgfvY8Q0vz7LJAoT7zlIutvwX3klWnTy Xv9wzQ0dSGgtL85ED8i7haF7ZLtoh6YvZMLnKyqf8LuzhpMiMguABVcUwkbXW0h3uN0q Boww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=avj+urXq7iXuKPR7WdlISyEaRr0xyzjqnDBQFi5kr/A=; b=n7pipj2SIbyNozzE1pmAz9cYgvnXxPEmAfSk8la04Df5rN36R3IXM+j/C0ONtpPqRg cB4R2ueV5bZR5diAvr43LPdrSSS/9VCNh78nWbcTJlNX45idcqC1Y1XVz3qvTlS5BbpW NdbKmVfQJXXnUQamSYhDXPpWL0Fwak69iZDMaYCH7tTdhWLKHLTHzaA20lJSJ80rauZC 2ZD0i3irOAm4JXK2D7fpn0d1iPK+jInoNCsR0aOPVrp8bQgMI2PgtJnUv4edf5OUSiwl 2zZN9Z0yYMboMTnAe8OoVMYjlZqe9Hr7BSXAuWnJHfmfI2JSyun4Ygt/1iO6hosvZey3 ZCLg== X-Gm-Message-State: AGi0PuaagQFHVAzt01anMgggHjjz33JuJ+2ZzXvfZonP1s0yyIhImXs2 mVK7aw6E/SfQAQj5RqqVoA2oIA== X-Google-Smtp-Source: APiQypJ17Ki4TllVDu4Z5jBrLHDl4v4fB5UAhlTkhMlubS3AJs/scMxHjx5ncwUu+QaTudaMuuVBuA== X-Received: by 2002:a5d:498d:: with SMTP id r13mr4784588wrq.374.1588345041441; Fri, 01 May 2020 07:57:21 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 5/7] disas: include an optional note for the start of disassembly Date: Fri, 1 May 2020 15:57:10 +0100 Message-Id: <20200501145713.19822-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::443 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: , Cc: riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This will become useful shortly for providing more information about output assembly inline. While there fix up the indenting and code formatting in disas(). Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/disas/disas.h | 2 +- include/exec/log.h | 4 ++-- accel/tcg/translate-all.c | 4 ++-- disas.c | 15 +++++++++++---- tcg/tcg.c | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/include/disas/disas.h b/include/disas/disas.h index 36c33f6f19..1b6e035e32 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -7,7 +7,7 @@ #include "cpu.h" =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size); +void disas(FILE *out, void *code, unsigned long size, const char *note); void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size); =20 diff --git a/include/exec/log.h b/include/exec/log.h index fcc7b9e00b..3ed797c1c8 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, targ= et_ulong start, rcu_read_unlock(); } =20 -static inline void log_disas(void *code, unsigned long size) +static inline void log_disas(void *code, unsigned long size, const char *n= ote) { QemuLogFile *logfile; rcu_read_lock(); logfile =3D atomic_rcu_read(&qemu_logfile); if (logfile) { - disas(logfile->fd, code, size); + disas(logfile->fd, code, size, note); } rcu_read_unlock(); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index e4f703a7e6..cdf58bb420 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1800,7 +1800,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, size_t data_size =3D gen_code_size - code_size; size_t i; =20 - log_disas(tb->tc.ptr, code_size); + log_disas(tb->tc.ptr, code_size, NULL); =20 for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { @@ -1814,7 +1814,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } } } else { - log_disas(tb->tc.ptr, gen_code_size); + log_disas(tb->tc.ptr, gen_code_size, NULL); } qemu_log("\n"); qemu_log_flush(); diff --git a/disas.c b/disas.c index 3937da6157..bb74650633 100644 --- a/disas.c +++ b/disas.c @@ -586,7 +586,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t= size) } =20 /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size) +void disas(FILE *out, void *code, unsigned long size, const char *note) { uintptr_t pc; int count; @@ -674,10 +674,17 @@ void disas(FILE *out, void *code, unsigned long size) for (pc =3D (uintptr_t)code; size > 0; pc +=3D count, size -=3D count)= { fprintf(out, "0x%08" PRIxPTR ": ", pc); count =3D print_insn(pc, &s.info); - fprintf(out, "\n"); - if (count < 0) - break; + if (note) { + fprintf(out, "\t\t%s\n", note); + note =3D NULL; + } else { + fprintf(out, "\n"); + } + if (count < 0) { + break; + } } + } =20 /* Look up symbol for debugging purpose. Returns "" if unknown. */ diff --git a/tcg/tcg.c b/tcg/tcg.c index dd4b3d7684..a2268d9db0 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1092,7 +1092,7 @@ void tcg_prologue_init(TCGContext *s) size_t data_size =3D prologue_size - code_size; size_t i; =20 - log_disas(buf0, code_size); + log_disas(buf0, code_size, NULL); =20 for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { @@ -1106,7 +1106,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size); + log_disas(buf0, prologue_size, NULL); } qemu_log("\n"); qemu_log_flush(); --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345592; cv=none; d=zohomail.com; s=zohoarc; b=kzWjHKGkhA5dRAfTuhdVCA81rZE3BJn3veutLzw2MWJgiuvmTOXi8f359eqtl/DaEo68Znr+S2ebih5GzxD7ij/1W1fFT8MCHc3Wks7ICSa6NTuZ38sWDyC48rXDVeS/ns4em/FCFvTbqLC47kVHjBHOPUHvfbptUCzjLtw0TYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345592; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IZSa8c21TyIpcw6MDYTFEpVBqr4T0wU6Ux/08+8c4yw=; b=YDWJ45CPpnNoSWA+TjFNUI/WdwcWppGCWaxCuD5zMIfvdSsh0RunDkOA33Wc3VBMZmxX1h/MzeGgVtlX39BPAeCu7v/B5CBiCIFRj3mFM/e2Lzxq+H1Z8JMHy92jWE8cfq4y5gOyS/kaXGzJN/0Cy4qa8txRFGtltBr4Dtat6pU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 158834559226719.48692378961607; Fri, 1 May 2020 08:06:32 -0700 (PDT) Received: from localhost ([::1]:48590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXFG-0001Iq-Qf for importer@patchew.org; Fri, 01 May 2020 11:06:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34316) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7S-0004sq-3i for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6S-0007xs-44 for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:25 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:52751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6R-0007tp-MT for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:23 -0400 Received: by mail-wm1-x344.google.com with SMTP id 188so6182653wmc.2 for ; Fri, 01 May 2020 07:57:23 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y11sm3292013wrh.59.2020.05.01.07.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:19 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A0E601FF92; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IZSa8c21TyIpcw6MDYTFEpVBqr4T0wU6Ux/08+8c4yw=; b=KsLLRDEki8wSguaUNhQfiOuCez9rFT1AcVtzsBPV8dTSLQbfaazbi+zHmxjoiUb4lv pI41gvWlfAykTYQLfBjEigwa9yCOX1LZk74pzA4J6Y+PsoX7tg1DuNgoy/Tw0C9WL2SI lKHNOxh5BE8yr3/VbzmlqsYk8pQDQc5FuGRZdiuuKTv2jAMgG76ihPZkUfsyJ7uyk0d/ T8TudtYvE191+PDU557qIR+vuN5buB18Tp6q/HWxVwrElAahS+rFYcS+k4nLrGAdTkqw h+YqeDy8bdpbrYVEZKw3nQ+MPJJEM4EqHGGybLLpEQfBDKz1KezxP922fJ69yP2/19Jc tCJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IZSa8c21TyIpcw6MDYTFEpVBqr4T0wU6Ux/08+8c4yw=; b=UieHzy4H/xoHsxNA9GMp4RqNaHEV5M5GKrYyYsam2gyDcl+wDbY6kyGqgVnBC4Exkd 6lBA0QjzbV3taiQdTsoP/buHqH4pGchdheOaMQ4CkhgSjQJKRQb5Kd9QIrnmq9HMo7xR 0sgYtGTHKH8kBIihNj6P3JUUlMM7qGnFc3lkEuKw/4zZAFz3h2Lersq0CZ516Ojq+At/ tnd6mw/IeBfSTQ6U+j4lscGIJgZqRS3Y+RaSGiTapZv1DR2M9m9JZH3Rkyo58SPcMmgb B5ax/QQVulP9E1dxCk8rdUyIskGJSWHdfqpTqvbBbnBfCPi+4gWBKfr1eJx+TdrRbEWX WVww== X-Gm-Message-State: AGi0Pub3oYFcb3YAjTL1hlGtCdRfYyfxaCATpSmemofNo+aZwlUSC6G+ PM4whzOMd7V1WcZtMGBrwjIO5w== X-Google-Smtp-Source: APiQypJhvV1M/4Wx7pa4RoU2HoqvM/DZhlUb21hrphI8btuIkxZx9Q0xAKzfhtWnbFISPz8uhtMg0g== X-Received: by 2002:a1c:3b09:: with SMTP id i9mr4303423wma.19.1588345042237; Fri, 01 May 2020 07:57:22 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 6/7] disas: add optional note support to cap_disas Date: Fri, 1 May 2020 15:57:11 +0100 Message-Id: <20200501145713.19822-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::344 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: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Include support for outputting a note at the top of a chunk of disassembly to capstone as well. Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- disas.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/disas.c b/disas.c index bb74650633..5e7eb65326 100644 --- a/disas.c +++ b/disas.c @@ -260,7 +260,8 @@ static void cap_dump_insn_units(disassemble_info *info,= cs_insn *insn, } } =20 -static void cap_dump_insn(disassemble_info *info, cs_insn *insn) +static void cap_dump_insn(disassemble_info *info, cs_insn *insn, + const char *note) { fprintf_function print =3D info->fprintf_func; int i, n, split; @@ -281,7 +282,8 @@ static void cap_dump_insn(disassemble_info *info, cs_in= sn *insn) } =20 /* Print the actual instruction. */ - print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); + print(info->stream, " %-8s %s\t\t%s\n", insn->mnemonic, insn->op_str, + note ? note : ""); =20 /* Dump any remaining part of the insn on subsequent lines. */ for (i =3D split; i < n; i +=3D split) { @@ -313,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) size -=3D tsize; =20 while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, NULL); } =20 /* If the target memory is not consumed, go back for more... */ @@ -342,7 +344,8 @@ static bool cap_disas_target(disassemble_info *info, ui= nt64_t pc, size_t size) } =20 /* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size) +static bool cap_disas_host(disassemble_info *info, void *code, size_t size, + const char *note) { csh handle; const uint8_t *cbuf; @@ -358,7 +361,8 @@ static bool cap_disas_host(disassemble_info *info, void= *code, size_t size) pc =3D (uintptr_t)code; =20 while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, note ? note : NULL); + note =3D NULL; } if (size !=3D 0) { (*info->fprintf_func)(info->stream, @@ -402,7 +406,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) csize +=3D tsize; =20 if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn); + cap_dump_insn(info, insn, NULL); if (--count <=3D 0) { break; } @@ -416,7 +420,7 @@ static bool cap_disas_monitor(disassemble_info *info, u= int64_t pc, int count) #endif /* !CONFIG_USER_ONLY */ #else # define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s) false +# define cap_disas_host(i, p, s, n) false # define cap_disas_monitor(i, p, c) false # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ @@ -664,7 +668,7 @@ void disas(FILE *out, void *code, unsigned long size, c= onst char *note) print_insn =3D print_insn_hppa; #endif =20 - if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size)) { + if (s.info.cap_arch >=3D 0 && cap_disas_host(&s.info, code, size, note= )) { return; } =20 --=20 2.20.1 From nobody Sat May 18 12:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1588345538; cv=none; d=zohomail.com; s=zohoarc; b=PICtR+ffdeIrsJcCWnd7rgjGbrGkOFJovyv4d8RCnBsG0Xnyj6BuWKAeMEhZpAl/8pwz09QXlh3MwJYGowpwfPt+lxsbnHeg8CBCesICbTCp3LNYNHPVDYY5XQtl36cb8apHPZYjoWPETz/bK+lWCDSMPRXhxtvIphvpJn+kd6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588345538; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xecdaPhT+t7HsLMZz6EaOAdCJ68I6JHyMXHYh9SkvvA=; b=R8ejGHNukT/We6Ddhq0AB8/aX5Mmqqhj2TGjzbwkIXIDs7eGW1vVj8gN+yP/pmVPF/M5/TUywNxTzmeQDVQwJTIasidWHaaSU3ax4oZypfA86gAMJtQDAHkgygaktvFnPG6RB5MdCg8F0yhfuT2EtrFdq/mlIM+i8EFULcSihf0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none 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 1588345538349449.6571739166701; Fri, 1 May 2020 08:05:38 -0700 (PDT) Received: from localhost ([::1]:45742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUXEP-00089L-1g for importer@patchew.org; Fri, 01 May 2020 11:05:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34308) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jUX7R-0004sX-2N for qemu-devel@nongnu.org; Fri, 01 May 2020 10:59:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jUX6T-00080k-7R for qemu-devel@nongnu.org; Fri, 01 May 2020 10:58:24 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jUX6S-0007xh-Pd for qemu-devel@nongnu.org; Fri, 01 May 2020 10:57:24 -0400 Received: by mail-wm1-x343.google.com with SMTP id k12so6174599wmj.3 for ; Fri, 01 May 2020 07:57:24 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id c83sm4754381wmd.23.2020.05.01.07.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2020 07:57:19 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B98861FF93; Fri, 1 May 2020 15:57:13 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xecdaPhT+t7HsLMZz6EaOAdCJ68I6JHyMXHYh9SkvvA=; b=hfv0ZDP2pF0XXZdGhYatVBkMJgP0DtiFYkVi9IJniep4+Dijp3KvYNX5lr/Ia8aWrk eKxSc8rjuZkHzDhjSm1GVoFsXRmLtiaVz1+AKs8cQZHVBkjkmmuZ0Knp6U1a9szlUNyQ gxqhbITutMbBK6K75nQvv6knF6Q4yX3t7TwyDXT6au4j+lqBqqhty30rmhJQfCXIXGH0 0InTgE9r8aKBy3D5lW/+kRSwXv99WVfEUbKAJl6QXPYbKLsYSU+/rK2Grn7yefPeoiZ/ LYaWpcM8ORpbHvftXyI29IJNoAFG7zvQ9hvzHykoIoYa32/BbasEtNB6m1nDp/jeJzJw Tk2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xecdaPhT+t7HsLMZz6EaOAdCJ68I6JHyMXHYh9SkvvA=; b=psGtl2U6IagTFwB+OR73RxkmXIcWsTY2jII4OPyJfPbztG+pMc+mIBb0lyrCdmJKLx ZfHxRXiPVx1xspjCeFTIdut3XSMdodIygrrs62xUt8AWuFmIrI+SaT2kURhj/xDVbAjc l/rlILjpfDo6C5IA0q+auB5WInkf8xD2F9gX4FGWIb7+h2sNqnkAQkB1RSo1ryP5KNlh /uaLpe3FyY1UKwZtPOdxdw6nynJKqyYzcTxxPGfBiW1mWjRwQto7PeB0JEpIPJGADFRc wvK/zGSRqkqCgwoTxKI149QMYTs5TdIi20HW+vtS1ZahhjBUmrlOFyJLre5N0c9zkq1Z IOqw== X-Gm-Message-State: AGi0PuaB4mQI3eFXFoetBrlh6xSb7oPoprONT1rq0l4jk9+u9hqIrhr6 CWXlRKae6xq1wIdWJcobTIZYgg== X-Google-Smtp-Source: APiQypImY+Ih3VJovnPBgOV0U8w2d4nKmnjyFDcp+0s1G2bSWO/cV2k8SJFFRWr+fj/HdjAiadPgDA== X-Received: by 2002:a05:600c:2112:: with SMTP id u18mr4592318wml.112.1588345043419; Fri, 01 May 2020 07:57:23 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 7/7] translate-all: include guest address in out_asm output Date: Fri, 1 May 2020 15:57:12 +0100 Message-Id: <20200501145713.19822-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200501145713.19822-1-alex.bennee@linaro.org> References: <20200501145713.19822-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a00:1450:4864:20::343 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: , Cc: riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We already have information about where each guest instructions representation starts stored in the tcg_ctx->gen_insn_data so we can rectify the PC for faults. We can re-use this information to annotate the out_asm output with guest instruction address which makes it a bit easier to work out where you are especially with longer blocks. A minor wrinkle is that some instructions get optimised away so we have to scan forward until we find some actual generated code. Signed-off-by: Alex Benn=C3=A9e Acked-by's ;-) Acked-by: Laurent Vivier --- v1 - better logic for doing chunk at a time - use new "note" facility to tag address - rewrite the commit log --- accel/tcg/translate-all.c | 40 +++++++++++++++++++++++++++++++++------ tcg/tcg.c | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index cdf58bb420..92940ae9e3 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1794,14 +1794,44 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && qemu_log_in_addr_range(tb->pc)) { FILE *logfile =3D qemu_log_lock(); + int code_size, data_size =3D 0; + g_autoptr(GString) note =3D g_string_new("[tb header & initial ins= truction]"); + size_t chunk_start =3D 0; + int insn =3D 0; qemu_log("OUT: [size=3D%d]\n", gen_code_size); if (tcg_ctx->data_gen_ptr) { - size_t code_size =3D tcg_ctx->data_gen_ptr - tb->tc.ptr; - size_t data_size =3D gen_code_size - code_size; - size_t i; + code_size =3D tcg_ctx->data_gen_ptr - tb->tc.ptr; + data_size =3D gen_code_size - code_size; + } else { + code_size =3D gen_code_size; + } =20 - log_disas(tb->tc.ptr, code_size, NULL); + /* Dump header and the first instruction */ + chunk_start =3D tcg_ctx->gen_insn_end_off[insn]; + log_disas(tb->tc.ptr, chunk_start, note->str); =20 + /* + * Dump each instruction chunk, wrapping up empty chunks into + * the next instruction. The whole array is offset so the + * first entry is the beginning of the 2nd instruction. The + * last offset is zeroed and indicates the remaining code. + */ + while (insn <=3D tb->icount && chunk_start < code_size) { + size_t chunk_end =3D tcg_ctx->gen_insn_end_off[insn]; + if (chunk_end > chunk_start) { + g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]", + tcg_ctx->gen_insn_data[insn][0]); + log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_star= t, + note->str); + chunk_start =3D chunk_end; + } + insn++; + } + + /* Finally dump any data we may have after the block */ + if (data_size) { + int i; + qemu_log(" data: [size=3D%d]\n", data_size); for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) =3D=3D 8) { qemu_log("0x%08" PRIxPTR ": .quad 0x%016" PRIx64 "\n= ", @@ -1813,8 +1843,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, *(uint32_t *)(tcg_ctx->data_gen_ptr + i)); } } - } else { - log_disas(tb->tc.ptr, gen_code_size, NULL); } qemu_log("\n"); qemu_log_flush(); diff --git a/tcg/tcg.c b/tcg/tcg.c index a2268d9db0..f5e4529df2 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -4211,6 +4211,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } tcg_debug_assert(num_insns >=3D 0); s->gen_insn_end_off[num_insns] =3D tcg_current_code_size(s); + s->gen_insn_end_off[num_insns + 1] =3D 0; =20 /* Generate TB finalization at the end of block */ #ifdef TCG_TARGET_NEED_LDST_LABELS --=20 2.20.1