All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: "Jason Wang" <jasowangio@gmail.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Samuel Thibault" <samuel.thibault@ens-lyon.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-rust@nongnu.org
Subject: Re: [PATCH 3/6] util/qemu-timer: Add MemRentrancyGuard to timer_{init, new}_full()
Date: Sat, 05 Dec 2026 11:51:36 +0200	[thread overview]
Message-ID: <tpkgs1.2dcfuzos76nfu@linaro.org> (raw)
In-Reply-To: <20261204131946.2175006-4-peter.maydell@linaro.org>

On Fri, 04 Dec 2026 15:19, Peter Maydell <peter.maydell@linaro.org> wrote:
>Add a MemReentrancyGuard parameter to timer_init_full() and
>timer_new_full(), so callers can specify a guard if they want to.
>Since there are not many direct callers of these two "full" functions
>we add the parameter here rather than having a new function
>timer_init_full_guarded().
>
>In a following commit we'll add _guarded() versions of some of the
>simpler timer initialization functions, which are what most callers
>will probably prefer over timer_init_full().
>
>Cc: qemu-stable@nongnu.org
>Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>---

The rust part is fine ("if it compiles it works")

For the patch:

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>

> include/qemu/aio.h             |  8 ++++----
> include/qemu/timer.h           | 17 ++++++++++++-----
> net/slirp.c                    |  4 ++--
> tests/unit/ptimer-test-stubs.c |  4 +++-
> ui/input.c                     |  3 ++-
> util/qemu-timer.c              |  5 +++--
> rust/util/src/timer.rs         |  1 +
> 7 files changed, 27 insertions(+), 15 deletions(-)
>
>diff --git a/include/qemu/aio.h b/include/qemu/aio.h
>index dbc5370eb03..b175d3f50d8 100644
>--- a/include/qemu/aio.h
>+++ b/include/qemu/aio.h
>@@ -628,7 +628,7 @@ static inline QEMUTimer *aio_timer_new_with_attrs(AioContext *ctx,
>                                                   int scale, int attributes,
>                                                   QEMUTimerCB *cb, void *opaque)
> {
>-    return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque);
>+    return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque, NULL);
> }
> 
> /**
>@@ -648,7 +648,7 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type,
>                                        int scale,
>                                        QEMUTimerCB *cb, void *opaque)
> {
>-    return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque);
>+    return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque, NULL);
> }
> 
> /**
>@@ -670,7 +670,7 @@ static inline void aio_timer_init_with_attrs(AioContext *ctx,
>                                              int scale, int attributes,
>                                              QEMUTimerCB *cb, void *opaque)
> {
>-    timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque);
>+    timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque, NULL);
> }
> 
> /**
>@@ -690,7 +690,7 @@ static inline void aio_timer_init(AioContext *ctx,
>                                   int scale,
>                                   QEMUTimerCB *cb, void *opaque)
> {
>-    timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque);
>+    timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque, NULL);
> }
> 
> /**
>diff --git a/include/qemu/timer.h b/include/qemu/timer.h
>index 11bcc3f0d36..1287682de61 100644
>--- a/include/qemu/timer.h
>+++ b/include/qemu/timer.h
>@@ -394,6 +394,8 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg);
>  * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
>  * @cb: the callback to be called when the timer expires
>  * @opaque: the opaque pointer to be passed to the callback
>+ * @reentrancy_guard: A guard set when entering @cb to prevent
>+ *    device-rentrancy issues. Optional; NULL for no guard.
>  *
>  * Initialise a timer with the given scale and attributes,
>  * and associate it with timer list for given clock @type in @timer_list_group
>@@ -406,7 +408,8 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg);
> void timer_init_full(QEMUTimer *ts,
>                      QEMUTimerListGroup *timer_list_group, QEMUClockType type,
>                      int scale, int attributes,
>-                     QEMUTimerCB *cb, void *opaque);
>+                     QEMUTimerCB *cb, void *opaque,
>+                     MemReentrancyGuard *reentrancy_guard);
> 
> /**
>  * timer_init:
>@@ -423,7 +426,7 @@ void timer_init_full(QEMUTimer *ts,
> static inline void timer_init(QEMUTimer *ts, QEMUClockType type, int scale,
>                               QEMUTimerCB *cb, void *opaque)
> {
>-    timer_init_full(ts, NULL, type, scale, 0, cb, opaque);
>+    timer_init_full(ts, NULL, type, scale, 0, cb, opaque, NULL);
> }
> 
> /**
>@@ -485,6 +488,8 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type,
>  * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
>  * @cb: the callback to be called when the timer expires
>  * @opaque: the opaque pointer to be passed to the callback
>+ * @reentrancy_guard: A guard set when entering @cb to prevent
>+ *    device-rentrancy issues. Optional; NULL for no guard.
>  *
>  * Create a new timer with the given scale and attributes,
>  * and associate it with timer list for given clock @type in @timer_list_group
>@@ -507,10 +512,12 @@ static inline void timer_init_ms(QEMUTimer *ts, QEMUClockType type,
> static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group,
>                                         QEMUClockType type,
>                                         int scale, int attributes,
>-                                        QEMUTimerCB *cb, void *opaque)
>+                                        QEMUTimerCB *cb, void *opaque,
>+                                        MemReentrancyGuard *reentrancy_guard)
> {
>     QEMUTimer *ts = g_new0(QEMUTimer, 1);
>-    timer_init_full(ts, timer_list_group, type, scale, attributes, cb, opaque);
>+    timer_init_full(ts, timer_list_group, type, scale, attributes,
>+                    cb, opaque, reentrancy_guard);
>     return ts;
> }
> 
>@@ -532,7 +539,7 @@ static inline QEMUTimer *timer_new_full(QEMUTimerListGroup *timer_list_group,
> static inline QEMUTimer *timer_new(QEMUClockType type, int scale,
>                                    QEMUTimerCB *cb, void *opaque)
> {
>-    return timer_new_full(NULL, type, scale, 0, cb, opaque);
>+    return timer_new_full(NULL, type, scale, 0, cb, opaque, NULL);
> }
> 
> /**
>diff --git a/net/slirp.c b/net/slirp.c
>index eea12e79816..298695a6766 100644
>--- a/net/slirp.c
>+++ b/net/slirp.c
>@@ -212,7 +212,7 @@ static void *net_slirp_timer_new_opaque(SlirpTimerId id,
>     t->cb_opaque = cb_opaque;
>     timer_init_full(&t->timer, NULL, QEMU_CLOCK_VIRTUAL,
>                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
>-                    net_slirp_timer_cb, t);
>+                    net_slirp_timer_cb, t, NULL);
>     return t;
> }
> #else
>@@ -222,7 +222,7 @@ static void *net_slirp_timer_new(SlirpTimerCb cb,
>     SlirpTimer *t = g_new(SlirpTimer, 1);
>     timer_init_full(&t->timer, NULL, QEMU_CLOCK_VIRTUAL,
>                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
>-                    cb, cb_opaque);
>+                    cb, cb_opaque, NULL);
>     return t;
> }
> #endif
>diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c
>index da46dda32d2..2f18d626b37 100644
>--- a/tests/unit/ptimer-test-stubs.c
>+++ b/tests/unit/ptimer-test-stubs.c
>@@ -37,7 +37,8 @@ bool qtest_allowed;
> void timer_init_full(QEMUTimer *ts,
>                      QEMUTimerListGroup *timer_list_group, QEMUClockType type,
>                      int scale, int attributes,
>-                     QEMUTimerCB *cb, void *opaque)
>+                     QEMUTimerCB *cb, void *opaque,
>+                     MemReentrancyGuard *reentrancy_guard)
> {
>     if (!timer_list_group) {
>         timer_list_group = &main_loop_tlg;
>@@ -48,6 +49,7 @@ void timer_init_full(QEMUTimer *ts,
>     ts->scale = scale;
>     ts->attributes = attributes;
>     ts->expire_time = -1;
>+    ts->reentrancy_guard = reentrancy_guard;
> }
> 
> void timer_mod(QEMUTimer *ts, int64_t expire_time)
>diff --git a/ui/input.c b/ui/input.c
>index f40a9883701..846b936ba40 100644
>--- a/ui/input.c
>+++ b/ui/input.c
>@@ -431,7 +431,8 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms)
>     if (!kbd_timer) {
>         kbd_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
>                                    SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
>-                                   qemu_input_queue_process, &kbd_queue);
>+                                   qemu_input_queue_process, &kbd_queue,
>+                                   NULL);
>     }
>     if (queue_count < queue_limit) {
>         qemu_input_queue_delay(&kbd_queue, kbd_timer,
>diff --git a/util/qemu-timer.c b/util/qemu-timer.c
>index 6658e5e623d..946c3dab13d 100644
>--- a/util/qemu-timer.c
>+++ b/util/qemu-timer.c
>@@ -352,7 +352,8 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout)
> void timer_init_full(QEMUTimer *ts,
>                      QEMUTimerListGroup *timer_list_group, QEMUClockType type,
>                      int scale, int attributes,
>-                     QEMUTimerCB *cb, void *opaque)
>+                     QEMUTimerCB *cb, void *opaque,
>+                     MemReentrancyGuard *reentrancy_guard)
> {
>     if (!timer_list_group) {
>         timer_list_group = &main_loop_tlg;
>@@ -363,7 +364,7 @@ void timer_init_full(QEMUTimer *ts,
>     ts->scale = scale;
>     ts->attributes = attributes;
>     ts->expire_time = -1;
>-    ts->reentrancy_guard = NULL;
>+    ts->reentrancy_guard = reentrancy_guard;
> }
> 
> void timer_deinit(QEMUTimer *ts)
>diff --git a/rust/util/src/timer.rs b/rust/util/src/timer.rs
>index f8e65c9a0ac..9533b34deb8 100644
>--- a/rust/util/src/timer.rs
>+++ b/rust/util/src/timer.rs
>@@ -85,6 +85,7 @@ pub fn init_full<T, F>(
>                 attributes as c_int,
>                 Some(timer_cb),
>                 (opaque as *mut T).cast::<c_void>(),
>+                ::core::ptr::null_mut(),
>             )
>         }
>     }
>-- 
>2.43.0
>


  parent reply	other threads:[~2026-12-05  9:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:19 [PATCH 0/6] util/qemu-timer: Support reentrancy guard and use in pcnet, hcd-xhci Peter Maydell
2026-12-04 13:19 ` [PATCH 1/6] util/qemu-timer: Make timerlist_run_timers() file local Peter Maydell
2026-12-04 14:51   ` Thomas Huth
2026-12-05  9:48   ` Manos Pitsidianakis
2026-12-04 13:19 ` [PATCH 2/6] util/qemu-timer: Add optional reentrancy guard to the timer API Peter Maydell
2026-12-04 15:00   ` Thomas Huth
2026-12-04 15:05     ` Peter Maydell
2026-12-04 15:10       ` Thomas Huth
2026-12-04 13:19 ` [PATCH 3/6] util/qemu-timer: Add MemRentrancyGuard to timer_{init, new}_full() Peter Maydell
2026-12-04 15:22   ` [PATCH 3/6] util/qemu-timer: Add MemRentrancyGuard to timer_{init,new}_full() Thomas Huth
2026-12-05  9:51   ` Manos Pitsidianakis [this message]
2026-12-04 13:19 ` [PATCH 4/6] util/qemu_timer: Add timer_new_ns_guarded() Peter Maydell
2026-12-04 15:26   ` Thomas Huth
2026-12-04 15:52     ` Peter Maydell
2026-12-04 13:19 ` [PATCH 5/6] hw/usb/hcd-xhci: Use timer reentrancy-guard API Peter Maydell
2026-12-04 15:28   ` Thomas Huth
2026-12-04 13:19 ` [PATCH 6/6] hw/net/pcnet: Use timer_new_ns_guarded() Peter Maydell
2026-12-04 15:28   ` Thomas Huth
2026-12-05  9:53   ` Manos Pitsidianakis
2026-12-04 15:32 ` [PATCH 0/6] util/qemu-timer: Support reentrancy guard and use in pcnet, hcd-xhci Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tpkgs1.2dcfuzos76nfu@linaro.org \
    --to=manos.pitsidianakis@linaro.org \
    --cc=fam@euphon.net \
    --cc=jasowangio@gmail.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=samuel.thibault@ens-lyon.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.