From patchwork Fri Mar 7 15:07: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: 871204 Delivered-To: patch@linaro.org Received: by 2002:a5d:64c8:0:b0:38f:210b:807b with SMTP id f8csp811985wri; Fri, 7 Mar 2025 07:14:25 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUh4fgQ+z3ilpetheqhBrytd9os1Bkv30CC5YJ4h7vxIuBQnLjkrtjH2jk74yFfFwbiQZBKiw==@linaro.org X-Google-Smtp-Source: AGHT+IHW4u2FNf09vgR/aVg+RlpD1UV7jK73NYCxHgBnp1r6XxsgHo0VxOLWhZkDkZbhYAe/o+DJ X-Received: by 2002:a05:6102:2d09:b0:4bb:e1c9:80c6 with SMTP id ada2fe7eead31-4c30a344411mr2990827137.0.1741360465187; Fri, 07 Mar 2025 07:14:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1741360465; cv=none; d=google.com; s=arc-20240605; b=VuWYkVesrsyOoyR/WdEKlFBpRtubV35Osio1UjEb1191iMplWioEKsjRolG5PR1aa2 YYACrptiLR5MnQCoV+7ZXYOOvQ29Ke69su+tYjYS3Oviz1qlchE+QB1GQ028S13LlSP/ z2/kk7+XcVRi895eEUPe5tMR0ZsIJFxlwAVGf6rzbcULo7c5ASzbjI4ic7bKVGOcdFSw 1i7XAi3qrSC+AJ+Nn+bZHEWNhmC5XCmTB+3gGM8/3yBah2oOE3pJr3M/0ixP5R7n1rnQ NRFtgkwZ+P6LFur4QpueejjJUZowh58DVuGz8POtCsYeYCDQ1vnMAopYGtGhqew3TZEl 67YA== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=cZx+EJrwSEPWcdmfK70Ab9fdIcmzEh488cpidIw4fLI=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=XsIWKwV3zuRL78NpFMRwUO2OlhooVbDJLN6Cen9eTNLYYZT/kPLTtFsCtE+ATATKSx IpEWSTUC6B+IZeJn/HVr4q2ajvansZvCRWKv/+lJVMYbLYH5EJzEpRBHHDujsaHAWwd1 pFGDqFPhEDXanBewUv1RdyN5dX3YnOCCg+7hsGlQfwht7opDFM9doIqNM0RS4E3Lun1Q PVZWUA6LYDndGhKXuXDRr+uKpqEtri0ZJ9Z0uREi55H9X9E2UX2bOQgPuKuuNPKbqIMW ISuTxh4bO9w28YP8Xe1YF83rpFz68cgbhq9xW3hl8euV59RdDeoqaTROPB7L9382S9sn Ue5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s3p1s0At; 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 ada2fe7eead31-4c2fb456f2fsi923230137.141.2025.03.07.07.14.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Mar 2025 07:14:25 -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=s3p1s0At; 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 1tqZIW-00012q-Fk; Fri, 07 Mar 2025 10:07:36 -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 1tqZIU-00011v-8N for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:34 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tqZIS-0008LB-Ad for qemu-devel@nongnu.org; Fri, 07 Mar 2025 10:07:33 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-39133f709f5so445724f8f.0 for ; Fri, 07 Mar 2025 07:07:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741360051; x=1741964851; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cZx+EJrwSEPWcdmfK70Ab9fdIcmzEh488cpidIw4fLI=; b=s3p1s0AtaBCx4R6UVezKIoBO7u64BmVlTqlohBdAkLXPv20EsZ/7HC7jsaZs/6tTkX /sr42D3fdgqpA9PAa/nBlhgs0wp33h6EC76cFabE4F+325EQJzJ8QmVIj12byle3O9Fo hBn39WaHPB/JZKNcJD0s4KC1yVwVULC45qS0RWY7GuLlc2y+7CjCL/1KGL8kKv6xyrV6 VyUikuCrDrRncJz67+7P7P6WkNBeLNw+Hs8SKBIocot2ENfsa8Rwt6CeJ5qpZrVk6J9s 9MzbQQbyHabZ+U7ClE7wphub3PrzyW5arVMVC+y48y1GzRHMhWgxJo9wpRR7AfSvrMJy vL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741360051; x=1741964851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cZx+EJrwSEPWcdmfK70Ab9fdIcmzEh488cpidIw4fLI=; b=ouwCFN6JjvaxFztLwD5leRxSBma7PAdVEO3zQOrYgkGx7Ayd4AVqaJ8FpA+LJWnAlo 0AtgneboD4HiWvXFLafPYTGqinHSzy6NdZCndSJfwAv6+muMBJVwQZLYdgumLK/Hf9ek 4vwuaOr8BmNkv6EZkbK399dSZCZ70pJgHShov80Z94IPyLpRINdsygW7FCGtWT0DmJxO dufex/yicWgcs/a8sjcPl2+LMzA+FFvawH2vJlf7ClXWTZkoUld+zIVK9hPVB/HHOC9p J5IEB+EtiJqa1bVlThhCaD/xzN9ZF42igwGW6lm53Gz6H1UDrwSeQxmL3OyVgA2lC6Nj iUhw== X-Gm-Message-State: AOJu0YxjGpY5gZrc4IEEVMBIkzLeys6ZIJF//I2XvF5DnrNa36AJzcKB 66yRnE5Y4ZxVa22k43pEEbhvhZtL5aOQ0FtCoDwpIlRZ+QmeqMqR3EhYhoS0H587qQcaw8DxpYV N X-Gm-Gg: ASbGnctTAzT7xKfAKsLD3i13CQYo/0PJ2K+iqQnFVrchTAT7uZ/4HKcrC2EgXE0pbvO jV4DArH4bWUp9fWU0s1X3/Jh24HbD5j+D5xTns3PEYhA5JBEeLQM3fAPSaB70772dt/wbRF+91m QbZ00Onr7t/OfPpy16AmxH4avW/aocm/VgzUP7VkIhX1UjZornKABSP8jQSdWSqtHroH6xog9on mDrSN/RP1/cIeWpdtuSo1OQJs0Li7RcVCqQWau/zLmXPqvdJsJ2lvEVzHEFv3p/yPnSbT3F9cud RAVGZtx8lqm19Vjr61rQFZCaTGDSSgeqq0CjLKodtTKckVhOnwU= X-Received: by 2002:a5d:584f:0:b0:391:ffc:2413 with SMTP id ffacd0b85a97d-39132da08b4mr2428556f8f.40.1741360050752; Fri, 07 Mar 2025 07:07:30 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912c1031fdsm5443627f8f.89.2025.03.07.07.07.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Mar 2025 07:07:30 -0800 (PST) From: Peter Maydell 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 Message-ID: <20250307150708.3222813-18-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250307150708.3222813-1-peter.maydell@linaro.org> References: <20250307150708.3222813-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.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. 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 Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Tested-by: Alex Bennée 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); }