From patchwork Fri Apr 6 12:38:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 132910 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp726678ljb; Fri, 6 Apr 2018 05:38:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49OWGl1UO4EJMIm4fGb6JEFzN0Yx1QVCP0Lh2kf1Os8vvUX8qHlokR+gXH3x/lKT3TEwoMw X-Received: by 10.28.116.7 with SMTP id p7mr7860823wmc.65.1523018327095; Fri, 06 Apr 2018 05:38:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523018327; cv=none; d=google.com; s=arc-20160816; b=kBU7GJwHF5rxjVhxlS+MiskXEQItGsSis5tI1MAPa++yKLG6yK9KVgLeC1q+2nXdbQ z6UfV8bpQKIQDksq0ZC42LWZe9KhMsgg1fejQ+yEbvu0lvr8IeFxJstN0rR6IaHydjF+ p92/vZxb9RXR6M4DsVO4DrN3nCr9c4GApx855NyrDi4VUi0cYg92+MLg7ytTKtgvRWQ7 gm13g6B9JyM3JemOIIlSG6ICS2AmdtPb9bh9aBUK9MUUvXA1oSZNbN0H9DVLabIC6thp /tBPvAeDYbIs3zq3/9krLIFJFf+WDwXfMh9kSE4yNmuPN5CSorBHjn4kkLhMwc8ypqi1 W6qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=nn0/Ra4W2byQd8XbzN5kwsFam7i9k6o1cM6cguAKh8M=; b=PeqJkqXAjJbZZj5L6n/yNjXBd+ctK/nnZZRJhLxu8xnYxycLIQeVnHaUoJiI3ryHqw iM/2zVVmiuZjqbFPiefDiHyfz7cTnIbBu834rR/uktZwCUOSnhag16PIAHa+QwDJeV/I lmGnlsdDQ+vj4yz04zMoF9P5t3duEbkdOQduryqG4TKou9r1iQFkZkGTCJkV9kaur1P3 I3JlME8aKaxqpPvC8nh3D+t9gyR0eYo/ObWlaEof1hrzsKoGzGELSDyfpeYJ9GUldLI9 yF9intS9R609kyvEsMA5bLWgN202MFaIsvzO33oUWQaqENf50f5KGs2qTfUgKzXfCEOQ 6+Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id u53si7734630wrb.184.2018.04.06.05.38.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Apr 2018 05:38:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1f4Qdb-0001bf-Bf; Fri, 06 Apr 2018 13:38:39 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, patches@linaro.org, Paolo Bonzini , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9e?= , "Emilio G. Cota" , "Pavel Dovgalyuk" Subject: [PATCH for-2.12] cpus.c: ensure running CPU recalculates icount deadlines on timer expiry Date: Fri, 6 Apr 2018 13:38:38 +0100 Message-Id: <20180406123838.21249-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 When we run in TCG icount mode, we calculate the number of instructions to execute using tcg_get_icount_limit(), which ensures that we stop execution at the next timer deadline. However there is a bug where currently we do not recalculate that limit if the guest reprograms a timer so that the next deadline moves closer, and so we will continue execution until the original limit and fire the timer later than we should. Fix this bug in qemu_timer_notify_cb(): if we are currently running a VCPU in icount mode, we simply need to kick it out of the main loop and back to tcg_cpu_exec(), where it will recalculate the icount limit. If we are not currently running a VCPU, then we retain the existing logic for waking up a halted CPU. Cc: qemu-stable@nongnu.org Fixes: https://bugs.launchpad.net/qemu/+bug/1754038 Signed-off-by: Peter Maydell --- Thanks to Paolo for tracking down which function needed fixing! cpus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.16.2 Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée diff --git a/cpus.c b/cpus.c index 2e6701795b..38eba8bff3 100644 --- a/cpus.c +++ b/cpus.c @@ -892,11 +892,19 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type) return; } - if (!qemu_in_vcpu_thread() && first_cpu) { + if (qemu_in_vcpu_thread()) { + /* A CPU is currently running; kick it back out to the + * tcg_cpu_exec() loop so it will recalculate its + * icount deadline immediately. + */ + qemu_cpu_kick(current_cpu); + } else if (first_cpu) { /* qemu_cpu_kick is not enough to kick a halted CPU out of * qemu_tcg_wait_io_event. async_run_on_cpu, instead, * causes cpu_thread_is_idle to return false. This way, * handle_icount_deadline can run. + * If we have no CPUs at all for some reason, we don't + * need to do anything. */ async_run_on_cpu(first_cpu, do_nothing, RUN_ON_CPU_NULL); }