From patchwork Wed Apr 1 09:47:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=LVtRNlmk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shGX13CKz9sR4 for ; Wed, 1 Apr 2020 20:48:34 +1100 (AEDT) Received: from localhost ([::1]:57138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZz5-0004BY-6C for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:48:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38387) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyf-0004BJ-BF for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZye-000296-Ep for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:05 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:45978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZye-00028a-9G for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:04 -0400 Received: by mail-wr1-x444.google.com with SMTP id t7so29716404wrw.12 for ; Wed, 01 Apr 2020 02:48:04 -0700 (PDT) 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=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=LVtRNlmkf0SEwI6n3XILfZ5dEar6Zo/Wcgi6qnaCoi1I15MiGFbqSvCHsrv9PS3i1o ZMiAD67aotCYrzK/mZo5ttz70YvCuuDsocbEYl8SaXnBiDacY4z1kIdbGfhJF2Oud3U/ bNDIBt+ThGflldG5q3jWmGwCUq87h2Fg3D3wtQtE2RQdNfCPFSMcSXQkJulzKRT51EZu 31JXdpj+q/zsaPQbi1wlJOzgtB5hRwAdwaCf4ml64J0VSeTS8ARVn7qqrz5txk8zcPx6 1WW0NLaBO55JlFCDwJzC0C56/qfyc49QPJ+E65a3cXu8xA5TuaEj7KniqwPuxZuCoIt+ cFZQ== 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=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=Ct8B7oAoujH9cFYFZdan5M8QYLOVhX6/xaEE1expbTL7xEOHGY3R775T1nXDY8cutE HzzffU2TEuxhSOVYXvN6dtw/fbbCdPiwF0x25Hbh772DIEDMAWkA87POjf+Wc6WEpluN qGshfYffhTsP3gHdbEH5GrX/JDeLDTaP3MxWSbwZWtCh4kCND9lx/UFUgj4HzEXGskt6 +dH+XgoPtrLK1aLvQWXdmLjAdM+7JrynCCoiYMf3vxy8mPkOz6CKuLDGShHDyqMac+84 tioFYHBnGrj9jTQ9Uk/BdI+q0b4gCSGULso6+Lj//78M1f69n+L5KecvFzuePLaNBwUM M6Bw== X-Gm-Message-State: ANhLgQ3MrymAgA8LVTrmdbKZWeZkZ5/DEOlLhqZ2QksHMW25gA5oarvG fPCLUUqZo+novFi9resu+whQyg== X-Google-Smtp-Source: ADFU+vsr7EyfLQyeJzCaT+WrNl2x1XNaklo5gCYZfKRAM9VLGJbhHttSoMl3sjscGKELvUyjEgtMcw== X-Received: by 2002:adf:b6a5:: with SMTP id j37mr25065764wre.412.1585734483166; Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 9sm1926646wmm.6.2020.04.01.02.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:00 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E86F91FF87; Wed, 1 Apr 2020 10:47:59 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] elf-ops: bail out if we have no function symbols Date: Wed, 1 Apr 2020 10:47:50 +0100 Message-Id: <20200401094759.5835-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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_Mathieu-Daud=C3=A9?= , Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It's perfectly possible to have no function symbols in your elf file and if we do the undefined behaviour sanitizer rightly complains about us passing NULL to qsort. Check nsyms before we go ahead. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/elf_ops.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h index a1411bfcab6..b5d4074d1e3 100644 --- a/include/hw/elf_ops.h +++ b/include/hw/elf_ops.h @@ -170,8 +170,13 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab, } i++; } - syms = g_realloc(syms, nsyms * sizeof(*syms)); + /* check we have symbols left */ + if (nsyms == 0) { + goto fail; + } + + syms = g_realloc(syms, nsyms * sizeof(*syms)); qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ)); for (i = 0; i < nsyms - 1; i++) { if (syms[i].st_size == 0) { From patchwork Wed Apr 1 09:47:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=j6sWA4nN; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shJJ1RMxz9sR4 for ; Wed, 1 Apr 2020 20:50:08 +1100 (AEDT) Received: from localhost ([::1]:57244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0c-0007fn-5B for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:50:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38417) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyi-0004CN-44 for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyh-0002AM-3i for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:08 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:34010) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyg-0002A2-UH for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:07 -0400 Received: by mail-wm1-x344.google.com with SMTP id c195so3074429wme.1 for ; Wed, 01 Apr 2020 02:48:06 -0700 (PDT) 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=9yYReGEoMkqsfZWblGMzvHlMGSzTNisl1Y211B1bnEY=; b=j6sWA4nNgPVM/bSVLmGG5O2gtvhTYDfqDA0C+LlOVSrqp8t0byDDQil33CI2GOmg3v gl06TrqhRxBn/nILqnTdipdP7NWc5BzoeItytGHxKtELRAjpJQNtZbtSxLIWSpekNDR/ FUAz6QvFFfRCp8UnZ7UQoPcpaEHk6iUd0Em+9myNf1di+K+K9vvnUtulILGHsmxKFi4Y lpWRAoUBVVBoGrKJ65200K/F8jrxUIrycZ9w3XiZQgwkRt762UmKOFNpnU/IoYI5xVVk XqQvdDxn5YY0lWGsbOWdavw/xIAIn5EPv4W5Eqm9TCLXxB+Bjp87wTcHLXl2it+HxKDI pRcg== 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=9yYReGEoMkqsfZWblGMzvHlMGSzTNisl1Y211B1bnEY=; b=rP00t/HiNvOl00J3ZT90lO9bEk017LmezGww0lFzUWq+ZMOYIqq/g3DUPVHeedi9zy lrDWEMWhrHFI2trnUAhoti/koIoD3y66C9cP11JUyLj3anZC9HfH6b1kzIBeIkzziadE 1SYcyxFLvLfzfmMkf2isd5OacNFPD4n88+ObHrRprPIxN2y5aCgA4hvUWfyBCMWj3TKI mNClm48toxfSJOjw/lNmznit4SZ1O08I0WQGLdeub2Ydd9mGTgW39MZZUJX59J3MVUAy 1L99PlH9PGGD7NtonmFqs4Vr9I96OJ4edA4hN91EIZQyxw/XkXEw9/y1h9JP5niMczIX 6IJQ== X-Gm-Message-State: AGi0PuYtOq/FT0MfnUScwBS9ErvACbKQVxRchstDaKfL95vwSSXzlg5f gpr3BXMnDsTYV9QZGOm6wHE4gQ== X-Google-Smtp-Source: APiQypLINN434d6iUSDES7A39dwlzFbgLy3RDmTDIyKH9QRLOsStR4rPZPAlk/dnqbdOzmjkgipUgQ== X-Received: by 2002:a1c:b60b:: with SMTP id g11mr3572353wmf.175.1585734485869; Wed, 01 Apr 2020 02:48:05 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w81sm1988288wmg.19.2020.04.01.02.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 251891FF8C; Wed, 1 Apr 2020 10:48:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 02/10] linux-user: protect fcntl64 with an #ifdef Date: Wed, 1 Apr 2020 10:47:51 +0100 Message-Id: <20200401094759.5835-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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: Richard Henderson , Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Checking TARGET_ABI_BITS is sketchy - we should check for the presence of the define to be sure. Also clean up the white space while we are there. Signed-off-by: Alex Bennée Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/syscall.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 5af55fca781..b679bc6b136 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11331,11 +11331,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, This is a hint, so ignoring and returning success is ok. */ return 0; #endif -#if TARGET_ABI_BITS == 32 +#ifdef TARGET_NR_fcntl64 case TARGET_NR_fcntl64: { - int cmd; - struct flock64 fl; + int cmd; + struct flock64 fl; from_flock64_fn *copyfrom = copy_from_user_flock64; to_flock64_fn *copyto = copy_to_user_flock64; @@ -11346,7 +11346,7 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, } #endif - cmd = target_to_host_fcntl_cmd(arg2); + cmd = target_to_host_fcntl_cmd(arg2); if (cmd == -TARGET_EINVAL) { return cmd; } From patchwork Wed Apr 1 09:47:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=G/NS5gfW; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shGZ2DXWz9sT2 for ; Wed, 1 Apr 2020 20:48:38 +1100 (AEDT) Received: from localhost ([::1]:57152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZz9-0004D1-US for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:48:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38405) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyg-0004BW-RC for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyf-00029q-RG for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:06 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyf-00029T-LW for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:05 -0400 Received: by mail-wr1-x443.google.com with SMTP id d5so29822537wrn.2 for ; Wed, 01 Apr 2020 02:48:05 -0700 (PDT) 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=R7MN9eSx9agbWPqT5OjGjNM4Lpuf6u0q6HsuyaT0dMs=; b=G/NS5gfWIvoCMjoY/hf6IqM6cjUKWTvJWafLiokeUrWmsyOUqHWVix0rCBZvqnwHcr 599UFL2w6uKsYK7GiuKBpkRDyTontw0CE6QTiJEm4ppRm96velXyZKeVq1cDeseFhscq XdeU14sYH8OY21JIrRI/JzJyuSsN0jvEgpjxk2PRFHcepz9QJx9eGpDMsqgqDwLE1fRl bc5KESuFNU+AWpsCeEsodlbZ+Ed3kqQmzSE2gNbYin/i8KRTXudMvzfn5UXj5BDCZMIC jOFVR5AN6EdmzKpv/LXRxQjZ1ndRSYrn4l0+LOb6sOq4PlSnYuQpOYxs4Lpy7Dl2RViO A3ig== 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=R7MN9eSx9agbWPqT5OjGjNM4Lpuf6u0q6HsuyaT0dMs=; b=oJA56x5KQ7K5KItnxBVOxx1dtULLWD0+qPanHdppmQZ4SqbOxJs8TV0vLylX1L2w/c OMhgCCdObVswizL+wD4reLv6EMeInar/LzePYWMd/WZ2r/d+ILketG32CDaNmQoqGM6X 2DwWXIjvNuY45htkpigZrzccECmMuSWndiTK7oip6oPvW/XSp3ncWlv0xsBqcFnwAo7K dRrBK8CEEKmFkzMOX1gR1UdeTonzeUtBnyrV0Em8nLQinfbZT2anjtCQUzOXYWFOFJb3 HAvPWDXozACvSwF63QNw+IXJr+zLhOEAWdMR8rC1y89OayRxZGMpX+vg5U3ykg/gfFrE /RAQ== X-Gm-Message-State: ANhLgQ34zpCnFVvqc93OFYmYoxpbgjyUPsK4vF0qBF9WXrIp9xhRWvDb spQbzhZr0XwiyYboaDnEaUqXiMZ3EFs= X-Google-Smtp-Source: ADFU+vvOFY+aWMF2/XPNNr7wtarEqkwsP/9guZq60tSSqWCzbXk0agQ23jh0oIsphq6MF7kN9ioSmQ== X-Received: by 2002:adf:fc45:: with SMTP id e5mr27049589wrs.56.1585734484637; Wed, 01 Apr 2020 02:48:04 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y80sm2006688wmc.45.2020.04.01.02.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 59C5F1FF8F; Wed, 1 Apr 2020 10:48:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 03/10] tests/tcg: remove extraneous pasting macros Date: Wed, 1 Apr 2020 10:47:52 +0100 Message-Id: <20200401094759.5835-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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: Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We are not using them and they just get in the way. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- tests/tcg/x86_64/system/boot.S | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/tcg/x86_64/system/boot.S b/tests/tcg/x86_64/system/boot.S index 205cfbd3982..73b19a2bda6 100644 --- a/tests/tcg/x86_64/system/boot.S +++ b/tests/tcg/x86_64/system/boot.S @@ -41,10 +41,7 @@ #define XEN_ELFNOTE_PHYS32_ENTRY 18 #define __ASM_FORM(x) x -#define __ASM_FORM_RAW(x) x -#define __ASM_FORM_COMMA(x) x, -#define __ASM_SEL(a,b) __ASM_FORM(b) -#define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b) +#define __ASM_SEL(a,b) __ASM_FORM(b) #define _ASM_PTR __ASM_SEL(.long, .quad) ELFNOTE(Xen, XEN_ELFNOTE_VIRT_BASE, _ASM_PTR 0x100000) From patchwork Wed Apr 1 09:47:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qaddUt6g; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shJH1WBjz9sSb for ; Wed, 1 Apr 2020 20:50:07 +1100 (AEDT) Received: from localhost ([::1]:57238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0a-0007co-32 for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:50:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38431) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyj-0004FR-G0 for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyi-0002As-Ed for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:09 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:34653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyi-0002Aa-8Z for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:08 -0400 Received: by mail-wr1-x442.google.com with SMTP id 65so29784059wrl.1 for ; Wed, 01 Apr 2020 02:48:08 -0700 (PDT) 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=L6skE25jv77X3Ic3q30MQuACWpAXjktUtUIdWwwluKc=; b=qaddUt6gSnfHtUbqDT8fOIjsUNFsxdg2jY032MjTS8Zc3Fkzy+uCiHF7IUyOY9TT3P igJF8E+F/vNAOD5so1Q7I3sFuMjso/YvUBbU65qpg00cGmcXqGd1VIsAYOPZ53kxLa66 Cd6sjMit8Hcqofi+3GCryuvhPk39ryUd1lipzLvF5qCy1GdMF7iPjHd9rkRKoUQonGff eRe8lUfhNphDBBQpUXM6Bsqh818DS9SNjBcdjs1JyC9Xa0eGsz9mrcBnzGvShrXSI4Hg Gxxh6ZsPcrAo6vDmJ7jTWLNtEMyWwLb8aCukw4rl7ZNRFbovcwSU6OBVQ5AJZuAH0D3N ++Mw== 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=L6skE25jv77X3Ic3q30MQuACWpAXjktUtUIdWwwluKc=; b=tBDwtU53SV5LH9pNvl9htFCqMrONxelXQgy86LeBMif1zjbX6zBMWUhgoPP8Amf8na q6SnKcvyQsactUU5L3E+aNZLaH/FateBal+Eqaerj8QkJpS6/0wZtXzAyJXo9XG+YL5r Pace7b2+jy5BCASy2t0onTX+xqTMHZAKGyUqMVs4Muh4pMYzqaSPJJhaqLitpBcMP3vC dPJXMIE3QWd/bsI7+WuQXCxOmxmpMnyC1XfPsHkBtUJffZ+bLzK0UKO38ptNhbgJbGz8 a2PT/SDocXMrjoAOok3zSqTpaK33sYIKNqnlBOs8tav0znd6R0bntmFoq1K3DEs/j3Up MH/Q== X-Gm-Message-State: ANhLgQ1KoP9b3SARGrAZJz+EEGbnZWm9vDt+PUhEnQJ/dLgLI52WBtlO pqmG2oCvL3U7QYihZitRw/sXTQ== X-Google-Smtp-Source: ADFU+vtQkvOfjACd8KkaSTd0VIWTUba0nb7zGH/a+DnZfcLlOiOf+zQ5meYxRi2t5lhVNzYa6uVRiw== X-Received: by 2002:adf:fc8b:: with SMTP id g11mr11313672wrr.51.1585734487218; Wed, 01 Apr 2020 02:48:07 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id b82sm1073589wme.25.2020.04.01.02.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 933431FF90; Wed, 1 Apr 2020 10:48:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 04/10] linux-user: more debug for init_guest_space Date: Wed, 1 Apr 2020 10:47:53 +0100 Message-Id: <20200401094759.5835-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Searching for memory space can cause problems so lets extend the CPU_LOG_PAGE output so you can watch init_guest_space fail to allocate memory. A more involved fix is actually required to make this function play nicely with the large guard pages the sanitiser likes to use. Signed-off-by: Alex Bennée Reviewed-by: Laurent Vivier --- linux-user/elfload.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8198be04460..619c054cc48 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2172,6 +2172,8 @@ unsigned long init_guest_space(unsigned long host_start, /* Check to see if the address is valid. */ if (host_start && real_start != current_start) { + qemu_log_mask(CPU_LOG_PAGE, "invalid %lx && %lx != %lx\n", + host_start, real_start, current_start); goto try_again; } @@ -2240,7 +2242,11 @@ unsigned long init_guest_space(unsigned long host_start, * probably a bad strategy if not, which means we got here * because of trouble with ARM commpage setup. */ - munmap((void *)real_start, real_size); + if (munmap((void *)real_start, real_size) != 0) { + error_report("%s: failed to unmap %lx:%lx (%s)", __func__, + real_start, real_size, strerror(errno)); + abort(); + } current_start += align; if (host_start == current_start) { /* Theoretically possible if host doesn't have any suitably From patchwork Wed Apr 1 09:47:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=RMProAHX; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shGf4wJMz9sR4 for ; Wed, 1 Apr 2020 20:48:42 +1100 (AEDT) Received: from localhost ([::1]:57180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZzE-0004QT-Hz for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38445) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyk-0004Gz-JR for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyj-0002Bf-JP for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:10 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyj-0002B3-Dn for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:09 -0400 Received: by mail-wm1-x341.google.com with SMTP id z7so3171019wmk.1 for ; Wed, 01 Apr 2020 02:48:09 -0700 (PDT) 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=h75bfILekusPXGlQBXuZSQUYvT0dH6xycgkUfP0rfEE=; b=RMProAHXOWc8vNSSVJOn0d1/V812X8r5sXDCj0Z/r/Tih7krd/eYR1UsEhM26pSWTB Dnzle2Op5YTAv+uplilIGicw/ebRfyGJewXZsSc/wR3L1iK57UPf/Sb51B7jAAqG+fyJ 4TeMfV6P3Oe6TkFezn+lcQyEYjzekG3Dm9y2B8K+FXeWGN7pTj5tCcIIb5KpQtxF/S/c QnBXgkq0/Wazl6j4dzTmsmqBltZBeEHS8oydZuQx2yNUos9hlBfIDwU4TZKyRtOD39UN 9S1VNTfdnQ87tdQVBX4V7CiwdHtdfIrak3t5cBzRuFFxW83D0GwDPQHSt57shRSuOaLa DM6w== 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=h75bfILekusPXGlQBXuZSQUYvT0dH6xycgkUfP0rfEE=; b=WxsjTnDhu9A4eKOSoMzbRaJAGqZ4oCsBgAFDYsmrn/DeCpOvrDXM4tbrhogvborNxV 70E+xOMkt2EZh6wFzCMOcByZ8f3BTz36Xbf/WntRhvrJ9s+iCwkIeUR3NJngtlbR4oHi Qk2knCUvjkvyNSQr1FL893rKK5PnT0QDSSapcR96+CdoiR0r+5P+c0jln+BHwvtbwR8d HXQSsXdztns9QT5a/RNKMFksf0fGJzE0u8Ml1Co812fHNqWQWbj/qWZKtn8lLXPEZiOU yWehD1eQJ861OKmENJ4Nv29fM3xQzOZA3NvS3IBYJm3oOVAPOpFdwtRKaR7+qFegOCss gnGg== X-Gm-Message-State: AGi0PubJLxW9OWwPbZxQzP19f1Cb/7aNGzBawO3KYZSvUlsjX+PUJKrn jmNXT3U4FmM15A+ONiOPNa0XQQ== X-Google-Smtp-Source: APiQypK9xv5BTWrp1VkpsZLejm1tKrhwj7MuUam69Y79t8z4Bp/CE39d3/rkI0HgDaFWd80NDtSeSA== X-Received: by 2002:a7b:c404:: with SMTP id k4mr3265439wmi.37.1585734488421; Wed, 01 Apr 2020 02:48:08 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z129sm1974080wmb.7.2020.04.01.02.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C84071FF91; Wed, 1 Apr 2020 10:48:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 05/10] target/xtensa: add FIXME for translation memory leak Date: Wed, 1 Apr 2020 10:47:54 +0100 Message-Id: <20200401094759.5835-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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: Max Filippov , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Dynamically allocating a new structure within the DisasContext can potentially leak as we can longjmp out of the translation loop (see test_phys_mem). The proper fix would be to use static allocation within the DisasContext but as the Xtensa translator imports it's code from elsewhere I leave that as an exercise for the maintainer. Signed-off-by: Alex Bennée Cc: Max Filippov Acked-by: Max Filippov --- target/xtensa/translate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 8aa972cafdf..37f65b1f030 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1174,6 +1174,11 @@ static void xtensa_tr_init_disas_context(DisasContextBase *dcbase, dc->callinc = ((tb_flags & XTENSA_TBFLAG_CALLINC_MASK) >> XTENSA_TBFLAG_CALLINC_SHIFT); + /* + * FIXME: This will leak when a failed instruction load or similar + * event causes us to longjump out of the translation loop and + * hence not clean-up in xtensa_tr_tb_stop + */ if (dc->config->isa) { dc->insnbuf = xtensa_insnbuf_alloc(dc->config->isa); dc->slotbuf = xtensa_insnbuf_alloc(dc->config->isa); From patchwork Wed Apr 1 09:47:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=o4vYVVwe; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shLG3Cs3z9sPF for ; Wed, 1 Apr 2020 20:51:50 +1100 (AEDT) Received: from localhost ([::1]:57302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa2G-0002xi-9j for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:51:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38459) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZym-0004L1-4T for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyl-0002CR-2W for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:12 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:39524) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyk-0002C7-Sj for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:11 -0400 Received: by mail-wm1-x333.google.com with SMTP id e9so6423010wme.4 for ; Wed, 01 Apr 2020 02:48:10 -0700 (PDT) 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=IiHiPfqSf5RxTYVWG0ZPN64iJbsFrXxtKKLhTgnCXm4=; b=o4vYVVwe2EC92JvUXX3NUKM4/28QtjdplV4no0lfxCgy5M98elsMbsK8YZ5zMP/yfg joliNWhm17CbcgQB4JIY1CnM4Hj1r2DN0KOsKsDu3aS8NPQOItWNXuNSYXjvo1wJGvC8 Or+nm2PfUhzOgJZTbX/UVTtEBdBAGmWLgdwrIW9Yz42054i+5snn/YVHmcGMvYfXJhay peXWQF4v4cnMaPK2BPoZZc2ElSvndfyGiBguuQ+Y7KJQOxst+ZqAvbyU+tGX7dgjwTq+ Um2ZdyxuJHYOSef5AFF9yHm92WKrg7ubRZqQD2Lbct1jsYKouhOg8ItPN8cMiE0rxr7J qTgw== 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=IiHiPfqSf5RxTYVWG0ZPN64iJbsFrXxtKKLhTgnCXm4=; b=Dev5vlF7YWbb9xryKrwab7PCK9eZ6QdWvgf2wjcvoMAUN+m0wAL2O4xbACVadlJKfe 0DEmb7xfPtc57WhtNqqopCX2yHvO723vnF8dT+tv6bN5rOK0Xd69uPxjNqmEWZyRJyGm NrD/PWP+idx18ARUUcfH7WVOLHT4z2QrSUxqjcv8nF7slYIPfxp4hyNN5t1UZeLhBhXe 0uxtoFwswIQaI0QoerCusRz1otQ1l/NeikWwFIVyefeUCT1Kpbc9hLxGYFZPJoKu7p9k /Xfp78HpyK/u3wHAfU9BoGRYkkEnBeqXkPYuXUPBb2QFvrcj3JcQeM4+nD2lDadeObFp MknQ== X-Gm-Message-State: AGi0PuYRtMGt09l8kmXN9EjyIfxKQCY3NC/C4Ic2sZiIvN9U8o5C4zdn /bH0Ktgp6i+OvFi9GIL8mkxWYg== X-Google-Smtp-Source: APiQypL3qT/ng4H8zsPoTm92t2srUtNHi9cg41Gzg+vNwft4IeWldnuE01wCzh7dbRLCePxvRh16yw== X-Received: by 2002:a1c:8193:: with SMTP id c141mr3330040wmd.14.1585734489788; Wed, 01 Apr 2020 02:48:09 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o9sm2184644wrx.48.2020.04.01.02.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 09BC91FF92; Wed, 1 Apr 2020 10:48:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 06/10] gdbstub: fix compiler complaining Date: Wed, 1 Apr 2020 10:47:55 +0100 Message-Id: <20200401094759.5835-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::333 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_Mathieu-Daud=C3=A9?= , Richard Henderson , Denis Plotnikov , Euler Robot , Chen Qun , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Denis Plotnikov ./gdbstub.c: In function ‘handle_query_thread_extra’: /usr/include/glib-2.0/glib/glib-autocleanups.h:28:10: error: ‘cpu_name’ may be used uninitialized in this function [-Werror=maybe-uninitialized] g_free (*pp); ^ ./gdbstub.c:2063:26: note: ‘cpu_name’ was declared here g_autofree char *cpu_name; ^ cc1: all warnings being treated as errors Signed-off-by: Denis Plotnikov Message-Id: <20200326151407.25046-1-dplotnikov@virtuozzo.com> Reported-by: Euler Robot Reported-by: Chen Qun Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 013fb1ac0f1..171e1509509 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2060,8 +2060,8 @@ static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_ctx) /* Print the CPU model and name in multiprocess mode */ ObjectClass *oc = object_get_class(OBJECT(cpu)); const char *cpu_model = object_class_get_name(oc); - g_autofree char *cpu_name; - cpu_name = object_get_canonical_path_component(OBJECT(cpu)); + g_autofree char *cpu_name = + object_get_canonical_path_component(OBJECT(cpu)); g_string_printf(rs, "%s %s [%s]", cpu_model, cpu_name, cpu->halted ? "halted " : "running"); } else { From patchwork Wed Apr 1 09:47:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265102 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=jQAatAea; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shJS4n2wz9sPF for ; Wed, 1 Apr 2020 20:50:16 +1100 (AEDT) Received: from localhost ([::1]:57250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0k-0007t1-IB for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyn-0004Of-Ew for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZym-0002Dj-6e for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:13 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:42120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZym-0002Ci-0m for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:12 -0400 Received: by mail-wr1-x444.google.com with SMTP id h15so29711519wrx.9 for ; Wed, 01 Apr 2020 02:48:11 -0700 (PDT) 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=g9xr3EL2jz3uIXqebGO8vaQXLJoFQmUrqrOGsA7SE/w=; b=jQAatAearxd3EEiqn5tSEB6+FPS2h3k2Td14CANfqmoJCDJfGpFBHjeY6zadkSv24h yOzZ+c4oPh3X7mEkfCn1TLTvqVi8LMAO+is7A/sV2hSz/E6I7CaU7oRQFgjjil0LdgiZ 2qwNUKn+0T+BxnJzheszEPcQLxXtYFhGbg9b/4h7EGsWqNryhmWWy0egpfn6c0HbPhJg f48+MdNSdYzfyYva/EklGDF/wx/edE196wks/6tT84kBC04HM55J1Zy0IjJSaxJXJ/dZ ocM6JskRmoB2jaw7XsvJkJgmPxtATA7+DDtpOKyykz3fMcNFL/j4Fn0WeZTaj0qjIEZm W8hw== 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=g9xr3EL2jz3uIXqebGO8vaQXLJoFQmUrqrOGsA7SE/w=; b=KxUFRKFvBcdOmdj6c8ZoeUNgWYUmypsDxjsZLScBtIBEFLD3HWU8noKWaFRMRJWyPY OVz3mkbVZWhQgy8uHsA50hE1mzf9FICJpQqfRap+SbcqYrUU8doGu0rjcBay10oGSOOS MElNPXdUWTnQi3B3IVumF4oVmToy9uhMgerXLpXzsw8yx/R9ZI1PHVwAMhrKLDznsJ41 gvb6R1Gr1aRAp/70FfAaSfWqI90IKOa0dDNV1pXTdyYTDh51qedtlb6BuiGtGyVnMIdi lryD6O60xv3i0IGzHyeJXJCqy8HpdfZ3jGCXIiUEOhy2mWupsvZpTLvh1aiT3ZN/cvW5 vZBQ== X-Gm-Message-State: ANhLgQ3XzRBVi+Hna/PMAFecqeV3SFPqA3ihC/tqoymVSEDI7HWCw/Ab MRyBCJy9im16P+2U2Rt7K+pVag== X-Google-Smtp-Source: ADFU+vtwS+KAz6fvg7u2JoBRVhs6QF6eo84RM319suKKZ1QSLFOeFRtdMDaFZbtLM/uu+wHG5FBeIQ== X-Received: by 2002:a5d:61c4:: with SMTP id q4mr26662376wrv.363.1585734491059; Wed, 01 Apr 2020 02:48:11 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m8sm1906126wmc.28.2020.04.01.02.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 364971FF93; Wed, 1 Apr 2020 10:48:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 07/10] softfloat: Fix BAD_SHIFT from normalizeFloatx80Subnormal Date: Wed, 1 Apr 2020 10:47:56 +0100 Message-Id: <20200401094759.5835-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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_Benn=C3=A9e?= , Richard Henderson , Aurelien Jarno , Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson All other calls to normalize*Subnormal detect zero input before the call -- this is the only outlier. This case can happen with +0.0 + +0.0 = +0.0 or -0.0 + -0.0 = -0.0, so return a zero of the correct sign. Reported-by: Coverity (CID 1421991) Signed-off-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20200327232042.10008-1-richard.henderson@linaro.org> --- fpu/softfloat.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 301ce3b537b..ae6ba718540 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5856,6 +5856,9 @@ static floatx80 addFloatx80Sigs(floatx80 a, floatx80 b, flag zSign, zSig1 = 0; zSig0 = aSig + bSig; if ( aExp == 0 ) { + if (zSig0 == 0) { + return packFloatx80(zSign, 0, 0); + } normalizeFloatx80Subnormal( zSig0, &zExp, &zSig0 ); goto roundAndPack; } From patchwork Wed Apr 1 09:47:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=aZ0z0rc/; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shJG0x01z9sR4 for ; Wed, 1 Apr 2020 20:50:05 +1100 (AEDT) Received: from localhost ([::1]:57234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0Z-0007aH-8c for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38489) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyo-0004SA-VG for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyn-0002FK-E0 for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:14 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:50713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyn-0002EI-6X for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:13 -0400 Received: by mail-wm1-x342.google.com with SMTP id t128so5875542wma.0 for ; Wed, 01 Apr 2020 02:48:13 -0700 (PDT) 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=a5n4+mCgHjpSYN+9AuOFcTGtUw1azSmiJDpjSXdf7Wc=; b=aZ0z0rc/9+8dM3ZkrGfOa9o/29ZpKvZfV9m6USTQ0NMEhY1w0K9+5AARPKSpjr6Poj f5fXTJDdbK9bpna/NzbkCZ7CFezRNnB7myByt0snEQaLhrtCMfFv8TsHz/85Mpaxi6Lx VYonRWHoLRgXAThAFVyxRLoe2yDHH4NOOSVPGReKzOHbqEPNO0GsVvddDpMrPqmbBwFE rpLKCF6JR3nbNfnubD+r5SXuoDSUjd67wH2Arb6XBQHk9CTcbQQ8BFqMNc3LD/fJR15R hayOM8w9HneoM3VcE4KFcyXev1doeLBsPUR3YIdizQDrk5SeqB60m0w8gq2Fg1byJYYk JO6A== 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=a5n4+mCgHjpSYN+9AuOFcTGtUw1azSmiJDpjSXdf7Wc=; b=gSo+/7DR56ksqGmu9B+ZtKtcCt/wuu3SVuC5IHE+aQtUnUUYaYZhea56gWaaOWRLR4 FWOHeAv8OEQfYguhgSLKSlJ58jZFTBfaBsENMP2sV7ZkGsUmwjaeNNwAp7M+0s58BPt9 YDPT97Nrrlnh+YSUnMSmWIoME7Gl++HpDcXSWBIucw+x/kPptQEIdsNom6s42e1KbU05 BIN97aDCWmy6z7GgNa3yKgbulTfumhvMlRAjNUxud0v9uvpFrThXyVwSduqmzwoBk1F3 xpyVo2+VZhhZbBQXgZLXs8fRSRJUZCrajYQDZ47PbOJpAG0Xf8TEgi6CbE4XLm3UMtI4 /Rrg== X-Gm-Message-State: AGi0Pub0sW38NpPiz2mMvPiNaNljpv1HXHRFe2xn2oKZj98J2UeMA5l2 gTmjPC4eMnxIaC1GfVbwSBmRHw== X-Google-Smtp-Source: APiQypLn83cBHAUgHLqKie7d1j0B/cliC3qfVv6pl9iAB9WfHDQsdBQf35ewDQ20PapGommnFScTHA== X-Received: by 2002:a1c:4684:: with SMTP id t126mr3375000wma.128.1585734492046; Wed, 01 Apr 2020 02:48:12 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n6sm2314114wrp.30.2020.04.01.02.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8DC061FF96; Wed, 1 Apr 2020 10:48:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 08/10] linux-user: factor out reading of /proc/self/maps Date: Wed, 1 Apr 2020 10:47:57 +0100 Message-Id: <20200401094759.5835-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Unfortunately reading /proc/self/maps is still considered the gold standard for a process finding out about it's own memory layout. As we will want this data in other contexts soon factor out the code to read and parse the data. Rather than just blindly copying the existing sscanf based code we use a more modern glib version of the parsing code to make a more general purpose map structure. Signed-off-by: Alex Bennée --- include/qemu/selfmap.h | 44 +++++++++++++++++++++++++ linux-user/syscall.c | 58 ++++++++++++++++----------------- util/selfmap.c | 74 ++++++++++++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + 4 files changed, 147 insertions(+), 30 deletions(-) create mode 100644 include/qemu/selfmap.h create mode 100644 util/selfmap.c diff --git a/include/qemu/selfmap.h b/include/qemu/selfmap.h new file mode 100644 index 00000000000..3bc96feb055 --- /dev/null +++ b/include/qemu/selfmap.h @@ -0,0 +1,44 @@ +/* + * Utility functions to read our own memory map + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _SELFMAP_H_ +#define _SELFMAP_H_ + +typedef struct { + uint64_t start; + uint64_t end; + + /* flags */ + bool is_read; + bool is_write; + bool is_exec; + bool is_priv; + + uint64_t offset; + gchar *dev; + int inode; + gchar *path; +} MapInfo; + + +/** + * read_self_maps: + * + * Read /proc/self/maps and return a list of MapInfo structures. + */ +GSList *read_self_maps(void); + +/** + * free_self_maps: + * @info: a GSlist + * + * Free a list of MapInfo structures. + */ +void free_self_maps(GSList *info); + +#endif /* _SELFMAP_H_ */ diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b679bc6b136..0246df01573 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -117,6 +117,7 @@ #include "qemu.h" #include "qemu/guest-random.h" +#include "qemu/selfmap.h" #include "user/syscall-trace.h" #include "qapi/error.h" #include "fd-trans.h" @@ -7232,45 +7233,45 @@ static int open_self_maps(void *cpu_env, int fd) { CPUState *cpu = env_cpu((CPUArchState *)cpu_env); TaskState *ts = cpu->opaque; - FILE *fp; - char *line = NULL; - size_t len = 0; - ssize_t read; + GSList *map_info = read_self_maps(); + GSList *s; - fp = fopen("/proc/self/maps", "r"); - if (fp == NULL) { - return -1; - } + for (s = map_info; s; s = g_slist_next(s)) { + MapInfo *e = (MapInfo *) s->data; - while ((read = getline(&line, &len, fp)) != -1) { - int fields, dev_maj, dev_min, inode; - uint64_t min, max, offset; - char flag_r, flag_w, flag_x, flag_p; - char path[512] = ""; - fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" - " %512s", &min, &max, &flag_r, &flag_w, &flag_x, - &flag_p, &offset, &dev_maj, &dev_min, &inode, path); - - if ((fields < 10) || (fields > 11)) { - continue; - } - if (h2g_valid(min)) { + if (h2g_valid(e->start)) { + uint64_t min = e->start; + uint64_t max = e->end; int flags = page_get_flags(h2g(min)); - max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX) + 1; + const char *path; + + max = h2g_valid(max - 1) ? + max : (uintptr_t) g2h(GUEST_ADDR_MAX) + 1; + if (page_check_range(h2g(min), max - min, flags) == -1) { continue; } + if (h2g(min) == ts->info->stack_limit) { - pstrcpy(path, sizeof(path), " [stack]"); + path = " [stack]"; + } else { + path = e->path; } + dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr - " %c%c%c%c %08" PRIx64 " %02x:%02x %d %s%s\n", - h2g(min), h2g(max - 1) + 1, flag_r, flag_w, - flag_x, flag_p, offset, dev_maj, dev_min, inode, - path[0] ? " " : "", path); + " %c%c%c%c %08" PRIx64 " %s %d %s%s\n", + h2g(min), h2g(max - 1) + 1, + e->is_read ? 'r' : '-', + e->is_write ? 'w' : '-', + e->is_exec ? 'x' : '-', + e->is_priv ? 'p' : '-', + e->offset, e->dev, e->inode, + path ? " " : "", path ? path : ""); } } + free_self_maps(map_info); + #ifdef TARGET_VSYSCALL_PAGE /* * We only support execution from the vsyscall page. @@ -7281,9 +7282,6 @@ static int open_self_maps(void *cpu_env, int fd) TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); #endif - free(line); - fclose(fp); - return 0; } diff --git a/util/selfmap.c b/util/selfmap.c new file mode 100644 index 00000000000..d72b2c32f07 --- /dev/null +++ b/util/selfmap.c @@ -0,0 +1,74 @@ +/* + * Utility function to get QEMU's own process map + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/selfmap.h" + +GSList *read_self_maps(void) +{ + gchar *maps; + GSList *map_info = NULL; + + if (g_file_get_contents("/proc/self/maps", &maps, NULL, NULL)) { + gchar **lines = g_strsplit(maps, "\n", 0); + int i, entries = g_strv_length(lines); + + for (i = 0; i < entries; i++) { + gchar **fields = g_strsplit(lines[i], " ", 0); + if (g_strv_length(fields) > 4) { + MapInfo *e = g_new0(MapInfo, 1); + int errors; + const char *end; + + errors = qemu_strtoul(fields[0], &end, 16, &e->start); + errors += qemu_strtoul(end + 1, NULL, 16, &e->end); + + e->is_read = fields[1][0] == 'r' ? true : false; + e->is_write = fields[1][1] == 'w' ? true : false; + e->is_exec = fields[1][2] == 'x' ? true : false; + e->is_priv = fields[1][3] == 'p' ? true : false; + + errors += qemu_strtoul(fields[2], NULL, 16, &e->offset); + e->dev = g_strdup(fields[3]); + errors += qemu_strtoi(fields[4], NULL, 10, &e->inode); + + /* A bit ugly as strsplit doesn't skip multiple separators */ + if (g_strv_length(fields) > 6) { + e->path = g_strdup(fields[g_strv_length(fields) - 1]); + } + map_info = g_slist_prepend(map_info, e); + } + + g_strfreev(fields); + } + g_strfreev(lines); + g_free(maps); + } + + /* ensure the map data is in the same order we collected it */ + return g_slist_reverse(map_info); +} + +/** + * free_self_maps: + * @info: a GSlist + * + * Free a list of MapInfo structures. + */ +static void free_info(gpointer data) +{ + MapInfo *e = (MapInfo *) data; + g_free(e->dev); + g_free(e->path); +} + +void free_self_maps(GSList *info) +{ + g_slist_free_full(info, &free_info); +} diff --git a/util/Makefile.objs b/util/Makefile.objs index 6718a38b616..fe339c2636b 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -63,3 +63,4 @@ util-obj-y += guest-random.o util-obj-$(CONFIG_GIO) += dbus.o dbus.o-cflags = $(GIO_CFLAGS) dbus.o-libs = $(GIO_LIBS) +util-obj-$(CONFIG_USER_ONLY) += selfmap.o From patchwork Wed Apr 1 09:47:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265103 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Bho9PpvI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shLF3HQwz9sR4 for ; Wed, 1 Apr 2020 20:51:49 +1100 (AEDT) Received: from localhost ([::1]:57294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa2F-0002u3-7A for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38494) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyp-0004TV-Dg for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyo-0002Fw-9f for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:15 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:45978) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyo-0002FX-3D for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:14 -0400 Received: by mail-wr1-x442.google.com with SMTP id t7so29717079wrw.12 for ; Wed, 01 Apr 2020 02:48:14 -0700 (PDT) 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=WLTsGPoiyiZpQWSAjDx1Jd/3OsKOnqyDSFWAME1qJxU=; b=Bho9PpvIJqh1yBVCpgktnF2q4gBLJiWRK1Bdesx3wnL+bemJhpFF1PtSZ+V0z2Whcl qnChS1AabKalg2BP7QCt6e9x5+0GxJXZhVSve+cbD1XWZkvsnFYExxwP4WasdAmzJj0J hYEhtdQc1gRLIleu5WkOCk/gRUSVRzSOvABl/rfkX5KLwSh2fgqh9RYG4gD2EEf+omeo P5UTatdU0nrIn57LzZRfvI8FXFZYveF8tlWC1zdqhDnhA4eO/hNs6IucRB1l6c7Wa9N+ x/6atOLjsBst1LJAEw4RkvK+ntRfZykRlGvD/plb2bySagklsTfkDhdAApKYjyKlDUez UAPQ== 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=WLTsGPoiyiZpQWSAjDx1Jd/3OsKOnqyDSFWAME1qJxU=; b=nWQaj1jUyEJDpLujiLffm+QJOGTp14laUIiEi8lJMyIC8+dCquMPIUz1qt7Lj8Slcr fT8qAhr2EU4AlPEJTcyO7JiPvfO8NUBmjeInfADxLjA2XWZfxkhNeZRpnF6RHXTwmmXO 3cGMwTfE2hQw25U2EPVBr5nugSeF/Fd2+bkcFUO47bl/i389uAi8/UEBpDj4XVCWcmAf P2abDXvdsmXIlBBTy415yDoCE/nMlm4zOSOaqMdeMwLCDuIYFeU34jeBrBXoZHfG0rSC vyO+K3fr2XulfRlAC8hUQfJ696CO1zDdlquqPAWMBNmUjvuDXHDsa0YzdKnAePCB7qgU pkaA== X-Gm-Message-State: ANhLgQ3VHu9JhzhEJ/IwP9CytePMVazEWI1d2sEmcdTEZ8kjxvKcUmu+ t9sd14xn8bLtI4Jy4wHHUCRaCg== X-Google-Smtp-Source: ADFU+vvmkcPnEaQoSqVRpRTP7Ezl4fwK7WCuek23SCd9jAE6+pWf+MZLzxDBU85j05YW39uphhtwoQ== X-Received: by 2002:adf:bb06:: with SMTP id r6mr25539282wrg.324.1585734493143; Wed, 01 Apr 2020 02:48:13 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r15sm2350519wra.19.2020.04.01.02.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C998A1FF98; Wed, 1 Apr 2020 10:48:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 09/10] linux-user: clean-up padding on /proc/self/maps Date: Wed, 1 Apr 2020 10:47:58 +0100 Message-Id: <20200401094759.5835-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't use magic spaces, calculate the justification for the file field like the kernel does with seq_pad. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- linux-user/syscall.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 0246df01573..b921432f4ff 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -7235,6 +7235,7 @@ static int open_self_maps(void *cpu_env, int fd) TaskState *ts = cpu->opaque; GSList *map_info = read_self_maps(); GSList *s; + int count; for (s = map_info; s; s = g_slist_next(s)) { MapInfo *e = (MapInfo *) s->data; @@ -7253,20 +7254,24 @@ static int open_self_maps(void *cpu_env, int fd) } if (h2g(min) == ts->info->stack_limit) { - path = " [stack]"; + path = "[stack]"; } else { path = e->path; } - dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr - " %c%c%c%c %08" PRIx64 " %s %d %s%s\n", - h2g(min), h2g(max - 1) + 1, - e->is_read ? 'r' : '-', - e->is_write ? 'w' : '-', - e->is_exec ? 'x' : '-', - e->is_priv ? 'p' : '-', - e->offset, e->dev, e->inode, - path ? " " : "", path ? path : ""); + count = dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr + " %c%c%c%c %08" PRIx64 " %s %d", + h2g(min), h2g(max - 1) + 1, + e->is_read ? 'r' : '-', + e->is_write ? 'w' : '-', + e->is_exec ? 'x' : '-', + e->is_priv ? 'p' : '-', + e->offset, e->dev, e->inode); + if (path) { + dprintf(fd, "%*s%s\n", 73 - count, "", path); + } else { + dprintf(fd, "\n"); + } } } @@ -7277,9 +7282,10 @@ static int open_self_maps(void *cpu_env, int fd) * We only support execution from the vsyscall page. * This is as if CONFIG_LEGACY_VSYSCALL_XONLY=y from v5.3. */ - dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx - " --xp 00000000 00:00 0 [vsyscall]\n", - TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); + count = dprintf(fd, TARGET_FMT_lx "-" TARGET_FMT_lx + " --xp 00000000 00:00 0", + TARGET_VSYSCALL_PAGE, TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE); + dprintf(fd, "%*s%s\n", 73 - count, "", "[vsyscall]"); #endif return 0; From patchwork Wed Apr 1 09:47:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1265105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=NUOTNK2F; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48shN61dWPz9sR4 for ; Wed, 1 Apr 2020 20:53:26 +1100 (AEDT) Received: from localhost ([::1]:57324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa3m-0004np-UD for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 05:53:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38515) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZys-0004aU-5K for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJZyp-0002HK-Ud for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:18 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53628) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJZyp-0002Gz-Me for qemu-devel@nongnu.org; Wed, 01 Apr 2020 05:48:15 -0400 Received: by mail-wm1-x343.google.com with SMTP id b12so5847085wmj.3 for ; Wed, 01 Apr 2020 02:48:15 -0700 (PDT) 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=wiruPLRzIVKr/sqR3IRGFAA55bADwbShqW9FNeJTSKM=; b=NUOTNK2FpGsl230XFpru04XaorS9Fxu5/PUxhVMSncfKVd12/RXuw7nVpC/KZyfzCN 5nRYhBRBaefVMu8OwfBvvISF3bbLoKILzcRF+ANgtCaC1rrvbqCC2Ti4OUk4IkMpiO/1 8Qs0GIymvfHqSCXN6bYvRc/P1f9DFnNCeBFxo5cZjrOerWl5fQQdGHTj0wNsi4AHuRfR UVzVAhiPh8UzYx7ynQ0EBNM3MXBGLvgxsR8cQBPUkkImvEHDONQeT+Jkc1qoCE/lKH6i 5WA7XZB4BSpVYRkbK+M4MLCTW36VV46+naQvpsNLQdfjHlB41cjWbT04soIKYWeWAWcq XnNA== 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=wiruPLRzIVKr/sqR3IRGFAA55bADwbShqW9FNeJTSKM=; b=cGj7yJMh+reTVRPHEl/QnRmx+M8VTfukCW0xrr6vStLdTzt8V9BGdTA1Dha/VF3pCP TDA6WtIW9TaLSMHimEKduoA/PbIgpZt0clU4UHSss7snIO71YOaFJr3hzsWVmibkcWwn 0KMjaMhZz3d9NuK5DI8ThnagvSwZhbdzRvuSrUowPs3hX5Q/QhkkuRgYeh7yPR4PTFwH LZOXqj6NQfWZQGKgWiZLJq7uAUTnsn9Kz8+08Th3KU+4XfiBXtpIbH2MFLDEE0YMqRQF FXcNxjlkWkNs15d/kd1EMmokrNo+5y6fiXjPajSclGPQ1Ro/dK491Feerr7HYO+XzFet 7Z1g== X-Gm-Message-State: AGi0PuYek+NsMFbS5FiL6t2ri5oqh2KcPhGUYK+/Asxj1EnbkKWWrOuf ZWCNJiVALfxGOCKjxhmOCezWQtdV9Tk= X-Google-Smtp-Source: APiQypLdIx782lgw4/UD2ldY+eLHyDtWTRn1EUvCLVFl21Vm9hfDHa+7CGE2qb9fqBc/AMHEiQou4Q== X-Received: by 2002:a7b:c145:: with SMTP id z5mr3413061wmi.55.1585734494441; Wed, 01 Apr 2020 02:48:14 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l10sm2329335wrq.95.2020.04.01.02.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Apr 2020 02:48:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 09A011FF99; Wed, 1 Apr 2020 10:48:02 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 10/10] linux-user: completely re-write init_guest_space Date: Wed, 1 Apr 2020 10:47:59 +0100 Message-Id: <20200401094759.5835-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200401094759.5835-1-alex.bennee@linaro.org> References: <20200401094759.5835-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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 , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This tries to simplify the init_guest_space code to be a little less convoluted and remove the brute force mapping algorithm that gets tripped up so badly by the sanitizers. 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. Less mind-binding gotos and hopefully clearer logic although perhaps more sloppy casting than I'm totally happy with. Signed-off-by: Alex Bennée --- linux-user/elfload.c | 279 +++++++++++++++++++------------------------ 1 file changed, 125 insertions(+), 154 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 619c054cc48..88c08513119 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" #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -2075,6 +2076,34 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, return sp; } +/* + * Wrapper to hide to keep the ugliness of the commpage checks out of + * the init_guest_space function bellow. For non-32 bit ARM targets it + * always succeeds. + */ +static bool check_commpage(unsigned long start, unsigned long size) +{ +#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) + if (init_guest_commpage(start, size) != 1) { + return false; + } +#endif + return true; +} + +/* + * init_guest_space: + * + * Reserve the initial chunk of guest address space. In order we try: + * + * - if given host_start just verify it + * - else try and allocate at guest_start to save offset calculations + * - finally allocate from lowest available >= host_size'd gap + * + * In practice it shouldn't matter if the guest can't extend brk above + * it's initial allocation because any moderately sane memory + * allocation library should be using mmap to allocate additional blocks. + */ unsigned long init_guest_space(unsigned long host_start, unsigned long host_size, unsigned long guest_start, @@ -2082,183 +2111,125 @@ unsigned long init_guest_space(unsigned long host_start, { /* In order to use host shmat, we must be able to honor SHMLBA. */ unsigned long align = MAX(SHMLBA, qemu_host_page_size); - unsigned long current_start, aligned_start; - int flags; + void *map_addr = NULL; + const int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE | MAP_FIXED; assert(host_start || host_size); - /* If just a starting address is given, then just verify that - * address. */ + /* + * If just a starting address is given, then just verify that + * address. If the commpage isn't happy we pretty much give up + * now. + */ if (host_start && !host_size) { -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - if (init_guest_commpage(host_start, host_size) != 1) { + if (!check_commpage(host_start, host_size)) { return (unsigned long)-1; + } else { + qemu_log_mask(CPU_LOG_PAGE, "%s: host_start @ %#lx verified\n", + __func__, host_start); + return host_start; } -#endif - return host_start; } - /* Setup the initial flags and start address. */ - current_start = host_start & -align; - flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE; - if (fixed) { - flags |= MAP_FIXED; - } - - /* Otherwise, a non-zero size region of memory needs to be mapped - * and validated. */ - -#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. + /* + * Now we are going to try and map something, we start by trying + * to satisfy exactly what the guest wants. This is unlikely to + * succeed but will make the code generators job easier if it can + * be done. + * + * If the commpage check isn't happy after we allocate we need to + * fall back to finding a big enough hole in the address space. */ - if (!host_start) { - unsigned long guest_full_size, host_full_size, real_start; - - guest_full_size = - (0xffff0f00 & qemu_host_page_mask) + qemu_host_page_size; - host_full_size = guest_full_size - guest_start; - real_start = (unsigned long) - mmap(NULL, host_full_size, PROT_NONE, flags, -1, 0); - if (real_start == (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; + map_addr = (void *) guest_start; + if (mmap(map_addr, host_size, PROT_NONE, flags, -1, 0) == map_addr) { + if (check_commpage(guest_start, host_size)) { + /* success, everyone is happy :-D */ + qemu_log_mask(CPU_LOG_PAGE, "%s: got what guest wanted @ %p\n", + __func__, map_addr); + return guest_start; } - 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 = host_full_size + qemu_host_page_size; - real_start = (unsigned long) - mmap(NULL, real_size, PROT_NONE, flags, -1, 0); - if (real_start == (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 = ROUND_UP(real_start, align); - } - current_start = real_start; - } - naive: -#endif - - while (1) { - unsigned long real_start, real_size, aligned_size; - aligned_size = real_size = host_size; - /* 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 = (unsigned long) - mmap((void *)current_start, host_size, PROT_NONE, flags, -1, 0); - if (real_start == (unsigned long)-1) { - return (unsigned long)-1; - } - - /* Check to see if the address is valid. */ - if (host_start && real_start != current_start) { - qemu_log_mask(CPU_LOG_PAGE, "invalid %lx && %lx != %lx\n", - host_start, real_start, current_start); - goto try_again; + if (munmap(map_addr, host_size) != 0) { + error_report("%s: failed to unmap %p:%lx (%s)", __func__, + map_addr, host_size, strerror(errno)); + abort(); } + } else if (fixed) { + /* + * If the caller wanted a fixed address we have pretty much failed + * to deliver here so it is time to bail out gracefully. + */ + error_report("%s: failed to honour fixed guest request @ %p", + __func__, map_addr); + return (unsigned long)-1; + } - /* 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=false). 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 = aligned_size + align; - real_start = (unsigned long) - mmap((void *)real_start, real_size, PROT_NONE, flags, -1, 0); - if (real_start == (unsigned long)-1) { - return (unsigned long)-1; + /* + * Finally we need to find a hole somewhere in the address space + * that will accept the initial mapping as well as being able to + * map the (ARM32 specific) commpage later. + * + * We need to ensure the address is properly aligned. 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 aforementioned ARM32 emulation. + */ + { +#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) + uint64_t required_size = + (0xffff0f00 & qemu_host_page_mask) + qemu_host_page_size; +#else + uint64_t required_size = host_size + align; +#endif + GSList *map_info = read_self_maps(); + GSList *last, *next; + map_addr = NULL; + + for (last = map_info, next = g_slist_next(last); + next; last = next, next = g_slist_next(next)) { + MapInfo *l = (MapInfo *) last->data; + MapInfo *n = (MapInfo *) next->data; + uint64_t base = ROUND_UP(l->end, align); + uint64_t gap_size = n->start - base; + if (gap_size > required_size) { + map_addr = (void *) base; + break; } - aligned_start = ROUND_UP(real_start, align); - } else { - aligned_start = real_start; } -#if defined(TARGET_ARM) && !defined(TARGET_AARCH64) - /* On 32-bit ARM, we need to also be able to map the commpage. */ - int valid = init_guest_commpage(aligned_start - guest_start, - aligned_size + guest_start); - if (valid == -1) { - munmap((void *)real_start, real_size); + /* + * We couldn't find any space in the memory map, woe... + */ + if (!map_addr) { + error_report("%s: couldn't find a %ld sized gap in the memory map", + __func__, required_size); return (unsigned long)-1; - } else if (valid == 0) { - goto try_again; } -#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) != 0) { - error_report("%s: failed to unmap %lx:%lx (%s)", __func__, - real_start, real_size, strerror(errno)); + /* + * From this point on it should be a formality but lets go through + * the steps anyway. + */ + if (mmap(map_addr, host_size + align , PROT_NONE, + flags | MAP_FIXED, -1, 0) == map_addr) { + unsigned long addr = (unsigned long) map_addr; + if (!check_commpage(addr, host_size + align)) { + error_report("%s: commpage won't fit in guest_memory @ %p", + __func__, map_addr); abort(); + } else { + qemu_log_mask(CPU_LOG_PAGE, "%s: guest address space @ %p\n", + __func__, map_addr); + return addr; } - current_start += align; - if (host_start == current_start) { - /* Theoretically possible if host doesn't have any suitably - * aligned areas. Normally the first mmap will fail. - */ - return (unsigned long)-1; - } + } else { + error_report("%s: failed to allocate guest address space @ %p (%d/%s)", + __func__, map_addr, errno, strerror(errno)); } - qemu_log_mask(CPU_LOG_PAGE, "Reserved 0x%lx bytes of guest address space\n", host_size); - - return aligned_start; + /* really should never get here */ + g_assert_not_reached(); } static void probe_guest_base(const char *image_name,