target/arm: Stop using variable length array in dc_zva
PATCH 1/1 target/arm: Stop using variable length array in dc_zva
Currently the dc_zva helper function uses a variable length array. In fact we know (as the comment above remarks) that the length of this array is bounded because the architecture limits the block size and QEMU limits the target page size. Use a fixed array size and assert that we don't run off it.
---
A small move in the direction of "avoid using variable length arrays in QEMU"...
target/arm/helper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/arm/helper.c +4 -1
@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/units.h" #include "target/arm/idau.h" #include "trace.h" #include "cpu.h"
@@ -12412,11 +12413,13 @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)* same QEMU executable. */ int maxidx =DIV_ROUND_UP (blocklen,TARGET_PAGE_SIZE ); -void *hostaddr[maxidx]; +void *hostaddr[DIV_ROUND_UP (2 * KiB,1 <<TARGET_PAGE_BITS_MIN )];int try, i;unsigned mmu_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_UB , mmu_idx); +assert (maxidx <=sizeof (hostaddr)); +for (try =0 ; try <2 ; try++) {for (i =0 ; i < maxidx; i++) {
Signature · 1 line
2.20.1
Le jeu. 28 mars 2019 15:30, Peter Maydell <[email protected]> a écrit :
Quoted 25 lines
Currently the
dc_zvahelper function uses a variable length array. In fact we know (as the comment above remarks) that the length of this array is bounded because the architecture limits the block size and QEMU limits the target page size. Use a fixed array size and assert that we don't run off it.Signed-off-by Peter Maydell <[email protected]>---
A small move in the direction of "avoid using variable length arrays in QEMU"...target/arm/helper.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/arm/helper.c +1
-0@@ -1,4 +1,5 @@#include "qemu/osdep.h" +#include "qemu/units.h" #include "target/arm/idau.h" #include "trace.h" #include "cpu.h"
target/arm/helper.c void HELPER(dc_zva)(CPUARMState *env, uint64_t · line 12418
Quoted 7 lines
target/arm/helper.c +1
-1@@ -12412,11 +12413,13 @@ void HELPER(dc_zva)(CPUARMState *env, uint64_tvaddr_in) * same QEMU executable. */ int maxidx =DIV_ROUND_UP (blocklen,TARGET_PAGE_SIZE ); -void *hostaddr[maxidx]; +void *hostaddr[DIV_ROUND_UP (2 * KiB,1 <<TARGET_PAGE_BITS_MIN )];
Or g_new()... For 2K nowadays that is fine.
int try, i;
Quoted 13 lines
target/arm/helper.c +2
-0unsigned mmu_idx =cpu_mmu_index (env, false);TCGMemOpIdx oi =make_memop_idx (MO_UB , mmu_idx); +assert (maxidx <=sizeof (hostaddr)); +for (try =0 ; try <2 ; try++) {for (i = 0; i < maxidx; i++) {--
2.20.1
target/arm/helper.c void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in) · line 12416
Quoted 2 lines · Peter Maydell
target/arm/helper.c +1
-1-void *hostaddr[maxidx]; +void *hostaddr[DIV_ROUND_UP (2 * KiB,1 <<TARGET_PAGE_BITS_MIN )];
A very fancy way of writing "2".
Quoted 5 lines
int try, i; unsigned mmu_idx = cpu_mmu_index(env, false); TCGMemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);+ assert(maxidx <= sizeof(hostaddr));
ARRAY_SIZE(hostaddr).
r~
Quoted 6 lines · Richard Henderson
target/arm/helper.c void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in) · line 12416
Quoted 2 lines · Peter Maydell
target/arm/helper.c +1
-1-void *hostaddr[maxidx]; +void *hostaddr[DIV_ROUND_UP (2 * KiB,1 <<TARGET_PAGE_BITS_MIN )];A very fancy way of writing "2".
Yes, but I thought this made the relationship between the constant size and what maxidx a little clearer.
Quoted 8 lines
Quoted 6 lines
int try, i; unsigned mmu_idx = cpu_mmu_index(env, false); TCGMemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);+ assert(maxidx <= sizeof(hostaddr));
ARRAY_SIZE(hostaddr).
Oops, yes.
thanks
-- PMM