microbit_i2c: Fix coredump when dump-vmstate
PATCH 1/1 microbit_i2c: Fix coredump when dump-vmstate
VMStateDescription.fields should be end with VMSTATE_END_OF_LIST(). However, microbit_i2c_vmstate doesn't follow it. Let's change it.
--- hw/i2c/microbit_i2c.c | 1 + 1 file changed, 1 insertion(+)
hw/i2c/microbit_i2c.c +1 -0
@@ -83,6 +83,7 @@ static const VMStateDescription microbit_i2c_vmstate = { .fields = (VMStateField[]) {VMSTATE_UINT32_ARRAY (regs, MicrobitI2CState,MICROBIT_I2C_NREGS ),VMSTATE_UINT32 (read_idx, MicrobitI2CState), +VMSTATE_END_OF_LIST () }, };
Signature · 1 line
2.26.2
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.
It might be easy to add a Coccinelle script to avoid future errors.
Quoted 21 lines
Fixes 9d68bf564e ("arm: Stub out NRF51 TWI magnetometer/accelerometer detection")Reported-by Euler Robot <[email protected]>Signed-off-by Peng Liang <[email protected]>--- hw/i2c/microbit_i2c.c | 1 + 1 file changed, 1 insertion(+)hw/i2c/microbit_i2c.c +1
-0@@ -83,6 +83,7 @@ static const VMStateDescription microbit_i2c_vmstate = { .fields = (VMStateField[]) {VMSTATE_UINT32_ARRAY (regs, MicrobitI2CState,MICROBIT_I2C_NREGS ),VMSTATE_UINT32 (read_idx, MicrobitI2CState), +VMSTATE_END_OF_LIST () }, };
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 18 lines
Fixes 9d68bf564e ("arm: Stub out NRF51 TWI magnetometer/accelerometerdetection")
Reported-by Euler Robot <[email protected]>Signed-off-by Peng Liang <[email protected]>---
hw/i2c/microbit_i2c.c| 1 +1 file changed, 1 insertion(+)hw/i2c/microbit_i2c.c +0
-0@@ -83,6 +83,7 @@ static const VMStateDescription microbit_i2c_vmstate = { .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, MicrobitI2CState, MICROBIT_I2C_NREGS),
Quoted 8 lines
Quoted 5 lines
hw/i2c/microbit_i2c.c +1
-0VMSTATE_UINT32(read_idx, MicrobitI2CState), + VMSTATE_END_OF_LIST() },};
.
Thanks! I'll try to add one.
Signature · 2 lines
Thanks, Peng
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
I tried to add a Coccinelle script to add VMSTATE_END_OF_LIST() to the end of VMStateDescription.fields. For those who are not defined as compound literals, it works well. However, I cannot make it work for those defined as compound literals. And Julia doesn't think compound literals are supported currently[1]. So maybe currently it's hard to check the error using Coccinelle :(
Thanks for my colleague Biaoxiang Ye, who wrote a shell script to find the errors, I didn't find other similar errors.
[1]
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2010201143330.2736@hadrien/T/#t
Thanks,
Peng
Quoted 26 lines
Quoted 21 lines
Fixes 9d68bf564e ("arm: Stub out NRF51 TWI magnetometer/accelerometerdetection")
Reported-by Euler Robot <[email protected]>Signed-off-by Peng Liang <[email protected]>---
hw/i2c/microbit_i2c.c| 1 +1 file changed, 1 insertion(+)hw/i2c/microbit_i2c.c +1
-0@@ -83,6 +83,7 @@ static const VMStateDescription microbit_i2c_vmstate = { .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, MicrobitI2CState,MICROBIT_I2C_NREGS ), VMSTATE_UINT32(read_idx, MicrobitI2CState), + VMSTATE_END_OF_LIST() },Quoted 2 lines
};
.
Quoted 10 lines · Peng Liang
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 6 lines
I tried to add a Coccinelle script to add
VMSTATE_END_OF_LIST()to the end of VMStateDescription.fields. For those who are not defined as compound literals, it works well. However, I cannot make it work for those defined as compound literals. And Julia doesn't think compound literals are supported currently[1]. So maybe currently it's hard to check the error using Coccinelle :(
Interesting.
Quoted 3 lines
Thanks for my colleague Biaoxiang Ye, who wrote a shell script to find the errors, I didn't find other similar errors.
Thanks for giving it a try. We could commit and run the script in a gitlab-ci job to avoid such regressions.
Quoted 34 lines
[1]
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2010201143330.2736@hadrien/T/#tThanks,
PengQuoted 26 lines
Quoted 21 lines
Fixes 9d68bf564e ("arm: Stub out NRF51 TWI magnetometer/accelerometerdetection")
Reported-by Euler Robot <[email protected]>Signed-off-by Peng Liang <[email protected]>--- hw/i2c/microbit_i2c.c | 1 + 1 file changed, 1 insertion(+)hw/i2c/microbit_i2c.c +1
-0@@ -83,6 +83,7 @@ static const VMStateDescription microbit_i2c_vmstate = { .fields = (VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, MicrobitI2CState,MICROBIT_I2C_NREGS ), VMSTATE_UINT32(read_idx, MicrobitI2CState), + VMSTATE_END_OF_LIST() },Quoted 2 lines
};
.
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Peng Liang
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 6 lines
I tried to add a Coccinelle script to add
VMSTATE_END_OF_LIST()to the end of VMStateDescription.fields. For those who are not defined as compound literals, it works well. However, I cannot make it work for those defined as compound literals. And Julia doesn't think compound literals are supported currently[1]. So maybe currently it's hard to check the error using Coccinelle :(
Quoted 9 lines
Interesting.
Quoted 3 lines
Thanks for my colleague Biaoxiang Ye, who wrote a shell script to find the errors, I didn't find other similar errors.
Thanks for giving it a try. We could commit and run the script in a gitlab-ci job to avoid such regressions.
The script will report all fields not defined as compound literals as errors (the number is much smaller than that of all VMStateDescription.fields).
Signature · 2 lines
Thanks, Peng
Quoted 11 lines · Peng Liang
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 6 lines
I tried to add a Coccinelle script to add
VMSTATE_END_OF_LIST()to the end of VMStateDescription.fields. For those who are not defined as compound literals, it works well. However, I cannot make it work for those defined as compound literals. And Julia doesn't think compound literals are supported currently[1]. So maybe currently it's hard to check the error using Coccinelle :(
I think we could probably significantly increase the chances that people find "missing terminator" errors in the course of normal debugging of their device if we made the terminator be something other than "is field->name NULL". That condition is quite likely to be satisfied by accident shortly after the real end-of-data (because zeroes are easy to find in memory), whereas if the condition is "field->flags is a magic number", for instance, then the chances of it being satisfied by accident are very low, and so a simple "loop through the field array until we find the end" is pretty likely to hang/crash. (If we don't already have such a loop we might need to add one in debug mode when a vmstate is registered.)
(This is why the REGINFO_SENTINEL used for Arm cpreg arrays is not a simple all-zeroes value, incidentally.)
thanks
-- PMM
Quoted 31 lines · Peter Maydell
Quoted 11 lines · Peng Liang
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.It might be easy to add a Coccinelle script to avoid future errors.
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 6 lines
I tried to add a Coccinelle script to add
VMSTATE_END_OF_LIST()to the end of VMStateDescription.fields. For those who are not defined as compound literals, it works well. However, I cannot make it work for those defined as compound literals. And Julia doesn't think compound literals are supported currently[1]. So maybe currently it's hard to check the error using Coccinelle :(I think we could probably significantly increase the chances that people find "missing terminator" errors in the course of normal debugging of their device if we made the terminator be something other than "is
field->nameNULL". That condition is quite likely to be satisfied by accident shortly after the real end-of-data (because zeroes are easy to find in memory), whereas if the condition is "field->flagsis a magic number", for instance, then the chances of it being satisfied by accident are very low, and so a simple "loop through the field array until we find the end" is pretty likely to hang/crash. (If we don't already have such a loop we might need to add one in debug mode when a vmstate is registered.)
Quoted 7 lines
(This is why the
REGINFO_SENTINELused for Arm cpreg arrays is not a simple all-zeroes value, incidentally.)thanks
-- PMM
.
I found that field->flags is a bit-or field, so maybe all 0xf or other magic number is still meaningful? Can we use field->version_id or field->struct_version_id as the condition? I found they are all int type but used as non-negative, so can we use field->version_id/field->struct_version_id == magic number (for example, -1) as a sentinel?
Signature · 2 lines
Thanks, Peng
Peter Maydell
AppliedQuoted 8 lines · Peng Liang
VMStateDescription.fields should be end with
VMSTATE_END_OF_LIST(). However,microbit_i2c_vmstatedoesn't follow it. Let's change it.Fixes 9d68bf564e ("arm: Stub out NRF51 TWI magnetometer/accelerometer detection")Reported-by Euler Robot <[email protected]>Signed-off-by Peng Liang <[email protected]>---
Applied to target-arm.next, thanks.
-- PMM