* [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API @ 2025-01-25 18:24 Philippe Mathieu-Daudé 2025-01-25 18:24 ` [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() Philippe Mathieu-Daudé ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-01-25 18:24 UTC (permalink / raw) To: qemu-devel; +Cc: Paolo Bonzini, Peter Maydell, Philippe Mathieu-Daudé Update few QEMUTimer docstring and add a sanity check during timer initialization. Noticed trying to understand leaks in QDev Realize -> Unrealize -> Realize transition. Philippe Mathieu-Daudé (2): qemu/timer: Clarify timer_new*() must be freed with timer_free() qemu/timer: Sanity check timer_list in timer_init_full() include/qemu/timer.h | 12 +++++++++++- util/qemu-timer.c | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) -- 2.47.1 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() 2025-01-25 18:24 [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé @ 2025-01-25 18:24 ` Philippe Mathieu-Daudé 2025-02-06 10:39 ` Daniel P. Berrangé 2025-01-25 18:24 ` [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() Philippe Mathieu-Daudé 2025-02-04 21:44 ` [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2 siblings, 1 reply; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-01-25 18:24 UTC (permalink / raw) To: qemu-devel; +Cc: Paolo Bonzini, Peter Maydell, Philippe Mathieu-Daudé There was not mention QEMUTimer created with timer_new*() must be released with timer_free() instead of g_free(), because then active timers are removed from the active list. Update the documentation mentioning timer_free(). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/qemu/timer.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index cc167bd825b..abd2204f3be 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -507,6 +507,8 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type, * with an AioContext---each of them runs its timer callbacks in its own * AioContext thread. * + * The timer returned must be freed using timer_free(). + * * Returns: a pointer to the timer */ static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group, @@ -530,6 +532,8 @@ static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group, * and associate it with the default timer list for the clock type @type. * See timer_new_full for details. * + * The timer returned must be freed using timer_free(). + * * Returns: a pointer to the timer */ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, @@ -548,6 +552,8 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, * associated with the clock. * See timer_new_full for details. * + * The timer returned must be freed using timer_free(). + * * Returns: a pointer to the newly created timer */ static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, @@ -566,6 +572,8 @@ static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, * associated with the clock. * See timer_new_full for details. * + * The timer returned must be freed using timer_free(). + * * Returns: a pointer to the newly created timer */ static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, @@ -584,6 +592,8 @@ static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, * associated with the clock. * See timer_new_full for details. * + * The timer returned must be freed using timer_free(). + * * Returns: a pointer to the newly created timer */ static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb, -- 2.47.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() 2025-01-25 18:24 ` [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() Philippe Mathieu-Daudé @ 2025-02-06 10:39 ` Daniel P. Berrangé 0 siblings, 0 replies; 10+ messages in thread From: Daniel P. Berrangé @ 2025-02-06 10:39 UTC (permalink / raw) To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Paolo Bonzini, Peter Maydell On Sat, Jan 25, 2025 at 07:24:24PM +0100, Philippe Mathieu-Daudé wrote: > There was not mention QEMUTimer created with timer_new*() must > be released with timer_free() instead of g_free(), because then > active timers are removed from the active list. Update the > documentation mentioning timer_free(). > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/qemu/timer.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() 2025-01-25 18:24 [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2025-01-25 18:24 ` [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() Philippe Mathieu-Daudé @ 2025-01-25 18:24 ` Philippe Mathieu-Daudé 2025-02-06 10:40 ` Daniel P. Berrangé 2025-02-09 9:37 ` Michael Tokarev 2025-02-04 21:44 ` [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2 siblings, 2 replies; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-01-25 18:24 UTC (permalink / raw) To: qemu-devel; +Cc: Paolo Bonzini, Peter Maydell, Philippe Mathieu-Daudé Ensure we are not re-initializing a QEMUTimer already added to an active list. timer_init*() functions expect either a recently created and zeroed QEMUTimer, or one previously free'd with timer_free(). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- include/qemu/timer.h | 2 +- util/qemu-timer.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index abd2204f3be..4717693f950 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -407,7 +407,7 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg); * (or default timer list group, if NULL). * The caller is responsible for allocating the memory. * - * You need not call an explicit deinit call. Simply make + * You need not call an explicit timer_deinit() call. Simply make * sure it is not on a list with timer_del. */ void timer_init_full(QEMUTimer *ts, diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 0e8a453eaa1..058cae6e487 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -354,6 +354,7 @@ void timer_init_full(QEMUTimer *ts, if (!timer_list_group) { timer_list_group = &main_loop_tlg; } + assert(ts->timer_list == NULL); ts->timer_list = timer_list_group->tl[type]; ts->cb = cb; ts->opaque = opaque; -- 2.47.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() 2025-01-25 18:24 ` [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() Philippe Mathieu-Daudé @ 2025-02-06 10:40 ` Daniel P. Berrangé 2025-02-09 9:37 ` Michael Tokarev 1 sibling, 0 replies; 10+ messages in thread From: Daniel P. Berrangé @ 2025-02-06 10:40 UTC (permalink / raw) To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Paolo Bonzini, Peter Maydell On Sat, Jan 25, 2025 at 07:24:25PM +0100, Philippe Mathieu-Daudé wrote: > Ensure we are not re-initializing a QEMUTimer already added > to an active list. timer_init*() functions expect either > a recently created and zeroed QEMUTimer, or one previously > free'd with timer_free(). > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/qemu/timer.h | 2 +- > util/qemu-timer.c | 1 + > 2 files changed, 2 insertions(+), 1 deletion(-) Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :| ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() 2025-01-25 18:24 ` [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() Philippe Mathieu-Daudé 2025-02-06 10:40 ` Daniel P. Berrangé @ 2025-02-09 9:37 ` Michael Tokarev 2025-02-09 9:41 ` Michael Tokarev 1 sibling, 1 reply; 10+ messages in thread From: Michael Tokarev @ 2025-02-09 9:37 UTC (permalink / raw) To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Paolo Bonzini, Peter Maydell 25.01.2025 21:24, Philippe Mathieu-Daudé wrote: > - * You need not call an explicit deinit call. Simply make > + * You need not call an explicit timer_deinit() call. Simply make > * sure it is not on a list with timer_del. Reworded this as "You need not call timer_deinit() explicitly. Simply make..." and applied to trivial-patches tree. Thanks, /mjt ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() 2025-02-09 9:37 ` Michael Tokarev @ 2025-02-09 9:41 ` Michael Tokarev 2025-02-09 17:41 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 10+ messages in thread From: Michael Tokarev @ 2025-02-09 9:41 UTC (permalink / raw) To: Philippe Mathieu-Daudé, qemu-devel; +Cc: Paolo Bonzini, Peter Maydell 09.02.2025 12:37, Michael Tokarev wrote: > 25.01.2025 21:24, Philippe Mathieu-Daudé wrote: > >> - * You need not call an explicit deinit call. Simply make >> + * You need not call an explicit timer_deinit() call. Simply make >> * sure it is not on a list with timer_del. > > Reworded this as "You need not call timer_deinit() explicitly. Simply make..." "You don't need to call timer_deinit() explicitly.", actually. This breaks quite a lot of CI tests: https://gitlab.com/mjt0k/qemu/-/pipelines/1662551717 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() 2025-02-09 9:41 ` Michael Tokarev @ 2025-02-09 17:41 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-02-09 17:41 UTC (permalink / raw) To: Michael Tokarev, qemu-devel; +Cc: Paolo Bonzini, Peter Maydell On 9/2/25 10:41, Michael Tokarev wrote: > 09.02.2025 12:37, Michael Tokarev wrote: >> 25.01.2025 21:24, Philippe Mathieu-Daudé wrote: >> >>> - * You need not call an explicit deinit call. Simply make >>> + * You need not call an explicit timer_deinit() call. Simply make >>> * sure it is not on a list with timer_del. >> >> Reworded this as "You need not call timer_deinit() explicitly. Simply >> make..." > > "You don't need to call timer_deinit() explicitly.", actually. > > This breaks quite a lot of CI tests: https://gitlab.com/mjt0k/qemu/-/ > pipelines/1662551717 Do sorry, I only tested on a specific config and missed all the other errors :/ ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API 2025-01-25 18:24 [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2025-01-25 18:24 ` [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() Philippe Mathieu-Daudé 2025-01-25 18:24 ` [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() Philippe Mathieu-Daudé @ 2025-02-04 21:44 ` Philippe Mathieu-Daudé 2025-02-06 9:44 ` Philippe Mathieu-Daudé 2 siblings, 1 reply; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-02-04 21:44 UTC (permalink / raw) To: qemu-devel, QEMU Trivial; +Cc: Paolo Bonzini, Peter Maydell, Pierrick Bouvier ping? On 25/1/25 19:24, Philippe Mathieu-Daudé wrote: > Update few QEMUTimer docstring and add a > sanity check during timer initialization. > > Noticed trying to understand leaks in QDev > Realize -> Unrealize -> Realize transition. > > Philippe Mathieu-Daudé (2): > qemu/timer: Clarify timer_new*() must be freed with timer_free() > qemu/timer: Sanity check timer_list in timer_init_full() > > include/qemu/timer.h | 12 +++++++++++- > util/qemu-timer.c | 1 + > 2 files changed, 12 insertions(+), 1 deletion(-) > ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API 2025-02-04 21:44 ` [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé @ 2025-02-06 9:44 ` Philippe Mathieu-Daudé 0 siblings, 0 replies; 10+ messages in thread From: Philippe Mathieu-Daudé @ 2025-02-06 9:44 UTC (permalink / raw) To: qemu-devel, QEMU Trivial Cc: Paolo Bonzini, Peter Maydell, Pierrick Bouvier, Daniel P. Berrangé, Markus Armbruster, Alex Bennée Cc'ing more developers. On 4/2/25 22:44, Philippe Mathieu-Daudé wrote: > ping? > > On 25/1/25 19:24, Philippe Mathieu-Daudé wrote: >> Update few QEMUTimer docstring and add a >> sanity check during timer initialization. >> >> Noticed trying to understand leaks in QDev >> Realize -> Unrealize -> Realize transition. >> >> Philippe Mathieu-Daudé (2): >> qemu/timer: Clarify timer_new*() must be freed with timer_free() >> qemu/timer: Sanity check timer_list in timer_init_full() >> >> include/qemu/timer.h | 12 +++++++++++- >> util/qemu-timer.c | 1 + >> 2 files changed, 12 insertions(+), 1 deletion(-) >> > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-02-09 17:42 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-25 18:24 [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2025-01-25 18:24 ` [PATCH 1/2] qemu/timer: Clarify timer_new*() must be freed with timer_free() Philippe Mathieu-Daudé 2025-02-06 10:39 ` Daniel P. Berrangé 2025-01-25 18:24 ` [PATCH 2/2] qemu/timer: Sanity check timer_list in timer_init_full() Philippe Mathieu-Daudé 2025-02-06 10:40 ` Daniel P. Berrangé 2025-02-09 9:37 ` Michael Tokarev 2025-02-09 9:41 ` Michael Tokarev 2025-02-09 17:41 ` Philippe Mathieu-Daudé 2025-02-04 21:44 ` [PATCH 0/2] qemu/timer: Clarify QEMUTimer new/free API Philippe Mathieu-Daudé 2025-02-06 9:44 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).