hw/intc/arm_gicv3_its: Fix address calculation in get_ite() and update_ite()
commita1ce993da6fc27b022075b02a2e1e1e5be329254
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 1 Feb 2022 19:32:00 +0000 (1 19:32 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Tue, 8 Feb 2022 10:56:29 +0000 (8 10:56 +0000)
treec677f381666a32c80aae40a4cf3ab1d790e8f35d
parent06985cc3fe5a5a7577ddd43406758aa79099b4f7
hw/intc/arm_gicv3_its: Fix address calculation in get_ite() and update_ite()

In get_ite() and update_ite() we work with a 12-byte in-guest-memory
table entry, which we intend to handle as an 8-byte value followed by
a 4-byte value.  Unfortunately the calculation of the address of the
4-byte value is wrong, because we write it as:

 table_base_address + (index * entrysize) + 4
(obfuscated by the way the expression has been written)

when it should be + 8.  This bug meant that we overwrote the top
bytes of the 8-byte value with the 4-byte value.  There are no
guest-visible effects because the top half of the 8-byte value
contains only the doorbell interrupt field, which is used only in
GICv4, and the two bugs in the "write ITE" and "read ITE" codepaths
cancel each other out.

We can't simply change the calculation, because this would break
migration of a (TCG) guest from the old version of QEMU which had
in-guest-memory interrupt tables written using the buggy version of
update_ite().  We must also at the same time change the layout of the
fields within the ITE_L and ITE_H values so that the in-memory
locations of the fields we care about (VALID, INTTYPE, INTID and
ICID) stay the same.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20220201193207.2771604-7-peter.maydell@linaro.org
hw/intc/arm_gicv3_its.c
hw/intc/gicv3_internal.h