From nobody Wed Oct 29 06:41:46 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524831527434365.3414176995003; Fri, 27 Apr 2018 05:18:47 -0700 (PDT) Received: from localhost ([::1]:47760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fC2Ki-0006cZ-D7 for importer@patchew.org; Fri, 27 Apr 2018 08:18:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fC2Jl-0006Fy-Lm for qemu-devel@nongnu.org; Fri, 27 Apr 2018 08:17:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fC2Ji-0000Ao-Gp for qemu-devel@nongnu.org; Fri, 27 Apr 2018 08:17:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44952 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fC2Ji-0000Ac-Cc for qemu-devel@nongnu.org; Fri, 27 Apr 2018 08:17:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AA7C42709C0; Fri, 27 Apr 2018 12:17:29 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-116-184.ams2.redhat.com [10.36.116.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id C36E06F9E6; Fri, 27 Apr 2018 12:17:24 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 27 Apr 2018 14:17:23 +0200 Message-Id: <20180427121723.3543-1-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 27 Apr 2018 12:17:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 27 Apr 2018 12:17:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lvivier@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st 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: Laurent Vivier , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" ppc64 uses a BC instruction to call the tcg_out_qemu_ld/st slow path. BC instruction uses a relative address encoded on 14 bits. The slow path functions are added at the end of the generated instructions buffer, in the reverse order of the callers. So more we have slow path functions more the distance between the caller (BC) and the function increases. This patch changes the behavior to generate the functions in the same order of the callers. Fixes: 15fa08f845 ("tcg: Dynamically allocate TCGOps") Signed-off-by: Laurent Vivier --- Notes: This is an RFC for several reasons: - it doens't really fix the overflow problem only avoids the case - it uses a recursive function to revert the slow path functions order (and we can have a stack overflow...), tcg/tcg-ldst.inc.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tcg/tcg-ldst.inc.c b/tcg/tcg-ldst.inc.c index 0e14cf4357..1f41cda482 100644 --- a/tcg/tcg-ldst.inc.c +++ b/tcg/tcg-ldst.inc.c @@ -41,12 +41,16 @@ typedef struct TCGLabelQemuLdst { static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l); static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l); =20 -static bool tcg_out_ldst_finalize(TCGContext *s) +static bool tcg_out_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) { - TCGLabelQemuLdst *lb; + bool ret; =20 - /* qemu_ld/st slow paths */ - for (lb =3D s->ldst_labels; lb !=3D NULL; lb =3D lb->next) { + if (lb =3D=3D NULL) { + return true; + } + + ret =3D tcg_out_slow_path(s, lb->next); + if (ret) { if (lb->is_ld) { tcg_out_qemu_ld_slow_path(s, lb); } else { @@ -57,11 +61,16 @@ static bool tcg_out_ldst_finalize(TCGContext *s) one operation beginning below the high water mark cannot overrun the buffer completely. Thus we can test for overflow after generating code without having to check during generation. */ - if (unlikely((void *)s->code_ptr > s->code_gen_highwater)) { - return false; - } + ret =3D (void *)s->code_ptr <=3D s->code_gen_highwater; } - return true; + + return ret; +} + +static bool tcg_out_ldst_finalize(TCGContext *s) +{ + /* qemu_ld/st slow paths */ + return tcg_out_slow_path(s, s->ldst_labels); } =20 /* --=20 2.14.3