From mboxrd@z Thu Jan 1 00:00:00 1970 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 508A6606A322 for ; Sat, 5 Dec 2026 09:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=dQ+47g5/ Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZmRs-0002Mv-Q8; Sat, 05 Dec 2026 04:52:56 -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 1xZmRq-0002LN-Cj for qemu-devel@nongnu.org; Sat, 05 Dec 2026 04:52:54 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xZmRo-0008TE-AB for qemu-devel@nongnu.org; Sat, 05 Dec 2026 04:52:54 -0500 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4bb70074ab2so12737165e9.0 for ; Sat, 05 Dec 2026 01:52:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1796464371; x=1797069171; darn=nongnu.org; h=content-type:content-transfer-encoding:mime-version:message-id :in-reply-to:references:user-agent:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=ym6lFF5Iuk6Vil/+zd72+q4hBi1lEUo8DuYMpBCPNZY=; b=dQ+47g5/9bOkWu92VEO9AsuDfv75C36O9QddfOHRWmto2efAGZnl4rDOjUGgyiMbmX wkj/VtFqLuZLb4ZhbUzG1ZWHQDl9lJSazBvhiUeRjunBLG/SPubRts2SevpeIbiZabmq 4+rTGwosnoyiDQnYwClmJHSJq3ihIuipVjexASp48GRUYhhZ9JKqHaxJQscVPFaSWFh7 wT+2hLRGyhazndClr+ltcr041Tj0wrRVIK9STaJ5ebFcpJ6vPFE27YFcm8muB8oZdm3R xkA7xTPrUYof6dGm/RpwOfdRMLCOWOz3H4WhQ8DaqOFmU1E/583obJkHJ5zFgM+hoNuX EB+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796464371; x=1797069171; h=content-type:content-transfer-encoding:mime-version:message-id :in-reply-to:references:user-agent:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ym6lFF5Iuk6Vil/+zd72+q4hBi1lEUo8DuYMpBCPNZY=; b=WRqZv5FvEwsxH5dCe1DsK69zPGav4uH1A5C0hTpi1RdTmTxpa/AGY3RRG3DNHpArr3 95iTYhSRNLAJsK7YxasgFGtCc+n6mIJbrGvwBNzf1Uyo0XRBoKVXKAL/U0l806o70g79 OohGh2aSV3V3eh90X9pEjN8B5yS/htlNelUBmwrGv7pb01hu783IEos8nEOQbJQ89NdF VopuQ65G8woEy9x8q4AtiytRhqTUrvWWjtCFwtNciMPUhQcrfv+vyohWsa5FkJ0PyPkS P0ZZREvlXONST+mdIU0h5lwDfrsjvyfQXaKoz3COFK4JiBtwQsgma5G9CjGrHXo5f9ut j0mA== X-Forwarded-Encrypted: i=1; AL+hErHU4my4R0yAiPB0idCFpDQNRALLpGkCGTF8Lfs+zryhCc3n+isqXZRtX0bcyenLzEwa6+cDHOryl9qq@nongnu.org X-Gm-Message-State: APuU4Z/odzrzo/KDdwVEDFvVEL1og/EYMdMErH6Nyq4PN7DuM/Sly36Y fUXl6Qc9NKeUPFGutCN69VxZH4H9cxSpTXqjcgn6FOFcT5A81RGHeKwAGLluALkFFXs= X-Gm-Gg: AZFdTZcj3tqMitIZycPHPrCZWKFo3ZEDzFZdQCupw0SGne6UWX9tP5dWcZTBpjgNcYX SaIy7eJQl2prscZQvRYJdFH2L9LflblpZqeNfckNBvdKxLpQmJIpBVBPQLBMsPJ133Jfgztl8G3 ssk26XX1N1pe3rnkEECm74lBfeJBi9aeS0hRnWvgyjUOx5K63poVGR5JWbeDo5I+ZQv0VQC4KX6 3Zlhnojx2sdL1I4oO3mU/cPpNOXiH6jFkPukNUZExQC4pATTlNwzQpPl76UHfhlY+t2hgwYtEyS 4OoBtUgrUCzvJ/vuJQ2O8s2BwDOpVoD8/bvEjwwfYo+LjXN90MuanhQxWOsKJoDyTIdQRPgMicX I3ce2oWWKeINubn/lvqubJDaslpUJ+liUvarZDyEEsiGoM3sKHQh1A9LtceQ1weuGFRJ6rJaNRz 9JrV2BfVyqUks+n6kr/lns08Qbbe8R32XdICXQjJdlPlEr+1Tncfy72kdMcokiJWnM1D1dii0sj MFcFhoaOQmFOGf84jJQswNSoRbC//3vPdwQd4YjV3xibpJ73Pj4fuus+NinHHoG2ti1pO4LLWUs yNZnt3vG7qi6Bk/wE8NH432GAppEbMsFoiYkeps1EpZUaxlShdHMEL8nO/GWBIiKIHnv6g4ubA7 b8v64S51zOEbfUTIxPSbFX94EityNfsvoug8pJvmQJupgNeO5eLBbLFifu/FO2t5mq7Kwx9T7Jn oZa25IU6pkfl59y/krzZoTQeG80KY6FW+AcCWSt50FGvh3IIFzxwA6F/ZmSmVyqbn/76MN X-Received: by 2002:a05:600c:3b0d:b0:4bb:a5e1:74ac with SMTP id 5b1f17b1804b1-4bbeb6ef6e9mr84016085e9.4.1796464370635; Sat, 05 Dec 2026 01:52:50 -0800 (PST) Received: from meli-email.org (athedsl-4431069.home.otenet.gr. [79.129.140.205]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d16e1a59a3sm10175816f8f.7.2026.12.05.01.52.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Dec 2026 01:52:50 -0800 (PST) Date: Sat, 05 Dec 2026 11:51:36 +0200 From: Manos Pitsidianakis To: Peter Maydell , qemu-devel@nongnu.org Cc: Jason Wang , Stefan Hajnoczi , Fam Zheng , Manos Pitsidianakis , Marc-Andr=?UTF-8?B?w6k=?= Lureau , Samuel Thibault , Paolo Bonzini , Thomas Huth , qemu-rust@nongnu.org Subject: Re: [PATCH 3/6] util/qemu-timer: Add MemRentrancyGuard to timer_{init, new}_full() User-Agent: meli/0.9.0 References: <20261204131946.2175006-1-peter.maydell@linaro.org> <20261204131946.2175006-4-peter.maydell@linaro.org> In-Reply-To: <20261204131946.2175006-4-peter.maydell@linaro.org> Message-ID: X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8"; format=flowed Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm1-x336.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-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-13.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 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 On Fri, 04 Dec 2026 15:19, Peter Maydell 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 >--- The rust part is fine ("if it compiles it works") For the patch: Reviewed-by: Manos Pitsidianakis > 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 >