All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
@ 2018-04-13 14:23 Peter Maydell
  2018-04-13 15:12 ` Michael S. Tsirkin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Peter Maydell @ 2018-04-13 14:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: patches, Michael S. Tsirkin, Richard Henderson, Aurelien Jarno,
	Yongbok Kim

The MIPS TCG target makes the assumption that the offset from the
target env pointer to the tlb_table is less than about 64K. This
used to be true, but gradual addition of features to the Arm
target means that it's no longer true there. This results in
the build-time assertion failing:

In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,
                 from /home/pm215/qemu/tcg/tcg.c:28:
/home/pm215/qemu/tcg/mips/tcg-target.inc.c: In function ‘tcg_out_tlb_load’:
/home/pm215/qemu/include/qemu/compiler.h:90:36: error: static assertion failed: "not expecting: offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff"
 #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg)
                                    ^
/home/pm215/qemu/include/qemu/compiler.h:98:30: note: in expansion of macro ‘QEMU_BUILD_BUG_MSG’
 #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)
                              ^
/home/pm215/qemu/tcg/mips/tcg-target.inc.c:1236:9: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
         QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
         ^
/home/pm215/qemu/rules.mak:66: recipe for target 'tcg/tcg.o' failed

An ideal long term approach would be to rearrange the CPU state
so that the tlb_table was not so far along it, but this is tricky
because it would move it from the "not cleared on CPU reset" part
of the struct to the "cleared on CPU reset" part. As a simple fix
for the 2.12 release, make the MIPS TCG target handle an arbitrary
offset by emitting more add instructions. This will mean an extra
instruction in the fastpath for TCG loads and stores for the
affected guests (currently just aarch64-softmmu).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This is sufficient that on MIPS host we can now at least build
and run an aarch64 guest kernel. I haven't tried 'make check'
because the only MIPS system I have access to is way too slow...

 tcg/mips/tcg-target.inc.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c
index 4b55ab8856..ca5f1d4894 100644
--- a/tcg/mips/tcg-target.inc.c
+++ b/tcg/mips/tcg-target.inc.c
@@ -1229,13 +1229,10 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
     tcg_out_opc_reg(s, ALIAS_PADD, TCG_REG_A0, TCG_REG_A0, TCG_AREG0);
 
     /* Compensate for very large offsets.  */
-    if (add_off >= 0x8000) {
-        /* Most target env are smaller than 32k; none are larger than 64k.
-           Simplify the logic here merely to offset by 0x7ff0, giving us a
-           range just shy of 64k.  Check this assumption.  */
-        QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
-                                   tlb_table[NB_MMU_MODES - 1][1])
-                          > 0x7ff0 + 0x7fff);
+    while (add_off >= 0x8000) {
+        /* Most target env are smaller than 32k, but a few are larger than 64k,
+         * so handle an arbitrarily large offset.
+         */
         tcg_out_opc_imm(s, ALIAS_PADDI, TCG_REG_A0, TCG_REG_A0, 0x7ff0);
         cmp_off -= 0x7ff0;
         add_off -= 0x7ff0;
-- 
2.16.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
  2018-04-13 14:23 [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table Peter Maydell
@ 2018-04-13 15:12 ` Michael S. Tsirkin
  2018-04-13 19:09 ` Richard Henderson
  2018-04-30 17:44 ` Alex Bennée
  2 siblings, 0 replies; 6+ messages in thread
From: Michael S. Tsirkin @ 2018-04-13 15:12 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, patches, Richard Henderson, Aurelien Jarno, Yongbok Kim

