From patchwork Tue Mar 13 17:33:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 885396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4013Qx1wSZz9sTD for ; Wed, 14 Mar 2018 05:34:00 +1100 (AEDT) Received: from localhost ([::1]:41933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evokG-0001dO-Uw for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2018 14:33:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evnog-00006G-GB for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:34:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evnof-0007xn-Dp for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:34:26 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:43703) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evnof-0007wf-2b for qemu-devel@nongnu.org; Tue, 13 Mar 2018 13:34:25 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue005 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MgaRP-1fJoTV0Un1-00Nzu3; Tue, 13 Mar 2018 18:34:10 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 18:33:53 +0100 Message-Id: <20180313173355.4468-17-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313173355.4468-1-laurent@vivier.eu> References: <20180313173355.4468-1-laurent@vivier.eu> X-Provags-ID: V03:K0:zGJAQ8Cbz5XtDsMSMhzO7P9w1HGyJv6+9qFI8n7NlS9iVPPFr7X Pgz9yN8gijCJBFYCjMs5POBSwdz3cpBm9cDrihEPe1j4ciaKEHz4wvUBH574svCJVc8pHjY IdHBetBWKfAO/3d93cep1S0hFObjlyr2FHHjf4DyydJX8iPHCe4yUzrjt6tBr24WTMtM9Ca ovjrx8G9geKR2H8x50X7A== X-UI-Out-Filterresults: notjunk:1; V01:K0:MUqVxN16ExQ=:PV3BL6B7mN0FubKvZ+3JO6 +KNzrlAyT3h5Da5wLx4Cw2uH1KhtmQ3Ou3N5OvOwCvxybhCXMVl5qqEjtdzc481IKqNeADkgl Wt1RT6Ai1iXHvmTSg4kcp3DYRHXxpecLDz5dZxrDvQGFoJrYlQ6pnl/CApuuT2HXTj6exxS0g GUZpUQbUmQKGvXUgI+jIEO6YRw1rWTYZWDRB10Jh8H9ycjdW+KJvee39Alh88oQnhkac/1LOr Mu4W6yMHqZBx0SMt+yjIOKjR8RRjJQLBUwOo34opXrU+iCUiEDDIDd4QOszYPHCRcg2ZYz7yq SOdkNIe3aHBQuH28+QqXURkdJFz9CizT5hGmv32GNEPaFIzVEWqSVvi/1QsO7TP6VgGxsZscw s3lvOCT5bcuc5c2QF4l2Xo3LpLty25EjxXV0t3TMJ7PFLw83Hohnt/pX3+GVRorqGdSmUrQSt w3/HqAJC85UTedKV8TSy8mOLQg8ZGSJgmGJ2EOfAakQhxmJeY36lN5kZ0LhlbLR2NuTupkiCO lcIt7imp0+QUcPOAROA8iRm5R7REG9/gAlV7Gsj1tccGcJVrelGs1hV7QXhJeXftSTRCco8TY kKehiREeTKuXVRA3jlh8YuV9z1UL2ouwkLQ4VF+DCmwPIdqMvcIHdnT8RafnH3v8jn5qHklaw H5LlK7gFw9HF4qt3qB2XB9yJ3qHWJ/oztuaK5ZtiAzA78i7yu7a+LQlbCq4iY9IqzceKJwgd5 M32w7sADd4h+8TgHLHwnjaVJl8DfC+X4kX4P1A== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.131 Subject: [Qemu-devel] [PULL 16/18] linux-user: init_guest_space: Clean up control flow a bit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Luke Shumaker , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Luke Shumaker Instead of doing if (check1) { if (check2) { success; } } retry; Do a clearer if (!check1) { goto try_again; } if (!check2) { goto try_again; } success; try_again: retry; Besides being clearer, this makes it easier to insert more checks that need to trigger a retry on check failure, or rearrange them, or anything like that. Because some indentation is changing, "ignore space change" may be useful for viewing this patch. Signed-off-by: Luke Shumaker Message-Id: <20171228180814.9749-8-lukeshu@lukeshu.com> Reviewed-by: Peter Maydell [lv: modified to try again fi valid == 0, not valid == -1 (error case)] Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8699f430b1..c6491a8d35 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1880,24 +1880,28 @@ unsigned long init_guest_space(unsigned long host_start, } /* Check to see if the address is valid. */ - if (!host_start || aligned_start == current_start) { + if (host_start && aligned_start != current_start) { + goto try_again; + } + #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) { - break; - } else if (valid == -1) { - munmap((void *)real_start, real_size); - return (unsigned long)-1; - } - /* valid == 0, so try again. */ -#else - /* On other architectures, whatever we have here is fine. */ - break; -#endif + /* 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); + 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