From patchwork Mon Feb 10 13:58:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 863773 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp1604309wrt; Mon, 10 Feb 2025 05:59:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVf4P4sSJmL8SQf/+0bL8G5T0T4qBJ/PO/nFHeJqDbmja37/Yzjcsq15Ytypc9pEyVH6dMQCA==@linaro.org X-Google-Smtp-Source: AGHT+IHA6xYJ2jgQSdHP63oGGsoCyw8szB+o6yyaj1Bhz9aHrhj1XBNG/umZuvyRFpf7Gh0HQJqL X-Received: by 2002:a05:620a:4556:b0:7c0:60d5:77d2 with SMTP id af79cd13be357-7c060d5797dmr352141485a.19.1739195943780; Mon, 10 Feb 2025 05:59:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1739195943; cv=none; d=google.com; s=arc-20240605; b=H+1cJX1yYpYzY+Dw6ts0hXt2eMt84Bo9sthrWkQznDO7ALRnJYLoPuTDFTyUbnpGCG 7jgnDsY+BF1a7nyPAmhyZj7O16FtyyM0F0hMx3EQIgyoj0UEjAlxsIZ+3fidyopNFEx2 Ztsx8HB9oomo7d4G2GhfEJvLbbS3Kugu6j0kpleeq2RsLIBIAd+kpfqaivkN/L+V3i4I YKE+NW8zDHOQpugLYtOMMoPBREc6OX61E9mWvgq7myvNzNMD8+dmxvD0uBgx6yLYNtGg lbSOUcp9EG23SFO2VjXB4FXhw/y8oq6w9Y0IRaneGor5wtGpJWijtz15rsAbsywJKk5N o4wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=pftZOTu4W41f/6GB8KhGZh3z4DebWeK+fUoY69RtqXY=; fh=vclVPaqTrchsE3MPkF4TzOsAGcIJfa73jkjIcMQqnrg=; b=ciiJiQTW/ty9COqc7xev7Cd+kZBx1JoFsju+WRgIUfFCxDX76xilc7IVcQqEttI8R+ B+EHyKgRRfMmKJu3159p1W6s/u8xrqu2fUD0Kc2Vz8cy0rwnvdjf+0UGo9ohaSqbQZrM /p7ejJGqlG9k0PvTLt2e54yKO+7EnJzM4hH2MWy2IzTyOfU+uz2APSHYkuHO7jipJzpy X9R13ooSaZB1mA+PgW68lf8SGykZFB5a9jPJXBbViapUL1hXs/eOug/XYN4/ELIHDdZW QFBlmQ21yAB9N1SGJ7fWBxcdwiqWE6bbzBKc/r1uvpmTLLzTVldX5nXwo3ROVkZ1HqrA teQA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jCSaHVrD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7c05f404d34si191502685a.652.2025.02.10.05.59.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Feb 2025 05:59:03 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jCSaHVrD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1thUIe-0006nz-BU; Mon, 10 Feb 2025 08:58:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1thUIc-0006nR-RV for qemu-devel@nongnu.org; Mon, 10 Feb 2025 08:58:10 -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 1thUIa-0001iZ-Hp for qemu-devel@nongnu.org; Mon, 10 Feb 2025 08:58:10 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4361815b96cso29298665e9.1 for ; Mon, 10 Feb 2025 05:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739195887; x=1739800687; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=pftZOTu4W41f/6GB8KhGZh3z4DebWeK+fUoY69RtqXY=; b=jCSaHVrDrvA46bnP+siUyl2uB0KgCHFs5Nj0ZJKT68F+5Ew/Ka6kVnUcI/8a6j55zQ kxvpNGfkJEaMLLJV0shWIvRBulu9Pct8Dqx5lCesUj8yP7gpoq6egjlsFRzSIZXhUZkK /pPh29bBZFUWg0ipUFzaj28g2tDDkhtc7lAIcP3miveX04cOnqTYtqvaMiZHkuQi1viW pOUeu5WxNegKJDnvn/+wCsxy6RqixKJ0Ny/I1u+pIWnNiVx9/24bU0G1Y6mT3KcmF67r z5aroXO8GtFHScK9rqbROe8+vRkwjkVipQWW+PMOLaD/iiLruwcaoyZzSE0qnN2Hy7rH 1KzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739195887; x=1739800687; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pftZOTu4W41f/6GB8KhGZh3z4DebWeK+fUoY69RtqXY=; b=eCzWwFNXj5EFXtTMxPhfCIQ2DtpVJl6Ln1nNrCbooReuV7cZy/X/QiTf9ZmIfdHvrj l5btWXBsIY+ROTmWlb5RTEp9eSwgqBtJtJFMUvmOQJsabNctfZEFpFyRGv+5WyZ16Kt6 1iVOj5pt6DWWHiaUKCszbJYfwXZdQePwiX73sbpDl93R4NBcVRBGLg9SN53rkreCRiIO iIGPlkQEtOXy7cd9v94TMDI+UdvVnrTKWmBqp9A3mdegfvt0c/sM1L72ikq2lTxZ/zhG oisX3Q4o9HM7k+fTMksfnKE/M6jqj8iT9kqyz+VTyiEJKwbl1zGgSf6QBv3JRGmd9bVE lpvQ== X-Forwarded-Encrypted: i=1; AJvYcCUYrFN0IVlrrO698g6BuE8rGtSVl932O1aUT9TL/CLeyBZF3nEbjBezHSeh8q1CdKWUv86itzcs62La@nongnu.org X-Gm-Message-State: AOJu0YzGQ0b1d+Q+0UkuEJOUCE1yN9xFZ9kUow6oG1q4w+ilmK0xgreX zN16k6skIk6k2mO0wWze3SPtqm/fn7Ck+oQ7jsQQbI3FKqFoF01c0Hutux4OQVuYWppozm0VWUk f X-Gm-Gg: ASbGncvqIjeohbSpJ5SxcyivF+IjIQDTVAO8YIG+UctX6l2hQDHq8ho9+KVaccUDBIL pniwghXpcGTY+62bEK4n4VIPmv3MMyaGNP0pnEzAQSoVMlwTuXVrULXXKRWSkbiWKaLOaDkI/p1 lAucafKYNA8u6SQNt4mObk1EpNNSblBbZEq367wrSeJ/qe3k3o74s3DvvIkJIJWDNhNcxMZnZGE oZsy4jXdKvF5v7rXuZooKJC/jzlfZGQCht9wypXDzhAWw60k7dcGSYrl9GBErbNDKPLhdtKzYRf BF8Rx9018Y0X689Qlo4HUA== X-Received: by 2002:a05:6000:1865:b0:386:1cd3:8a03 with SMTP id ffacd0b85a97d-38dc9346494mr10134005f8f.32.1739195886658; Mon, 10 Feb 2025 05:58:06 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38dd187360asm7596636f8f.43.2025.02.10.05.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 05:58:05 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Paolo Bonzini Subject: [PATCH] util/qemu-timer.c: Don't warp timer from timerlist_rearm() Date: Mon, 10 Feb 2025 13:58:04 +0000 Message-Id: <20250210135804.3526943-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.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.5A 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 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Tested-by: Alex Bennée --- As far as I can tell, this is the right thing, and it fixes the "icount warps the timer when it should not" bug I'm trying to address, but I'm not super familiar with the icount subsystem or its evolution, so it's possible I've accidentally broken some other setup here. This does pass the tcg, functional and avocado tests, including the record-and-replay ones. I've cc'd it to stable as a bugfix, but it definitely merits careful review first. --- util/qemu-timer.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 0e8a453eaa1..af6e1787e57 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); }