* [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st
@ 2018-04-27 12:17 Laurent Vivier
2018-04-27 12:28 ` Laurent Vivier
0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2018-04-27 12:17 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Richard Henderson
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st
2018-04-27 12:17 [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st Laurent Vivier
@ 2018-04-27 12:28 ` Laurent Vivier
0 siblings, 0 replies; 2+ messages in thread
From: Laurent Vivier @ 2018-04-27 12:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Richard Henderson
On 27/04/2018 14:17, Laurent Vivier wrote:
> 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...),
I think the number of slow path functions cannot be greater than
TCG_MAX_INSNS (i.e. 512): is it enough to overflow the stack?
Thanks,
Laurent
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-27 12:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-27 12:17 [Qemu-devel] [RFC] tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st Laurent Vivier
2018-04-27 12:28 ` Laurent Vivier
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).