rtc devices: Avoid putting time_t in 32-bit variables
cover rtc devices: Avoid putting time_t in 32-bit variables
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a time_t variable but then truncate it by passing it to qemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.
We can fix the Coverity complaint by making qemu_get_timedate() take a time_t; we should also correspondingly make the qemu_timedate_diff() function return a time_t. However this will only push the issue out to callers of qemu_timedate_diff() if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.
Luckily there aren't that many callers of qemu_timedate_diff() and most of them already use either time_t or int64_t for the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes the rtc.c functions. If I missed any callsites in devices then hopefully Coverity will point them out.
This patchset is a migration compat break for the aspeed boards, because the offset field in aspeed_rtc is in its vmstate struct. We could in theory make this a compatible migration change, but I don't believe we care about migration compat for these boards.
I've only tested this with 'make check' and 'make check-avocado', which probably do not exercise these RTC devices much.
I've tagged this as for-8.2 because the code has been like this forever. We might as well give ourselves plenty of time to see if there's any unforeseen consequences of widening the type.
thanks
-- PMM
Peter Maydell (4):
hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm() hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference
rtc: Use time_t for passing and returning time offsets
include/hw/rtc/aspeed_rtc.h | 2 +- include/sysemu/rtc.h | 4 ++-- hw/rtc/aspeed_rtc.c | 5 ++--- hw/rtc/m48t59.c | 2 +- hw/rtc/twl92230.c | 4 ++-- softmmu/rtc.c | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm()
In the m48t59 device we almost always use 64-bit arithmetic when dealing with time_t deltas. The one exception is in set_alarm(), which currently uses a plain 'int' to hold the difference between two time_t values. Switch to int64_t instead to avoid any possible overflow issues.
--- hw/rtc/m48t59.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rtc/m48t59.c +1 -1
@@ -133,7 +133,7 @@ static void alarm_cb (void *opaque)static void set_alarm (M48t59State *NVRAM ) { -int diff; +int64_t diff;if (NVRAM ->alrm_timer !=NULL ) {timer_del (NVRAM ->alrm_timer); diff =qemu_timedate_diff (&NVRAM ->alarm) -NVRAM ->time_offset;
Signature · 1 line
2.34.1
Re: [PATCH for-8.2 1/4] hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm()
Quoted 10 lines · Peter Maydell
In the m48t59 device we almost always use 64-bit arithmetic when dealing with
time_tdeltas. The one exception is inset_alarm(), which currently uses a plain 'int' to hold the difference between twotime_tvalues. Switch toint64_tinstead to avoid any possible overflow issues.Signed-off-by Peter Maydell <[email protected]>--- hw/rtc/m48t59.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH for-8.2 1/4] hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm()
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
In the m48t59 device we almost always use 64-bit arithmetic when dealing with
time_tdeltas. The one exception is inset_alarm(), which currently uses a plain 'int' to hold the difference between twotime_tvalues. Switch toint64_tinstead to avoid any possible overflow issues.Signed-off-by Peter Maydell <[email protected]>--- hw/rtc/m48t59.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Similarly:
-- >8 --
hw/rtc/m48t59.c +1 -2
@@ -88,7 +88,7 @@ static M48txxInfo m48txx_sysbus_info[] = {static void alarm_cb (void *opaque) {struct tm tm; -uint64_t next_time; +int64_t next_time;M48t59State *NVRAM = opaque; ---
Re: [PATCH for-8.2 1/4] hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm()
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Peter Maydell
In the m48t59 device we almost always use 64-bit arithmetic when dealing with
time_tdeltas. The one exception is inset_alarm(), which currently uses a plain 'int' to hold the difference between twotime_tvalues. Switch toint64_tinstead to avoid any possible overflow issues.Signed-off-by Peter Maydell <[email protected]>--- hw/rtc/m48t59.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Similarly:
-- >8 --
hw/rtc/m48t59.c static M48txxInfo m48txx_sysbus_info[] = { · line 92
Quoted 6 lines
hw/rtc/m48t59.c +1
-1@@ -88,7 +88,7 @@ static M48txxInfo m48txx_sysbus_info[] = {static void alarm_cb (void *opaque) {struct tm tm; -uint64_t next_time; +int64_t next_time;M48t59State *NVRAM = opaque;
Why? next_time should always be positive here, I think.
-- PMM
PATCH 2/4 hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec
In reply to Peter MaydellIn the twl92230 device, use int64_t for the two state fields sec_offset and alm_sec, because we set these to values that are either time_t or differences between two time_t values.
These fields aren't saved in vmstate anywhere, so we can safely widen them.
---
I have a suspicion that really these fields *should* be being migrated, but this device is only used in the n800 and n810 boards, so I'm not going to investigate how broken migration/vmsave is there...
--- hw/rtc/twl92230.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/rtc/twl92230.c +2 -2
@@ -65,8 +65,8 @@ struct MenelausState {struct tm tm;struct tm new;struct tm alm; -int sec_offset; -int alm_sec; +int64_t sec_offset; +int64_t alm_sec;int next_comp; } rtc;uint16_t rtc_next_vmstate;
Signature · 1 line
2.34.1
Re: [PATCH for-8.2 2/4] hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec
Quoted 8 lines · Peter Maydell
In the twl92230 device, use
int64_tfor the two state fieldssec_offsetandalm_sec, because we set these to values that are eithertime_tor differences between twotime_tvalues.These fields aren't saved in vmstate anywhere, so we can safely widen them.
Signed-off-by Peter Maydell <[email protected]>
Quoted 8 lines
---
I have a suspicion that really these fields *should* be being migrated, but this device is only used in the n800 and n810 boards, so I'm not going to investigate how broken migration/vmsave is there...--- hw/rtc/twl92230.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH 3/4 hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference
In reply to Peter MaydellIn the aspeed_rtc device we store a difference between two time_t values in an 'int'. This is not really correct when time_t could be 64 bits. Enlarge the field to 'int64_t'.
This is a migration compatibility break for the aspeed boards. While we are changing the vmstate, remove the accidental duplicate of the offset field.
---
I took "bump the migration version" as the simplest approach here, because I don't think we care about migration compat in this case. If we do I can write the alternate version of the patch...
--- include/hw/rtc/aspeed_rtc.h | 2 +- hw/rtc/aspeed_rtc.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
include/hw/rtc/aspeed_rtc.h +1 -1
@@ -18,7 +18,7 @@ struct AspeedRtcState {qemu_irq irq;uint32_t reg[0x18 ]; -int offset; +int64_t offset; };
hw/rtc/aspeed_rtc.c +2 -3
@@ -136,11 +136,10 @@ static const MemoryRegionOps aspeed_rtc_ops = {static const VMStateDescription vmstate_aspeed_rtc = { .name =TYPE_ASPEED_RTC , - .version_id =1 , + .version_id =2 , .fields = (VMStateField []) {VMSTATE_UINT32_ARRAY (reg, AspeedRtcState,0x18 ), -VMSTATE_INT32 (offset, AspeedRtcState), -VMSTATE_INT32 (offset, AspeedRtcState), +VMSTATE_INT64 (offset, AspeedRtcState),VMSTATE_END_OF_LIST () } };
Signature · 1 line
2.34.1
Re: [PATCH for-8.2 3/4] hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference
Quoted 7 lines · Peter Maydell
In the
aspeed_rtcdevice we store a difference between twotime_tvalues in an 'int'. This is not really correct whentime_tcould be 64 bits. Enlarge the field to 'int64_t'.This is a migration compatibility break for the aspeed boards. While we are changing the vmstate, remove the accidental duplicate of the offset field.
Ah yes. Thanks.
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>
Quoted 5 lines
---
I took "bump the migration version" as the simplest approach here, because I don't think we care about migration compat in this case. If we do I can write the alternate version of the patch...
I don't think we care much about migration compat and fyi, migration of aspeed machines broke a while ago. It still migrates if done before Linux is loaded.
C.
Quoted 36 lines
--- include/hw/rtc/aspeed_rtc.h | 2 +- hw/rtc/aspeed_rtc.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)include/hw/rtc/aspeed_rtc.h +1
-1@@ -18,7 +18,7 @@ struct AspeedRtcState {qemu_irq irq;uint32_t reg[0x18 ]; -int offset; +int64_t offset; };hw/rtc/aspeed_rtc.c +2
-3@@ -136,11 +136,10 @@ static const MemoryRegionOps aspeed_rtc_ops = {static const VMStateDescription vmstate_aspeed_rtc = { .name =TYPE_ASPEED_RTC , - .version_id =1 , + .version_id =2 , .fields = (VMStateField []) {VMSTATE_UINT32_ARRAY (reg, AspeedRtcState,0x18 ), -VMSTATE_INT32 (offset, AspeedRtcState), -VMSTATE_INT32 (offset, AspeedRtcState), +VMSTATE_INT64 (offset, AspeedRtcState),VMSTATE_END_OF_LIST () } };
Re: [PATCH for-8.2 3/4] hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference
Quoted 26 lines · Cédric Le Goater
Quoted 7 lines · Peter Maydell
In the
aspeed_rtcdevice we store a difference between twotime_tvalues in an 'int'. This is not really correct whentime_tcould be 64 bits. Enlarge the field to 'int64_t'.This is a migration compatibility break for the aspeed boards. While we are changing the vmstate, remove the accidental duplicate of the offset field.
Ah yes. Thanks.
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Quoted 5 lines
---
I took "bump the migration version" as the simplest approach here, because I don't think we care about migration compat in this case. If we do I can write the alternate version of the patch...
Quoted 3 lines
I don't think we care much about migration compat and fyi, migration of aspeed machines broke a while ago. It still migrates if done before Linux is loaded.
Is that the "migration of AArch32 Secure state doesn't work properly" bug, or am I misremembering?
-- PMM
Re: [PATCH for-8.2 3/4] hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference
Quoted 27 lines · Peter Maydell
Quoted 26 lines · Cédric Le Goater
Quoted 7 lines · Peter Maydell
In the
aspeed_rtcdevice we store a difference between twotime_tvalues in an 'int'. This is not really correct whentime_tcould be 64 bits. Enlarge the field to 'int64_t'.This is a migration compatibility break for the aspeed boards. While we are changing the vmstate, remove the accidental duplicate of the offset field.
Ah yes. Thanks.
Quoted 2 lines
Signed-off-by Peter Maydell <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Quoted 5 lines
---
I took "bump the migration version" as the simplest approach here, because I don't think we care about migration compat in this case. If we do I can write the alternate version of the patch...
Quoted 6 lines
Quoted 3 lines
I don't think we care much about migration compat and fyi, migration of aspeed machines broke a while ago. It still migrates if done before Linux is loaded.
Is that the "migration of AArch32 Secure state doesn't work properly" bug, or am I misremembering?
probably, arm926 is not impacted, arm1176 and cortex-a7 are.
C.
PATCH 4/4 rtc: Use time_t for passing and returning time offsets
In reply to Peter MaydellThe functions qemu_get_timedate() and qemu_timedate_diff() take and return a time offset as an integer. Coverity points out that means that when an RTC device implementation holds an offset as a time_t, as the m48t59 does, the time_t will get truncated. (CID 1507157, 1517772).
The functions work with time_t internally, so make them use that type in their APIs.
Note that this won't help any Y2038 issues where either the device model itself is keeping the offset in a 32-bit integer, or where the hardware under emulation has Y2038 or other rollover problems. If we missed any cases of the former then hopefully Coverity will warn us about them since after this patch we'd be truncating a time_t in assignments from qemu_timedate_diff().)
--- include/sysemu/rtc.h | 4 ++-- softmmu/rtc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/sysemu/rtc.h +2 -2
@@ -42,7 +42,7 @@* The behaviour of the clock whose value this function returns will * depend on the -rtc command line option passed by the user. */ -void qemu_get_timedate (struct tm *tm,int offset); +void qemu_get_timedate (struct tm *tm,time_t offset);/** * qemu_timedate_diff: Return difference between a struct tm and the RTC
@@ -53,6 +53,6 @@ void qemu_get_timedate(struct tm *tm, int offset);* a timestamp one hour further ahead than the current RTC time * then this function will return 3600. */ -int qemu_timedate_diff (struct tm *tm); +time_t qemu_timedate_diff (struct tm *tm);#endif
softmmu/rtc.c +2 -2
@@ -68,7 +68,7 @@ static time_t qemu_ref_timedate(QEMUClockType clock)return value; } -void qemu_get_timedate (struct tm *tm,int offset) +void qemu_get_timedate (struct tm *tm,time_t offset) {time_t ti =qemu_ref_timedate (rtc_clock);
@@ -85,7 +85,7 @@ void qemu_get_timedate(struct tm *tm, int offset) } } -int qemu_timedate_diff (struct tm *tm) +time_t qemu_timedate_diff (struct tm *tm) {time_t seconds;
Signature · 1 line
2.34.1
Re: [PATCH for-8.2 4/4] rtc: Use time_t for passing and returning time offsets
Quoted 16 lines · Peter Maydell
The functions
qemu_get_timedate()andqemu_timedate_diff()take and return a time offset as an integer. Coverity points out that means that when an RTC device implementation holds an offset as atime_t, as the m48t59 does, thetime_twill get truncated. (CID 1507157, 1517772).The functions work with
time_tinternally, so make them use that type in their APIs.Note that this won't help any Y2038 issues where either the device model itself is keeping the offset in a 32-bit integer, or where the hardware under emulation has Y2038 or other rollover problems. If we missed any cases of the former then hopefully Coverity will warn us about them since after this patch we'd be truncating a
time_tin assignments fromqemu_timedate_diff().)
Quoted 5 lines
Signed-off-by Peter Maydell <[email protected]>--- include/sysemu/rtc.h | 4 ++-- softmmu/rtc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
+Markus
Quoted 13 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.
Quoted 6 lines
Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.
Do we need to change the type of the RTC_CHANGE event?
This is wrong, but to give an idea:
qapi/misc.json +1 -2
@@ -553,47 +553,47 @@ ## # @RTC_CHANGE: # # Emitted when the guest changes the RTC time. # # @offset: offset in seconds between base RTC clock (as specified by # -rtc base), and new RTC clock value # # @qom-path: path to the RTC object in the QOM tree # # Note: This event is rate-limited. It is not guaranteed that the RTC # in the system implements this event, or even that the system has # an RTC at all. # # Since: 0.13 # # Example: # # <- { "event": "RTC_CHANGE", # "data": { "offset": 78 }, # "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } ## { 'event': 'RTC_CHANGE', - 'data': { 'offset': 'int', 'qom-path': 'str' } } + 'data': { 'offset': 'int64', 'qom-path': 'str' } } ---
Quoted 47 lines · Philippe Mathieu-Daudé
+Markus
Quoted 13 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.Quoted 6 lines
Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.Do we need to change the type of the
RTC_CHANGEevent?This is wrong, but to give an idea:
qapi/misc.json +0
-0@@ -553,47 +553,47 @@ ## # @RTC_CHANGE: # # Emitted when the guest changes the RTC time. # # @offset: offset in seconds between base RTC clock (as specified by # -rtc base), and new RTC clock value # # @qom-path: path to the RTC object in the QOM tree # # Note: This event is rate-limited. It is not guaranteed that the RTC # in the system implements this event, or even that the system has # an RTC at all. # # Since: 0.13 #
qapi/misc.json line 577
Quoted 10 lines
qapi/misc.json +1
-2# Example: # # <- { "event": "RTC_CHANGE", # "data": { "offset": 78 }, # "timestamp": { "seconds": 1267020223, "microseconds": 435656 } } ## { 'event': 'RTC_CHANGE', - 'data': { 'offset': 'int', 'qom-path': 'str' } } + 'data': { 'offset': 'int64', 'qom-path': 'str' } } ---
If I understand the 'Built-in Types' section in docs/devel/qapi-code-gen.rst correctly, the QAPI 'int' type is already 64 bits.
thanks
-- PMM
Quoted 26 lines · Peter Maydell
Quoted 25 lines · Philippe Mathieu-Daudé
+Markus
Quoted 13 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.Quoted 6 lines
Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.Do we need to change the type of the
RTC_CHANGEevent?
[...]
Quoted 3 lines
If I understand the 'Built-in Types' section in
docs/devel/qapi-code-gen.rstcorrectly, the QAPI 'int' type is already 64 bits.
Correct. Also needlessly confusing.
Hi Peter,
Quoted 13 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.
Quoted 6 lines
Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.
PL031State::tick_offset is uint32_t, and pl031_get_count() also returns that type. Is that expected?
Quoted 24 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 13 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.Quoted 6 lines
Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.
Quoted 2 lines
PL031State::tick_offsetisuint32_t, andpl031_get_count()also returns that type. Is that expected?
I think those fall into the category of "the device we are modelling does not support 64-bit timestamps" -- the PL031 RTC_DR register is only 32 bits.
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Philippe Mathieu-Daudé
Hi Peter,
Quoted 19 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.
Quoted 6 lines
Quoted 2 lines
PL031State::tick_offsetisuint32_t, andpl031_get_count()also returns that type. Is that expected?I think those fall into the category of "the device we are modelling does not support 64-bit timestamps" -- the PL031
RTC_DRregister is only 32 bits.
Good, thanks for confirming.
Quoted 26 lines · Peter Maydell
This patchset was prompted by a couple of Coverity warnings (CID 1507157, 1517772) which note that in the m48t59 RTC device model we keep an offset in a
time_tvariable but then truncate it by passing it toqemu_get_timedate(), which currently uses an 'int' argument for its offset parameter.We can fix the Coverity complaint by making
qemu_get_timedate()take atime_t; we should also correspondingly make theqemu_timedate_diff()function return atime_t. However this will only push the issue out to callers ofqemu_timedate_diff()if they are putting the result in a 32-bit variable or doing 32-bit arithmetic on it.Luckily there aren't that many callers of
qemu_timedate_diff()and most of them already use eithertime_torint64_tfor the calculations they do on its return value. The first three patches fix devices which weren't doing that; patch four then fixes thertc.cfunctions. If I missed any callsites in devices then hopefully Coverity will point them out.This patchset is a migration compat break for the aspeed boards, because the offset field in
aspeed_rtcis in its vmstate struct. We could in theory make this a compatible migration change, but I don't believe we care about migration compat for these boards.
Quoted 6 lines
I've only tested this with 'make check' and 'make check-avocado', which probably do not exercise these RTC devices much.
I've tagged this as for-8.2 because the code has been like this forever. We might as well give ourselves plenty of time to see if there's any unforeseen consequences of widening the type.
8.2 dev cycle is now open, so I plan to take these through the arm tree, since they're mostly arm timer devices.
thanks
-- PMM