On Fri, Apr 13, 2018 at 03:23:36PM +0100, Peter Maydell wrote:
> The MIPS TCG target makes the assumption that the offset from the
> target env pointer to the tlb_table is less than about 64K. This
> used to be true, but gradual addition of features to the Arm
> target means that it's no longer true there. This results in
> the build-time assertion failing:
> 
> In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,
>                  from /home/pm215/qemu/tcg/tcg.c:28:
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c: In function ‘tcg_out_tlb_load’:
> /home/pm215/qemu/include/qemu/compiler.h:90:36: error: static assertion failed: "not expecting: offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff"
>  #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg)
>                                     ^
> /home/pm215/qemu/include/qemu/compiler.h:98:30: note: in expansion of macro ‘QEMU_BUILD_BUG_MSG’
>  #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)
>                               ^
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c:1236:9: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
>          QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
>          ^
> /home/pm215/qemu/rules.mak:66: recipe for target 'tcg/tcg.o' failed
> 
> An ideal long term approach would be to rearrange the CPU state
> so that the tlb_table was not so far along it, but this is tricky
> because it would move it from the "not cleared on CPU reset" part
> of the struct to the "cleared on CPU reset" part. As a simple fix
> for the 2.12 release, make the MIPS TCG target handle an arbitrary
> offset by emitting more add instructions. This will mean an extra
> instruction in the fastpath for TCG loads and stores for the
> affected guests (currently just aarch64-softmmu).
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> This is sufficient that on MIPS host we can now at least build
> and run an aarch64 guest kernel. I haven't tried 'make check'
> because the only MIPS system I have access to is way too slow...
> 
>  tcg/mips/tcg-target.inc.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c
> index 4b55ab8856..ca5f1d4894 100644
> --- a/tcg/mips/tcg-target.inc.c
> +++ b/tcg/mips/tcg-target.inc.c
> @@ -1229,13 +1229,10 @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
>      tcg_out_opc_reg(s, ALIAS_PADD, TCG_REG_A0, TCG_REG_A0, TCG_AREG0);
>  
>      /* Compensate for very large offsets.  */
> -    if (add_off >= 0x8000) {
> -        /* Most target env are smaller than 32k; none are larger than 64k.
> -           Simplify the logic here merely to offset by 0x7ff0, giving us a
> -           range just shy of 64k.  Check this assumption.  */
> -        QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
> -                                   tlb_table[NB_MMU_MODES - 1][1])
> -                          > 0x7ff0 + 0x7fff);
> +    while (add_off >= 0x8000) {
> +        /* Most target env are smaller than 32k, but a few are larger than 64k,
> +         * so handle an arbitrarily large offset.
> +         */
>          tcg_out_opc_imm(s, ALIAS_PADDI, TCG_REG_A0, TCG_REG_A0, 0x7ff0);
>          cmp_off -= 0x7ff0;
>          add_off -= 0x7ff0;
> -- 
> 2.16.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
  2018-04-13 14:23 [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table Peter Maydell
  2018-04-13 15:12 ` Michael S. Tsirkin
@ 2018-04-13 19:09 ` Richard Henderson
  2018-04-16 14:30   ` Peter Maydell
  2018-04-30 17:44 ` Alex Bennée
  2 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2018-04-13 19:09 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: patches, Michael S. Tsirkin, Aurelien Jarno, Yongbok Kim

On 04/13/2018 04:23 AM, Peter Maydell wrote:
> The MIPS TCG target makes the assumption that the offset from the
> target env pointer to the tlb_table is less than about 64K. This
> used to be true, but gradual addition of features to the Arm
> target means that it's no longer true there. This results in
> the build-time assertion failing:
> 
> In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,
>                  from /home/pm215/qemu/tcg/tcg.c:28:
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c: In function ‘tcg_out_tlb_load’:
> /home/pm215/qemu/include/qemu/compiler.h:90:36: error: static assertion failed: "not expecting: offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff"
>  #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg)
>                                     ^
> /home/pm215/qemu/include/qemu/compiler.h:98:30: note: in expansion of macro ‘QEMU_BUILD_BUG_MSG’
>  #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)
>                               ^
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c:1236:9: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
>          QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
>          ^
> /home/pm215/qemu/rules.mak:66: recipe for target 'tcg/tcg.o' failed

Yes, I asked for help on this from the MIPS folks back in January when I posted
patches for ppc and arm(32) hosts.  And then of course forgot about it in the
interim.

> +    while (add_off >= 0x8000) {
> +        /* Most target env are smaller than 32k, but a few are larger than 64k,
> +         * so handle an arbitrarily large offset.
> +         */
>          tcg_out_opc_imm(s, ALIAS_PADDI, TCG_REG_A0, TCG_REG_A0, 0x7ff0);
>          cmp_off -= 0x7ff0;
>          add_off -= 0x7ff0;

This is a pretty darned good solution, really.  I should have thought of it
myself at the time.  The new AArch64 offset is about 80k, so there will be two
adds emitted.  Loading C<<16 into a temp register and then adding would be no
better in the end (one can only add C<<16 directly with mipsr6 extensions).

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
  2018-04-13 19:09 ` Richard Henderson
@ 2018-04-16 14:30   ` Peter Maydell
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2018-04-16 14:30 UTC (permalink / raw)
  To: Richard Henderson
  Cc: QEMU Developers, patches, Michael S. Tsirkin, Aurelien Jarno,
	Yongbok Kim

On 13 April 2018 at 20:09, Richard Henderson <rth@twiddle.net> wrote:
> On 04/13/2018 04:23 AM, Peter Maydell wrote:
>> The MIPS TCG target makes the assumption that the offset from the
>> target env pointer to the tlb_table is less than about 64K. This
>> used to be true, but gradual addition of features to the Arm
>> target means that it's no longer true there. This results in
>> the build-time assertion failing:
>>
>> In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,
>>                  from /home/pm215/qemu/tcg/tcg.c:28:
>> /home/pm215/qemu/tcg/mips/tcg-target.inc.c: In function ‘tcg_out_tlb_load’:
>> /home/pm215/qemu/include/qemu/compiler.h:90:36: error: static assertion failed: "not expecting: offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff"
>>  #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg)
>>                                     ^
>> /home/pm215/qemu/include/qemu/compiler.h:98:30: note: in expansion of macro ‘QEMU_BUILD_BUG_MSG’
>>  #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)
>>                               ^
>> /home/pm215/qemu/tcg/mips/tcg-target.inc.c:1236:9: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
>>          QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
>>          ^
>> /home/pm215/qemu/rules.mak:66: recipe for target 'tcg/tcg.o' failed
>
> Yes, I asked for help on this from the MIPS folks back in January when I posted
> patches for ppc and arm(32) hosts.  And then of course forgot about it in the
> interim.
>
>> +    while (add_off >= 0x8000) {
>> +        /* Most target env are smaller than 32k, but a few are larger than 64k,
>> +         * so handle an arbitrarily large offset.
>> +         */
>>          tcg_out_opc_imm(s, ALIAS_PADDI, TCG_REG_A0, TCG_REG_A0, 0x7ff0);
>>          cmp_off -= 0x7ff0;
>>          add_off -= 0x7ff0;
>
> This is a pretty darned good solution, really.  I should have thought of it
> myself at the time.  The new AArch64 offset is about 80k, so there will be two
> adds emitted.  Loading C<<16 into a temp register and then adding would be no
> better in the end (one can only add C<<16 directly with mipsr6 extensions).
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks; applied to master.

-- PMM

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
  2018-04-13 14:23 [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table Peter Maydell
  2018-04-13 15:12 ` Michael S. Tsirkin
  2018-04-13 19:09 ` Richard Henderson
@ 2018-04-30 17:44 ` Alex Bennée
  2018-04-30 18:00   ` Peter Maydell
  2 siblings, 1 reply; 6+ messages in thread
From: Alex Bennée @ 2018-04-30 17:44 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Richard Henderson, Michael S. Tsirkin, Yongbok Kim,
	Aurelien Jarno, patches


Peter Maydell <peter.maydell@linaro.org> writes:

> The MIPS TCG target makes the assumption that the offset from the
> target env pointer to the tlb_table is less than about 64K. This
> used to be true, but gradual addition of features to the Arm
> target means that it's no longer true there. This results in
> the build-time assertion failing:
>
> In file included from /home/pm215/qemu/include/qemu/osdep.h:36:0,
>                  from /home/pm215/qemu/tcg/tcg.c:28:
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c: In function ‘tcg_out_tlb_load’:
> /home/pm215/qemu/include/qemu/compiler.h:90:36: error: static assertion failed: "not expecting: offsetof(CPUArchState, tlb_table[NB_MMU_MODES - 1][1]) > 0x7ff0 + 0x7fff"
>  #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg)
>                                     ^
> /home/pm215/qemu/include/qemu/compiler.h:98:30: note: in expansion of macro ‘QEMU_BUILD_BUG_MSG’
>  #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)
>                               ^
> /home/pm215/qemu/tcg/mips/tcg-target.inc.c:1236:9: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
>          QEMU_BUILD_BUG_ON(offsetof(CPUArchState,
>          ^
> /home/pm215/qemu/rules.mak:66: recipe for target 'tcg/tcg.o' failed
>
> An ideal long term approach would be to rearrange the CPU state
> so that the tlb_table was not so far along it, but this is tricky
> because it would move it from the "not cleared on CPU reset" part
> of the struct to the "cleared on CPU reset" part.

Is that really a problem? Doesn't it mean we'll just reload the TLB
after a reset?

--
Alex Bennée

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table
  2018-04-30 17:44 ` Alex Bennée
@ 2018-04-30 18:00   ` Peter Maydell
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2018-04-30 18:00 UTC (permalink / raw)
  To: Alex Bennée
  Cc: QEMU Developers, Richard Henderson, Michael S. Tsirkin,
	Yongbok Kim, Aurelien Jarno, patches

On 30 April 2018 at 18:44, Alex Bennée <alex.bennee@linaro.org> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>> An ideal long term approach would be to rearrange the CPU state
>> so that the tlb_table was not so far along it, but this is tricky
>> because it would move it from the "not cleared on CPU reset" part
>> of the struct to the "cleared on CPU reset" part.
>
> Is that really a problem? Doesn't it mean we'll just reload the TLB
> after a reset?

It was the sort of "this subtly changes the semantics on all
hosts for the sake of an issue that's mips-hosts-only" change
that I didn't want to try to reason through and make very close
to release when we didn't have a lot of time to test the results...

thanks
-- PMM

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-30 18:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-13 14:23 [Qemu-devel] [PATCH for-2.12] tcg/mips: Handle large offsets from target env to tlb_table Peter Maydell
2018-04-13 15:12 ` Michael S. Tsirkin
2018-04-13 19:09 ` Richard Henderson
2018-04-16 14:30   ` Peter Maydell
2018-04-30 17:44 ` Alex Bennée
2018-04-30 18:00   ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.