* [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging
@ 2008-10-29 19:31 Blue Swirl
2008-10-29 19:53 ` Paul Brook
2008-10-29 21:37 ` [Qemu-devel] " Fabrice Bellard
0 siblings, 2 replies; 12+ messages in thread
From: Blue Swirl @ 2008-10-29 19:31 UTC (permalink / raw)
To: Fabrice Bellard, qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 467 bytes --]
Hi,
When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
one and vice versa. This patch adds a run time sanity check for TCGv
sizes.
Because a 32 bit Qemu host does not really use 64 bit TCGvs, the patch
is only functional on a 64 bit host. Of course also a pure 32 bit Qemu
target is not likely to suffer from TCGv size confusion.
Some use cases are not covered yet. Comments?
[-- Attachment #2: runtime_tcgv_size_check.diff --]
[-- Type: plain/text, Size: 15798 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 19:31 [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging Blue Swirl
@ 2008-10-29 19:53 ` Paul Brook
2008-10-29 20:06 ` Blue Swirl
2008-10-29 21:37 ` [Qemu-devel] " Fabrice Bellard
1 sibling, 1 reply; 12+ messages in thread
From: Paul Brook @ 2008-10-29 19:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Blue Swirl
On Wednesday 29 October 2008, Blue Swirl wrote:
> Hi,
>
> When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> one and vice versa. This patch adds a run time sanity check for TCGv
> sizes.
Would it make more sense to push these down into tcg_gen_op* ?
tcg-op.h is already fairly unwieldy.
I wonder if it's worth adding TCG_LOW to enable checking on 32-bit hosts.
For futureproofing I'd name things FOO_I32 rather than FOO_32.
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 19:53 ` Paul Brook
@ 2008-10-29 20:06 ` Blue Swirl
2008-10-29 20:14 ` Paul Brook
0 siblings, 1 reply; 12+ messages in thread
From: Blue Swirl @ 2008-10-29 20:06 UTC (permalink / raw)
To: Paul Brook; +Cc: qemu-devel
On 10/29/08, Paul Brook <paul@codesourcery.com> wrote:
> On Wednesday 29 October 2008, Blue Swirl wrote:
> > Hi,
> >
> > When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> > the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> > one and vice versa. This patch adds a run time sanity check for TCGv
> > sizes.
>
>
> Would it make more sense to push these down into tcg_gen_op* ?
How? At that point we don't know what was the correct size.
> tcg-op.h is already fairly unwieldy.
True, and as debugging TCGv will not be common, I'm not sure whether
the patch is worth committing.
> I wonder if it's worth adding TCG_LOW to enable checking on 32-bit hosts.
>
> For futureproofing I'd name things FOO_I32 rather than FOO_32.
Good point, will fix.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 20:06 ` Blue Swirl
@ 2008-10-29 20:14 ` Paul Brook
2008-10-29 20:25 ` Blue Swirl
0 siblings, 1 reply; 12+ messages in thread
From: Paul Brook @ 2008-10-29 20:14 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
On Wednesday 29 October 2008, Blue Swirl wrote:
> On 10/29/08, Paul Brook <paul@codesourcery.com> wrote:
> > On Wednesday 29 October 2008, Blue Swirl wrote:
> > > Hi,
> > >
> > > When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> > > the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> > > one and vice versa. This patch adds a run time sanity check for TCGv
> > > sizes.
> >
> > Would it make more sense to push these down into tcg_gen_op* ?
>
> How? At that point we don't know what was the correct size.
I figure there's only a handful of different cases, so it'll be cleaner to
introduce tcg_gen_op_i32_i32 etc. which trivially reduce to tcg_gen_op2 when
debugging is disabled.
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 20:14 ` Paul Brook
@ 2008-10-29 20:25 ` Blue Swirl
0 siblings, 0 replies; 12+ messages in thread
From: Blue Swirl @ 2008-10-29 20:25 UTC (permalink / raw)
To: Paul Brook; +Cc: qemu-devel
On 10/29/08, Paul Brook <paul@codesourcery.com> wrote:
> On Wednesday 29 October 2008, Blue Swirl wrote:
> > On 10/29/08, Paul Brook <paul@codesourcery.com> wrote:
> > > On Wednesday 29 October 2008, Blue Swirl wrote:
> > > > Hi,
> > > >
> > > > When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> > > > the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> > > > one and vice versa. This patch adds a run time sanity check for TCGv
> > > > sizes.
> > >
> > > Would it make more sense to push these down into tcg_gen_op* ?
> >
> > How? At that point we don't know what was the correct size.
>
>
> I figure there's only a handful of different cases, so it'll be cleaner to
> introduce tcg_gen_op_i32_i32 etc. which trivially reduce to tcg_gen_op2 when
> debugging is disabled.
Now I see. I'll try that next.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 19:31 [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging Blue Swirl
2008-10-29 19:53 ` Paul Brook
@ 2008-10-29 21:37 ` Fabrice Bellard
2008-10-30 0:07 ` Paul Brook
1 sibling, 1 reply; 12+ messages in thread
From: Fabrice Bellard @ 2008-10-29 21:37 UTC (permalink / raw)
To: Blue Swirl; +Cc: qemu-devel
Blue Swirl wrote:
> Hi,
>
> When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> one and vice versa. This patch adds a run time sanity check for TCGv
> sizes.
>
> Because a 32 bit Qemu host does not really use 64 bit TCGvs, the patch
> is only functional on a 64 bit host. Of course also a pure 32 bit Qemu
> target is not likely to suffer from TCGv size confusion.
>
> Some use cases are not covered yet. Comments?
Theses tests can be done at compile time by introducing the TCGv_i32 and
TCGv_i64 types. The same can be done with the helpers by using a few
macros to declare them.
A optional runtime check would be still useful as an additional pass
using the OP definitions to ensure that the TCG optimizations pass(es)
are OK. IMHO, doing it only in tcg_gen_xxx is not enough.
Fabrice.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-10-29 21:37 ` [Qemu-devel] " Fabrice Bellard
@ 2008-10-30 0:07 ` Paul Brook
2008-10-30 9:38 ` Fabrice Bellard
0 siblings, 1 reply; 12+ messages in thread
From: Paul Brook @ 2008-10-30 0:07 UTC (permalink / raw)
To: qemu-devel; +Cc: Blue Swirl
On Wednesday 29 October 2008, Fabrice Bellard wrote:
> Blue Swirl wrote:
> > Hi,
> >
> > When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> > the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> > one and vice versa. This patch adds a run time sanity check for TCGv
> > sizes.
> >
> > Because a 32 bit Qemu host does not really use 64 bit TCGvs, the patch
> > is only functional on a 64 bit host. Of course also a pure 32 bit Qemu
> > target is not likely to suffer from TCGv size confusion.
> >
> > Some use cases are not covered yet. Comments?
>
> Theses tests can be done at compile time by introducing the TCGv_i32 and
> TCGv_i64 types. The same can be done with the helpers by using a few
> macros to declare them.
That would also require updating all the target code in translate.c to use
these types. In principle there's no reason why this couldn't be done, but
it'd be a much more invasive change.
AFAIK there's no way of doing compile time inheritance checking in C.
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-10-30 0:07 ` Paul Brook
@ 2008-10-30 9:38 ` Fabrice Bellard
2008-11-01 12:00 ` Blue Swirl
0 siblings, 1 reply; 12+ messages in thread
From: Fabrice Bellard @ 2008-10-30 9:38 UTC (permalink / raw)
To: Paul Brook; +Cc: Blue Swirl, qemu-devel
Paul Brook wrote:
> On Wednesday 29 October 2008, Fabrice Bellard wrote:
>> Blue Swirl wrote:
>>> Hi,
>>>
>>> When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
>>> the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
>>> one and vice versa. This patch adds a run time sanity check for TCGv
>>> sizes.
>>>
>>> Because a 32 bit Qemu host does not really use 64 bit TCGvs, the patch
>>> is only functional on a 64 bit host. Of course also a pure 32 bit Qemu
>>> target is not likely to suffer from TCGv size confusion.
>>>
>>> Some use cases are not covered yet. Comments?
>> Theses tests can be done at compile time by introducing the TCGv_i32 and
>> TCGv_i64 types. The same can be done with the helpers by using a few
>> macros to declare them.
>
> That would also require updating all the target code in translate.c to use
> these types. In principle there's no reason why this couldn't be done, but
> it'd be a much more invasive change.
If you define TCGv as the word size of the emulated CPU, it will
eliminates most of the changes.
> AFAIK there's no way of doing compile time inheritance checking in C.
Fabrice.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-10-30 9:38 ` Fabrice Bellard
@ 2008-11-01 12:00 ` Blue Swirl
2008-11-01 12:59 ` Paul Brook
0 siblings, 1 reply; 12+ messages in thread
From: Blue Swirl @ 2008-11-01 12:00 UTC (permalink / raw)
To: Fabrice Bellard; +Cc: Paul Brook, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1875 bytes --]
On 10/30/08, Fabrice Bellard <fabrice@bellard.org> wrote:
> Paul Brook wrote:
> > On Wednesday 29 October 2008, Fabrice Bellard wrote:
> >> Blue Swirl wrote:
> >>> Hi,
> >>>
> >>> When emulating a mixed 32/64 bit Qemu target CPUs it's easy to confuse
> >>> the TCGv size, passing 32 bit TCGv to a function expecting a 64 bit
> >>> one and vice versa. This patch adds a run time sanity check for TCGv
> >>> sizes.
> >>>
> >>> Because a 32 bit Qemu host does not really use 64 bit TCGvs, the patch
> >>> is only functional on a 64 bit host. Of course also a pure 32 bit Qemu
> >>> target is not likely to suffer from TCGv size confusion.
> >>>
> >>> Some use cases are not covered yet. Comments?
> >> Theses tests can be done at compile time by introducing the TCGv_i32 and
> >> TCGv_i64 types. The same can be done with the helpers by using a few
> >> macros to declare them.
> >
> > That would also require updating all the target code in translate.c to use
> > these types. In principle there's no reason why this couldn't be done, but
> > it'd be a much more invasive change.
>
>
> If you define TCGv as the word size of the emulated CPU, it will
> eliminates most of the changes.
This version introduces TCGv_i32 and TCGv_i64. TCGv_ptr and TCGv (TL
sized) are based on them.
For Sparc, the patch is very invasive (I just commented out the
helpers to avoid that part) but I think i386 would need much smaller
changes.
With the patch, I found some bugs in Sparc translation. I'm not sure
what to do with helpers, there should be a way to declare the size of
the arguments somehow and then the calling should be easier than:
tcg_gen_helper_1_4_i64_tl_i32_i32_i32(helper_ld_asi, dst, addr, r_asi,
r_size, r_sign);
Otherwise, I think only some variant of the TCGV_LOW parts are worth
committing, they make the code slightly more easy to understand.
[-- Attachment #2: compile_time_tcgv_size_check.diff.bz2 --]
[-- Type: application/x-bzip2, Size: 14840 bytes --]
[-- Attachment #3: sparc_tcgv_size_fixes.diff --]
[-- Type: plain/text, Size: 6657 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-11-01 12:00 ` Blue Swirl
@ 2008-11-01 12:59 ` Paul Brook
2008-11-01 16:56 ` Paul Brook
0 siblings, 1 reply; 12+ messages in thread
From: Paul Brook @ 2008-11-01 12:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Blue Swirl
> This version introduces TCGv_i32 and TCGv_i64. TCGv_ptr and TCGv (TL
> sized) are based on them.
This is looking good to me.
> For Sparc, the patch is very invasive (I just commented out the
> helpers to avoid that part) but I think i386 would need much smaller
> changes.
>
> With the patch, I found some bugs in Sparc translation. I'm not sure
> what to do with helpers, there should be a way to declare the size of
> the arguments somehow and then the calling should be easier than:
> tcg_gen_helper_1_4_i64_tl_i32_i32_i32(helper_ld_asi, dst, addr, r_asi,
> r_size, r_sign);
I think we can build some infrastructure to make helpers easier to handle.
It should be relatively mechanical changes to the existing helper[s].h. ARM
and m68k already do this, though need a bit more work to get static
typechecking. All the information it there's it's just not quite in the
right form. I'll see if I can dig out the CPP magic required for this.
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-11-01 12:59 ` Paul Brook
@ 2008-11-01 16:56 ` Paul Brook
2008-11-01 17:03 ` Blue Swirl
0 siblings, 1 reply; 12+ messages in thread
From: Paul Brook @ 2008-11-01 16:56 UTC (permalink / raw)
To: qemu-devel; +Cc: Blue Swirl
> > With the patch, I found some bugs in Sparc translation. I'm not sure
> > what to do with helpers, there should be a way to declare the size of
> > the arguments somehow and then the calling should be easier than:
> > tcg_gen_helper_1_4_i64_tl_i32_i32_i32(helper_ld_asi, dst, addr, r_asi,
> > r_size, r_sign);
>
> I think we can build some infrastructure to make helpers easier to handle.
> It should be relatively mechanical changes to the existing helper[s].h.
> ARM and m68k already do this, though need a bit more work to get static
> typechecking. All the information it there's it's just not quite in the
> right form. I'll see if I can dig out the CPP magic required for this.
I've got something that works. Any chance you could resend you patch with a
signed-off-by line so I can do the integration?
Paul
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] Re: [PATCH][RFC] Run time TCGv size check for debugging
2008-11-01 16:56 ` Paul Brook
@ 2008-11-01 17:03 ` Blue Swirl
0 siblings, 0 replies; 12+ messages in thread
From: Blue Swirl @ 2008-11-01 17:03 UTC (permalink / raw)
To: Paul Brook; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 997 bytes --]
On 11/1/08, Paul Brook <paul@codesourcery.com> wrote:
> > > With the patch, I found some bugs in Sparc translation. I'm not sure
> > > what to do with helpers, there should be a way to declare the size of
> > > the arguments somehow and then the calling should be easier than:
> > > tcg_gen_helper_1_4_i64_tl_i32_i32_i32(helper_ld_asi, dst, addr, r_asi,
> > > r_size, r_sign);
> >
> > I think we can build some infrastructure to make helpers easier to handle.
> > It should be relatively mechanical changes to the existing helper[s].h.
> > ARM and m68k already do this, though need a bit more work to get static
> > typechecking. All the information it there's it's just not quite in the
> > right form. I'll see if I can dig out the CPP magic required for this.
>
>
> I've got something that works. Any chance you could resend you patch with a
> signed-off-by line so I can do the integration?
I don't trust these much, but anyway:
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
[-- Attachment #2: compile_time_tcgv_size_check.diff.bz2 --]
[-- Type: application/x-bzip2, Size: 14840 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2008-11-01 17:03 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-29 19:31 [Qemu-devel] [PATCH][RFC] Run time TCGv size check for debugging Blue Swirl
2008-10-29 19:53 ` Paul Brook
2008-10-29 20:06 ` Blue Swirl
2008-10-29 20:14 ` Paul Brook
2008-10-29 20:25 ` Blue Swirl
2008-10-29 21:37 ` [Qemu-devel] " Fabrice Bellard
2008-10-30 0:07 ` Paul Brook
2008-10-30 9:38 ` Fabrice Bellard
2008-11-01 12:00 ` Blue Swirl
2008-11-01 12:59 ` Paul Brook
2008-11-01 16:56 ` Paul Brook
2008-11-01 17:03 ` Blue Swirl
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).