From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [PULL 17/21] util/qemu-timer.c: Don't warp timer from timerlist_rearm()
Date: Fri, 7 Mar 2025 15:07:04 +0000 [thread overview]
Message-ID: <20250307150708.3222813-18-peter.maydell@linaro.org> (raw)
In-Reply-To: <20250307150708.3222813-1-peter.maydell@linaro.org>
Currently we call icount_start_warp_timer() from timerlist_rearm().
This produces incorrect behaviour, because timerlist_rearm() is
called, for instance, when a timer callback modifies its timer. We
cannot decide here to warp the timer forwards to the next timer
deadline merely because all_cpu_threads_idle() is true, because the
timer callback we were called from (or some other callback later in
the list of callbacks being invoked) may be about to raise a CPU
interrupt and move a CPU from idle to ready.
The only valid place to choose to warp the timer forward is from the
main loop, when we know we have no outstanding IO or timer callbacks
that might be about to wake up a CPU.
For Arm guests, this bug was mostly latent until the refactoring
commit f6fc36deef6abc ("target/arm/helper: Implement
CNTHCTL_EL2.CNT[VP]MASK"), which exposed it because it refactored a
timer callback so that it happened to call timer_mod() first and
raise the interrupt second, when it had previously raised the
interrupt first and called timer_mod() afterwards.
This call seems to have originally derived from the
pre-record-and-replay icount code, which (as of e.g. commit
db1a49726c3c in 2010) in this location did a call to
qemu_notify_event(), necessary to get the icount code in the vCPU
round-robin thread to stop and recalculate the icount deadline when a
timer was reprogrammed from the IO thread. In current QEMU,
everything is done on the vCPU thread when we are in icount mode, so
there's no need to try to notify another thread here.
I suspect that the other reason why this call was doing icount timer
warping is that it pre-dates commit efab87cf79077a from 2015, which
added a call to icount_start_warp_timer() to main_loop_wait(). Once
the call in timerlist_rearm() has been removed, if the timer
callbacks don't cause any CPU to be woken up then we will end up
calling icount_start_warp_timer() from main_loop_wait() when the rr
main loop code calls rr_wait_io_event().
Remove the incorrect call from timerlist_rearm().
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2703
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Message-id: 20250210135804.3526943-1-peter.maydell@linaro.org
---
util/qemu-timer.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index 3243d2c515c..788466fe22f 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -409,10 +409,6 @@ static bool timer_mod_ns_locked(QEMUTimerList *timer_list,
static void timerlist_rearm(QEMUTimerList *timer_list)
{
- /* Interrupt execution to force deadline recalculation. */
- if (icount_enabled() && timer_list->clock->type == QEMU_CLOCK_VIRTUAL) {
- icount_start_warp_timer();
- }
timerlist_notify(timer_list);
}
--
2.43.0
next prev parent reply other threads:[~2025-03-07 15:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 15:06 [PULL 00/21] target-arm queue Peter Maydell
2025-03-07 15:06 ` [PULL 01/21] hw/arm/smmu-common: Remove the repeated ttb field Peter Maydell
2025-03-07 15:06 ` [PULL 02/21] hw/gpio: npcm7xx: fixup out-of-bounds access Peter Maydell
2025-03-07 15:06 ` [PULL 03/21] tests/functional/test_arm_sx1: Check whether the serial console is working Peter Maydell
2025-03-07 15:06 ` [PULL 04/21] target/arm: Apply correct timer offset when calculating deadlines Peter Maydell
2025-03-07 15:06 ` [PULL 05/21] target/arm: Don't apply CNTVOFF_EL2 for EL2_VIRT timer Peter Maydell
2025-03-07 15:06 ` [PULL 06/21] target/arm: Make CNTPS_* UNDEF from Secure EL1 when Secure EL2 is enabled Peter Maydell
2025-03-07 15:06 ` [PULL 07/21] target/arm: Always apply CNTVOFF_EL2 for CNTV_TVAL_EL02 accesses Peter Maydell
2025-03-07 15:06 ` [PULL 08/21] target/arm: Refactor handling of timer offset for direct register accesses Peter Maydell
2025-03-07 15:06 ` [PULL 09/21] target/arm: Implement SEL2 physical and virtual timers Peter Maydell
2025-03-07 15:06 ` [PULL 10/21] target/arm: Document the architectural names of our GTIMERs Peter Maydell
2025-03-07 15:06 ` [PULL 11/21] hw/arm: enable secure EL2 timers for virt machine Peter Maydell
2025-03-07 15:06 ` [PULL 12/21] hw/arm: enable secure EL2 timers for sbsa machine Peter Maydell
2025-03-07 15:07 ` [PULL 13/21] target/arm: Correct LDRD atomicity and fault behaviour Peter Maydell
2025-03-07 15:07 ` [PULL 14/21] target/arm: Correct STRD atomicity Peter Maydell
2025-03-07 15:07 ` [PULL 15/21] target/arm: Drop unused address_offset from op_addr_{rr, ri}_post() Peter Maydell
2025-03-07 15:07 ` [PULL 16/21] target/arm: Make dummy debug registers RAZ, not NOP Peter Maydell
2025-03-07 15:07 ` Peter Maydell [this message]
2025-03-07 15:07 ` [PULL 18/21] include/exec/memop.h: Expand comment for MO_ATOM_SUBALIGN Peter Maydell
2025-03-07 15:07 ` [PULL 19/21] hw/arm/smmu: Introduce smmu_configs_inv_sid_range() helper Peter Maydell
2025-03-07 15:07 ` [PULL 20/21] target/rx: Set exception vector base to 0xffffff80 Peter Maydell
2025-03-07 15:07 ` [PULL 21/21] target/rx: Remove TCG_CALL_NO_WG from helpers which write env Peter Maydell
2025-03-09 0:41 ` [PULL 00/21] target-arm queue Stefan Hajnoczi
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=20250307150708.3222813-18-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 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).