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: 185131 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp328703ilr; Wed, 1 Apr 2020 02:48:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs+OmhpcaOG5ocZ3TI/ws6b+BfCbOvDWfQOz13iAcopIRkgopHKQt1HOFKs+IEXcV6uchDn X-Received: by 2002:a05:620a:1405:: with SMTP id d5mr9235168qkj.275.1585734498262; Wed, 01 Apr 2020 02:48:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734498; cv=none; d=google.com; s=arc-20160816; b=TLlcIgowlB0FZaIVW6InYtO2eNqyl1VsVYvpYybxHrleATn2Z/GY7UbgjTot/xw+uT pSdBmzAlX4iCB4bvfKjo06ymunTUrn3KsgGgFyNcPFbmjrW4BaqwuIrUFAaPCgEQhV4Q pQ3tx6TpnAN5kORuPSBBwNqW4Ey0TaWDBRRvaUFJFy6Q3IowXJlqcErzwwl1px55I8Le GdyehNBX9h/hKJjaP+6kyyIh2zN9J6Y7bDIU/rBdDbvHm+qHlt44SfzLoQ0XDaoXfHUM zX6/95pxOBGqAYarsg0fm2LwVnsEx5LTA3WkGObzPFBr2+bLSdc1Y3bappHArQzzSH+D 7/Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=dAKPurE9Z4/yGpaiKXNSiApWEbrm/XJIzako9b36VuI=; b=BT9QlXqd/Ols+RjrO+TuF38h0uck6qYKduvuxT5YDk1H9dpDI68zCpc1vczBeOMuyM nZzeJDszsYWG+SEr0uUEXcfWO9nRAWYot9YYEmnDpDn++6TdkrPAMIMEqfCt1qiQx0Av XfGL8RJku1LbEsQfR/O3rF+Uu5R0xy/IK6RLtX+iGP16a9sKmQPsV0aJ/UZB9LMPAmOO pXqB2RsKkHGqV54XPi4Kj98syah0rNNP6/Hmwo3eoSUl8U3/qgEH/0bxgLY6IJRQ5fpC ytfkb+cDFVU4UwXPSFCta4aahj42B8S9JB2P++jFBhR4g8W4oShEmWWAc3w2axE9O5IQ DgDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LVtRNlmk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id bq5si759127qvb.48.2020.04.01.02.48.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:48:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LVtRNlmk; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyr-0004BY-OB for patch@linaro.org; Wed, 01 Apr 2020 05:48:17 -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-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+patch=linaro.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(-) -- 2.20.1 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: 185136 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp329825ilr; Wed, 1 Apr 2020 02:49:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsbPCM/NZ5r9c+azzKjHnjDbZZ0VEK5Re6ZbAAbxbwe89dRl7DNI2ZJzmcGBC8mqHcT6ITf X-Received: by 2002:a37:4c0a:: with SMTP id z10mr9361333qka.408.1585734589729; Wed, 01 Apr 2020 02:49:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734589; cv=none; d=google.com; s=arc-20160816; b=eiOHWUL6BF+NbyMZ8RA9wFxCc6s105ksN5bYG36DZzp4vSUnZA/HBQhKvmWsQenCiS tnw/2RAoNd/jyaBcdGZuZhEttP7Rt8Aas5LJuKok40nL2AN3F50Lf2ksCaU9LtrSeN1B IOZVLClB3Yex7QBPCevalzjVlQWlSUFWRdIWIT3uynpHDHl+8/S9EdrMKcTNqJ3KNaan 7szddRGy0TgJQIlLhKsDCpyO+SLScRdcyhrk3WauR3LGfMQQmrZM6ON3gz4Xs+kSu3X3 Bzg8m7s4X/MZ3DCHdZ+vNAbtQtvJZ6xv2H33L9bpsrLeiOrAnMzPutpUEeqj3ZJo506W kUTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=9yYReGEoMkqsfZWblGMzvHlMGSzTNisl1Y211B1bnEY=; b=bDoTxLgMj+x49FkejD3h4EdC4sG7+n+pTtS0f9ENymuY5mXLX/f0mx+9IQ8eTYw+pu +fpdbyqO2CrnZJj4O3L7bA7lsR1B88oacnUqrhljRGT5Ut1L58YfWhxySfFoRqelUo4x 4DH12pPcl6PfKCZygeW2tpiMOtDgU1lsQRmK2bgy6vRZ+GPSHf5PaIDJasvZjyqAZ/lx 2kExhPCxdp3rWEtnfNhG8dFtdT2VFgOgljQNGWfFI4z4R97wn1p2GS+pIab6k0XkDdqt 6EhTSi6c5MFyDKXfZk7mOLF5ZIycaUtQu8kMnflpNV5IrBsDp6DnA/6cR58LiKPIV/iH ho5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j6sWA4nN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d11si861879qki.28.2020.04.01.02.49.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:49:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=j6sWA4nN; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0L-0007fn-8U for patch@linaro.org; Wed, 01 Apr 2020 05:49:49 -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-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+patch=linaro.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(-) -- 2.20.1 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: 185132 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp328724ilr; Wed, 1 Apr 2020 02:48:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuZFVOlhOTijvRVzFUUpHpalASnRRVzfZEfPazdpNOE6lCvnzKoPQBqrSWYfnBnLEQYD1Ux X-Received: by 2002:ac8:23af:: with SMTP id q44mr9280978qtq.54.1585734500948; Wed, 01 Apr 2020 02:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734500; cv=none; d=google.com; s=arc-20160816; b=tEL22EcuUxzuCgExpJUlT7DNwqt2kg0fY5OZ2GaGXeUKlBUCTCWh/Yl/w6ZQ7viyPn np2ulYQ+ehbbD71hNiFZu9csUektU9lCaZoTekmck38nBARB5f1SN9G52XXaD7Gn+s6+ iXnDzodhQp+a+qAt3lAfOfKX/uejbDdCENmX5TpqPRXodlY7r/yPWONbUKTfhHAZy7kb ck7WceeXt7q+elEzkDI/6SLK/0vUQsCztIw25SPPtxuBmSEgTihqWvangmQsV4fTIIRt TXEKUoAikPy+/EuBUwVSp6HhNNSvOFdTqURUau/RbVeeW4tDTKfmLzgRfEhgT/onqMhZ c3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=R7MN9eSx9agbWPqT5OjGjNM4Lpuf6u0q6HsuyaT0dMs=; b=y+DrUn0unLeNq/aQ6eQp2YucHNEsDp+kcT9s0q+YTHpO3T76Y+swJTn2CymKWK3/id S02KIgj9RvwVQk9Po13M0BS/XR0hqKzg5RBp7SM+NG4B8JQF5D6PaeJFFRjXn52ySvhC dFwfD+5FFIq8EzMu3IwruXH6O7NF1MsIUTfcMwu6sazgTVK+P32gKUHj8+Rm/nXDJDn6 4MvZyhIQehhQ+N6YBKWZci+xkADzOUN3RHYb93rsuBisJzjqH/AqRenbIRmwS+OobnH8 diCJwXX8YmYCovDOnJR3Uo3x3CeiHuHFOwULOTRtxq48jBqr+eUxEaR6UnaG7yi7oA6Y CcEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="G/NS5gfW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u1si850528qtk.39.2020.04.01.02.48.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="G/NS5gfW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyu-0004D1-EI for patch@linaro.org; Wed, 01 Apr 2020 05:48:20 -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-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+patch=linaro.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(-) -- 2.20.1 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: 185135 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp329813ilr; Wed, 1 Apr 2020 02:49:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuoI0i+TuaGsk55DtVr1dqqgrtTwIep9VXiubNUoiZgJzTBaKH4btFo6CXTerITqBJ0fEDS X-Received: by 2002:a0c:fe04:: with SMTP id x4mr20793000qvr.69.1585734588652; Wed, 01 Apr 2020 02:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734588; cv=none; d=google.com; s=arc-20160816; b=jzHbf4OjpC1AR1bws4/GTsBT1wfK/2qntQxnftPee23WKDI6ixhbxubXTp2Nye4n5a 7RZlPn1M6uk8NOqlQpYIKrHflbvyYR0H1+nfi/K5skncmeyOQU17z0VKaLT4F+1zOvuQ V/9Tf5YGAQX6Z6tZWs1zu7zeR77J2zYwj88GaGZlkRwpcsfHvt+8vGJNyuFXHhlV4QmI mrPkFlTghsQP3URt3HPugniLquAIRNbgTigRgTHUxZNqfPuvHguOTF7x2287rBzTxLCE npEYKabmoW6wj4jAEUzRXv98jlOwdCj7LB/prmHZiXyFBGdbaW7r+9N3+xRTuq9DxWn8 og+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=L6skE25jv77X3Ic3q30MQuACWpAXjktUtUIdWwwluKc=; b=riMwtk1H2wsnYgevFyWPxi9JewosiJEN/jC29P0gqihIKf7jPJ99Ga0L8noszm+KS2 0UbMb8cPAKHDzGwoJjV9pdg+lH64noUf1HTWSfCRkqoBdTIXmGlDni/lchLWpLMzVa4i w304TaYTzUBiAqDlFHuPRyqjkuJKNgOlXVDT0yEjiki3Ymz9B3aE8pdI+bJs88aSfgl4 DVMbBIIK56qkT8BHMT1WEdrxVsgFs2f3Tf/OZ7v9gfn/1QuVtPejgjb45FUmkHFkqCPS 8r3PHU3+kqBHV/sa2E4TVwJTszkdeeMT9w8x2CDn8Igg2aieaHjDOAjOc5hUnRldZwDN odew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qaddUt6g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id w6si820828qki.311.2020.04.01.02.49.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:49:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qaddUt6g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0K-0007co-5u for patch@linaro.org; Wed, 01 Apr 2020 05:49:48 -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-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+patch=linaro.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(-) -- 2.20.1 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: 185133 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp328764ilr; Wed, 1 Apr 2020 02:48:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtsv2cIW/oWOusjYgs4J/DppJ4ECM9n8OlFOgLT4G/GC4BsmWj/1d0PD8dX5/j7YY+bqZbG X-Received: by 2002:aed:3383:: with SMTP id v3mr9480003qtd.177.1585734505584; Wed, 01 Apr 2020 02:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734505; cv=none; d=google.com; s=arc-20160816; b=IjQyUDtRxfHPUfPUfyk8xCn6j+n76PpDz5Es99ZhnMcCamXjD3Uiju0mx753F+wMne FxYyKnM1LfYaIeimB4eH32c0QdwnTGna1t0Kr+V565LmDLvtuVgbMAqgJ2q2r/JpGvhs vqvKvgFdDfQI8VGbMU1I7+gtaO23iEPhc8rVzJL8OD9l1U/8Byvm418b8P3oFuMKO1Ee atthtH3lGZ2x6JDh/KptGNYOMQ7owFcDEMubbFAaZa40Zp7maPSnUVViUjfb3XE9HMVy 4CxGFl3UV8rWb3yyn07EwocbSGR2mG3DPnw+KyxMdxs+g4ww1O02TKK6/mLPGuxbz5DB iXsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=h75bfILekusPXGlQBXuZSQUYvT0dH6xycgkUfP0rfEE=; b=Q1m3AicE6oVl073b3XElUqBF9dfDPJDviWhRuQGErqokSJLm5d1HEZ9+xXLVuOkC4V YTr08ELRehTdH21CSnSzOKMQ5WxbHTXQH9Xq+DAIiAbXz8wUPRh1jASoYUqEnebCzzC6 mSJvNDW+zwdQd1Q2F0ZK0i4cQj/f/Qn/huDn6XdWXNKqD4VMxay1js4lDs2Avey0aGx1 /1rJ/IabSe/S95qFxcsOX+HOkdHcASODOozfVl+F1OHSWi64UKwsbW4BXiBLIPJRtzRF KPriNkwHTZ7vMH5jfxLycmryejQ9MqggLN5aMZ3lY5WxGZZKHb7ri0XRqmJC0ZzwX6eZ SreA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RMProAHX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i10si555433qtj.121.2020.04.01.02.48.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:48:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RMProAHX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJZyz-0004QT-2m for patch@linaro.org; Wed, 01 Apr 2020 05:48:25 -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-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+patch=linaro.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 --- target/xtensa/translate.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.20.1 Acked-by: Max Filippov 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: 185140 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp331160ilr; Wed, 1 Apr 2020 02:51:39 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvalocy0BgNah6B9F/a/SfAoreDkVirNp9ZJ4HzLyvpdSj9NdS6Q56+0IBQO7LkmkuCuhT4 X-Received: by 2002:ac8:1b46:: with SMTP id p6mr9542044qtk.369.1585734699069; Wed, 01 Apr 2020 02:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734699; cv=none; d=google.com; s=arc-20160816; b=Sn5BNHk51r12jpXdoUKIxJAoOZvD80goGqjmu40ITsb5G5Z1r0oz5CrBRpok5Ef5i1 6ChsdHYZ8VS8GcbQVOBHjRxWcScJsqS8jmJKyQuTHcOwXllbriTf7HI/wy0byurseV/6 txn8oCCN7gk5cxD32WZJjHSulta9n6BfNULE5oDr7Xe0BdCtQpyWmu9gZQ8pI5PbZO+3 0ABUzwY9e2FgLo7P8fuFA7FrhPTtp/Lwlm7zjKReUXeauWUgVGGhqkXcusHyuDuTJaOb 2M/3r3Ype5AeqZAPJ2KubRtUEUJE4JRRX3c7133JDjeyWjF6MGNh2BnWfuZb4d3k39lV G3uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=IiHiPfqSf5RxTYVWG0ZPN64iJbsFrXxtKKLhTgnCXm4=; b=ZfvRx+MmZtHFvXeMoaWtb0cNHrnIeefPt2iwd7SV1QuYjyioWnsa60xT+qpdF//viz IXhcDaiAMvGgTOJZutrZJC+wa468EpJWCrjVtj6wAfb2038OnzS6fIzilpyx3PJDk71D Q1hBxkteszDYrYh1Yt7xDRbzYMrB228b8CuPU155cFc3MtBxzjoIP9yrDHHzG6j4B0Tq E7oCxZDvPwaACn3JqvmDJwwEy8vmdY6RFsCmGQsaLazRf+B/ZDR1uNofO3B+dXAgR25F J/EXe7o2LoVCeQ+KS4JpEw4AjnHC4Z3HNjoI2ZW6FjR+CTBI8v6tQGL3b1MoJ1iTNgj8 KKNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=o4vYVVwe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v18si786911qvh.173.2020.04.01.02.51.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:51:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=o4vYVVwe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa26-0002xi-Kq for patch@linaro.org; Wed, 01 Apr 2020 05:51:38 -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-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+patch=linaro.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(-) -- 2.20.1 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: 185137 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp329883ilr; Wed, 1 Apr 2020 02:49:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtN+ladMtjbvsB0qogLcO5S2JX/pQxK6J/R6r2iLLa+iAkkevaE2vtgN5MZgR2xFKEhwoA9 X-Received: by 2002:aed:2822:: with SMTP id r31mr9225382qtd.87.1585734594586; Wed, 01 Apr 2020 02:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734594; cv=none; d=google.com; s=arc-20160816; b=jcd4gVIa7fSkHAFahqjd2Iclk+JZBAX1pqghVEpQeLBLHK5Ngp7mtBnAZxme1TCjfO wmeWVpb+/m6kNjdTJjK43bmPEOZfBtpjEAp9dqunOSo2BT7wsHG/CTz4W/xO4TjQ9kG7 whIU6twHd4yL4/tTNrflp3AG91NN/iKRHnNFqBi7e56Fr+b9pOr/bYux6+OJu5g5fJI0 WNCVEv0bzTKd3hNUw8iz14dd5mnj02WUQ93dqTS0d4AwAUW4WRp9x0OqxPjQMY/RmExJ 9NZToXTWr1ukOnMDOZE5TswB+ZEK0SfnkeChf9eWiQ9lJ3Ot+s8Eai+T92IDOm+wvPKu M5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=g9xr3EL2jz3uIXqebGO8vaQXLJoFQmUrqrOGsA7SE/w=; b=U41D0pZKdG/5Kmn/2wtxxJKi9pATIJD4aLcOngRJwiGEBV4/AbCJk9z01kvXUW7Y1Q Ae0Kcz8QGMiBqCq4Tile0YXkSP+MEQ0uhsV9S7HwMHQD4fBfpG/6m8SuEy/2ygX8dVwA j1EgiWUGF5tjrt4i+4PZnnNpLy5co2gnnPbHldsT8EpMBEIlGEDasducV2dx6NjT7QaA E0rqfUJMrjbupgGFBenlArWAiwfYkPXYAr1K/NU8c6K50YOq1Y3Oh4rVxbdvgSWkXhwz ujEcG+v67okeMWq+5XU45HKO62tkyp6jm9Ywtuh/iYX3KlskS9BrP+eQWBoRnaQHK3TI CZ/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jQAatAea; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o8si757843qvu.87.2020.04.01.02.49.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:49:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jQAatAea; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa0Q-0007t1-1l for patch@linaro.org; Wed, 01 Apr 2020 05:49:54 -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-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+patch=linaro.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(+) -- 2.20.1 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: 185138 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp330972ilr; Wed, 1 Apr 2020 02:51:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvTJ1+gIqC545kKhg//uE/6J8ThVpLoRZgfegIwCAoSQ8SUYIQ0rCJ8POabqkyUIwxfUyVT X-Received: by 2002:a37:9b51:: with SMTP id d78mr9273780qke.65.1585734685838; Wed, 01 Apr 2020 02:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734685; cv=none; d=google.com; s=arc-20160816; b=z6fj7uxOX/oYLTb+kFxVcQY39TvkzPr83UlINAeH4kNQeIIEUz7LKBvwBL5kyW+cQK 2gOjHPZmVH07sVBzENv8n+d6rAMU/yeLShh2rnyOxrM61riYCJTH23RbvumLFebFCMJe wMguKaVrXNvzAp+BIJ1pYPJCGdPnQf9wYUBwWK0sQb/arS/oijt2+DRoV51V1ttQesxQ pI0EYNnAikcmALkyMGjckbaFHnnKTiIPGXcVZCVa52Diwxea5HENKBms6Ni4/Pqu7oz/ xID525GRLzXIr4MPa1wf3mMbaF22CrdlZsBKk3H/p5Qkzw1fZvEoNi0hbh2rWF1kHTXF agFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=a5n4+mCgHjpSYN+9AuOFcTGtUw1azSmiJDpjSXdf7Wc=; b=RQQRDOvokVzU5Mgy7HRndgTKpcMw0OhOwqRklJejvGwv0Mm08/yI8hmvm36V1IXxpl YSMGjlECoSPCwJDPP5kxiql7sSPWUUU+cqRoB5McYqKFS44iVgVtVAvB/eIR3dyIORBt oqeVVzZYATBZIBAAOvKXqhcpPgDLnOczzOCnZ5i0dkOhsmueDX2KJ7bx/Z9gFcK46XKW sG7RaL7LeE9iMtxbSff7tCfkZTQm2miW/AXjtr8e1TtjMwMTg7A9zttR061y3s/aaCHq aiYhdVnKmhBdaR9zFIR9PGCVsgdZMKmP7e/Wb/HAzUWGkIha8/Crv3h++6iaCfwGHqCT pAUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aZ0z0rc/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g15si737765qka.307.2020.04.01.02.51.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:51:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="aZ0z0rc/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa1t-0002fa-80 for patch@linaro.org; Wed, 01 Apr 2020 05:51:25 -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-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+patch=linaro.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 -- 2.20.1 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: 185139 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp331148ilr; Wed, 1 Apr 2020 02:51:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIuMU4Y0tVaSfIBJwKrfW5rnFZ0WgUDLXWeaichJenPCp5sSqSMPGRniewRcuIT6Y1OmVT6 X-Received: by 2002:aed:24b2:: with SMTP id t47mr3559432qtc.317.1585734697855; Wed, 01 Apr 2020 02:51:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734697; cv=none; d=google.com; s=arc-20160816; b=hoij4JQYuf8iHg10UodzBBQQsXSNoihlEHEzE8p3jG7diqUW1ipjINaYfLp6dI0KD7 sGMYCjflRLLQwGDjwt3VifabmeirYgriJFa9Z2ZAwjNgPghlPLLjzkTIkAkW9fRURiM7 bT2HdD4gbXXwoMSIdQ0iUh5+IQkZCD1HwcIpndVg5DNL5MWYvnUyHzQ2pX9zeXHly3vC FIKzoNx2X3ILSPf0oodPObvaMVutftdOUF0k8Bjtfde4mNzyCPQ+25tvEKjzDF5xo64f 5PdnlQVG+n2ExWRjRuhJW/8Gb8zUFVWh4ubOmaA8b/5z3hLAI5Ice6JdMJteRyK8MOVP 6/Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WLTsGPoiyiZpQWSAjDx1Jd/3OsKOnqyDSFWAME1qJxU=; b=LB8y50vr++yV5Eink7sO2YzJtFPLTHz8Etxle8yP9u1AsVsmngu/Ut6MixH/KhYre3 rnNDsBh6sxdFS0mnctBGTQwCUJcshSxbAKq+aDnxGE21fSmPkwYFwcyT0zqXiuTiXu9V QRpmAnsPW72vmbe4zDbe4d+7xgXgSbABsp0cezsx0sfrQzr/rfJ3kMyupjG1560ehYv+ EzkMgateB++En4JAzqANDVeV9Gf23aF1FDMlsAFPMkfDxzIRlUzo/47/m8Fv3tfaU8Wt hbS+tLUsiwvLQXH5QGSdtztEwj0KN0T+eDNE9Xe9I4p9SI71L3ddBRGXJUfVcrhcE2lq aZRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Bho9PpvI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e18si796597qkm.379.2020.04.01.02.51.37 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:51:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Bho9PpvI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa25-0002u3-Ap for patch@linaro.org; Wed, 01 Apr 2020 05:51:37 -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-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+patch=linaro.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 --- linux-user/syscall.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) -- 2.20.1 Reviewed-by: Richard Henderson 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: 185141 Delivered-To: patch@linaro.org Received: by 2002:a92:de47:0:0:0:0:0 with SMTP id e7csp332258ilr; Wed, 1 Apr 2020 02:53:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsnDAJzjciMDffWDNuP3hbBDfQdU8umpuuwSuXcUQnZRZ01ORu8wXmpvS/chQ/ik3lMQXiS X-Received: by 2002:ac8:7253:: with SMTP id l19mr9606185qtp.241.1585734792212; Wed, 01 Apr 2020 02:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585734792; cv=none; d=google.com; s=arc-20160816; b=jxgr2Nk+LytBnLqJ0ezBr1aS4bNIFfAUPLECz+UIOhlBmYCdZLHop2yuYWiNUoGQPd Hoq0HWmtoXusoF4sH1lY3JZatVJ+TqCmTBx/dW9T/qS0lPoXMjHeBYg8Z8EJWj3w5Y30 1lKn1ZWpPrl/209LIuO54JJyfkZdaa+BbEWPmFWuR1AdY3X8qhWmXLaP/ZtGENVdA+jQ rmqZxvDVqyFQUN5k5zaasLUkQ60Nkzk8I3pgdvq8Wzodd2Qlv6tfSIfdLBvGIg+OnIfb pXJvw+R5LQjLO7eA7Vvac4oBlXy+YQREOytwITjM0VbnMqY+dJnXRK67Jzu2CAV8eOTM PPug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=wiruPLRzIVKr/sqR3IRGFAA55bADwbShqW9FNeJTSKM=; b=VUCRRIl2LUtjuai3JYJ4C1qBeAcpdiA5BCl3/kVUyAnTi8Y93PetClTVeD89aspeaz XBLTEci9gjJHSH6EYQHPjooUZN+4Vez4QQBYTGkV7Foc34/AFYipiXmh0yyoCvyaU8mt x/kAGpOIA3oSvEnNZ8aEysRTgwICvr6fl47hGNfZ4zvLd8NLApwS5JK0LxlAP93gC7Uc ntWinrz+8pAZndyPRaQzpgckQVE3b0LwaTTFw851UiICrHi4vgXiRk/1KUO0JHnYFCd5 zKtojLiPnxKOzKwZB72pHfQilYmZigDhZQhqw/y1IDgJIW02psPp5OvgY492IAFR4efC bjKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NUOTNK2F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c5si784990qvb.182.2020.04.01.02.53.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 01 Apr 2020 02:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NUOTNK2F; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJa3b-0004np-NW for patch@linaro.org; Wed, 01 Apr 2020 05:53:11 -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-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+patch=linaro.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(-) -- 2.20.1 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,