qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st
Date: Fri, 27 Apr 2018 14:17:23 +0200	[thread overview]
Message-ID: <20180427121723.3543-1-lvivier@redhat.com> (raw)

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 <lvivier@redhat.com>
---

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);
 
-static bool tcg_out_ldst_finalize(TCGContext *s)
+static bool tcg_out_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
 {
-    TCGLabelQemuLdst *lb;
+    bool ret;
 
-    /* qemu_ld/st slow paths */
-    for (lb = s->ldst_labels; lb != NULL; lb = lb->next) {
+    if (lb == NULL) {
+        return true;
+    }
+
+    ret = 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 = (void *)s->code_ptr <= 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);
 }
 
 /*
-- 
2.14.3

             reply	other threads:[~2018-04-27 12:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-27 12:17 Laurent Vivier [this message]
2018-04-27 12:28 ` [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180427121723.3543-1-lvivier@redhat.com \
    --to=lvivier@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).