Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA340606A322 for ; Fri, 4 Dec 2026 13:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=VIdsZ7/I Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZTCf-0002GR-92; Fri, 04 Dec 2026 08:19:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZTCd-0002Ed-5a for qemu-rust@nongnu.org; Fri, 04 Dec 2026 08:19:55 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZTCa-0004uE-OP for qemu-rust@nongnu.org; Fri, 04 Dec 2026 08:19:54 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4bb85e07aadso10455005e9.1 for ; Fri, 04 Dec 2026 05:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796390391; x=1796995191; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=sOetbx5l8NjgrTHG0YY7eueLOeZYdsNK6pWcrlxnvi0=; b=VIdsZ7/IwV1AKNlx/1UkFa9tcA2tqRW0lIsiR1QxM190xVdCOpjHedU2EtZvwh36Lp wYgia6QVrXHRAavZHX0NJ3JTBhJrCZrzIooQ3c2uc9JlIVxy2MujEjgsKKHBvs0Qo8Mc CntrUS8Gp4igBh4LQp2PUmtHR69H+cUSKmAtTsZyUAO+eZ5572GvENbnXuqpqdowBqnL p0AfINJ/AgKvf9eKdSNEpwvgs7g9IHznCAWNM8P1YuepZweThswrAE9jGVVWB+c+xu7I MpNAZ1U/27jmsMLlJquKT96viQ1rOJB4PS0iDZG6XTGiPoWQNGhjtWko7Hu52b3c+L7O Fp2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796390391; x=1796995191; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=sOetbx5l8NjgrTHG0YY7eueLOeZYdsNK6pWcrlxnvi0=; b=AX73MGVfxYPUVWt2YGA5gowPPUvPuXkMFtVwEiUBhJ3AJt0CDpAwHOM54vtbZ9Sb4N MuYeRlWvVUsFQ5U7JiDj+kzSSxuTW1nLReR4SFY0mQYHdMRjUA6aApsLilPUXGVKJWnW k7YgMXq0gSFEWHDcb+r37FYLtpxkvlYWFEeZazkj/+6WfewHkEXdGAYJGMiqyWXJ9BJq cCjq+zdfoZcE79Lyto4NmZsEtStQ/w+dejPCSIHhXEqOFkrR7VcHW1HpAyX1CVdh720l P2Z90tVHXxUwH36Kj4DqLrtJuhqRxQ3bUwr4YsriMkyjiD60K7oQ3BxZXWwkPEyS2rpg 6O3g== X-Forwarded-Encrypted: i=1; AL+hErHyf60NTHG9jkEu4qhlHAourQromV2KuZ3+6QXlmtnqPfCNFFpRPfTK76NxvBKrj4yJ1EdK05giHw8=@nongnu.org X-Gm-Message-State: APuU4Z8/q4n2TeCSkvO/37hYZ8npz+P6mQ7/TEJKahqBhiwUPjdIszhm kOlGnZONMtSUL/CWbCwpc9UCkDJJGXeAZ3xu7qCfPkPH9wsCFgmtl8yz9ytX0aC8C1U= X-Gm-Gg: AZFdTZcDs+ZkC8bWVT/1W4l3TpMqop/qnsadf6BJnMGeqheBXB88P6vcdzzgFoZs4eo UDwfWiOjnO+WFAgp2g0kgxaEmH1kq8rKBhc2XnwF1bqEulPu72stT1Pm74hL5DtO+MGo2uTwbrZ kKWxf5bqOGtGMBEYOGR6IAfaHyyDGUgCcoVv/NbsEla6SjHx7s33XPPu9Jtyc9frbWrswBG0onx eF4SnuwUrhCbJ6Igy5JPur6hJ9n4Dz0soaolPabEYD8jIzP/dnBKndRz3IuHlBZNEACaUOfTZAa ujCI6gtDsO+2QBvAMLllWzywvZZKv0baRUboeBP/l+6xMzsEmXBu7+2LS6g3FmvoQPG4gAz5s34 Qwpiu1jrMzXQYiYE8njwSmFq82pusbPu0EcUwd21CF0lwOEe4j1p+p1Chi8Rz0SFgJo4eJkOjaB Faj81FDmUiuOzsXtZk4ASJI3JGof87v6UV7GOVeuuULHh9v4H+Ej/XJ8KqOcLrxzc+zr4waNVHN pg0rWAPJPkN91Xrtp0u95/oy2bWszieBQw88a06P2XwrzvIq6Jl0kS4dqor8fN+96Lv3L4f+SUD Vb8X+wRX85VpVm8nI7KpE80FgQzF9tHZxiFfKpBe5DPa4ZCbmIc75eTkfBVUN/byzpKm3APaDdG TauS01TEgESHQBGFlTHfTYz7x+b8EKarY5w== X-Received: by 2002:a05:600c:1d15:b0:4bb:5de1:e90f with SMTP id 5b1f17b1804b1-4bbeb8cf94cmr40683495e9.31.1796390390846; Fri, 04 Dec 2026 05:19:50 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1738cfb80sm5342097f8f.36.2026.12.04.05.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 05:19:50 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Fam Zheng , Manos Pitsidianakis , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Samuel Thibault , Paolo Bonzini , Thomas Huth , qemu-rust@nongnu.org Subject: [PATCH 3/6] util/qemu-timer: Add MemRentrancyGuard to timer_{init, new}_full() Date: Fri, 4 Dec 2026 13:19:43 +0000 Message-ID: <20261204131946.2175006-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204131946.2175006-1-peter.maydell@linaro.org> References: <20261204131946.2175006-1-peter.maydell@linaro.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-rust-bounces+qemu-rust=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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_ 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_ 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( attributes as c_int, Some(timer_cb), (opaque as *mut T).cast::(), + ::core::ptr::null_mut(), ) } } -- 2.43.0