Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2227432/?format=api
{ "id": 2227432, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2227432/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260423170229.64655-14-philmd@linaro.org/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.1/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260423170229.64655-14-philmd@linaro.org>", "date": "2026-04-23T17:02:25", "name": "[13/16] target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "db82518f55f39c5d2af892aba3f0ce14a1828b22", "submitter": { "id": 85046, "url": "http://patchwork.ozlabs.org/api/1.1/people/85046/?format=api", "name": "Philippe Mathieu-Daudé", "email": "philmd@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260423170229.64655-14-philmd@linaro.org/mbox/", "series": [ { "id": 501223, "url": "http://patchwork.ozlabs.org/api/1.1/series/501223/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=501223", "date": "2026-04-23T17:02:12", "name": "accel/hvf: Assorted collection of patches queued before v11 release", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/501223/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2227432/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2227432/checks/", "tags": {}, "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=nGn0SSrq;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g1jDy10Sfz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 03:06:58 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wFxTv-0002op-5M; Thu, 23 Apr 2026 13:04:51 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wFxTL-0001hn-T7\n for qemu-devel@nongnu.org; Thu, 23 Apr 2026 13:04:17 -0400", "from mail-wm1-x334.google.com ([2a00:1450:4864:20::334])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <philmd@linaro.org>) id 1wFxTH-0005lc-VR\n for qemu-devel@nongnu.org; Thu, 23 Apr 2026 13:04:15 -0400", "by mail-wm1-x334.google.com with SMTP id\n 5b1f17b1804b1-4891f625344so54416995e9.0\n for <qemu-devel@nongnu.org>; Thu, 23 Apr 2026 10:04:11 -0700 (PDT)", "from localhost.localdomain (88-187-86-199.subs.proxad.net.\n [88.187.86.199]) by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-4891b46cffasm353820325e9.13.2026.04.23.10.04.08\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Thu, 23 Apr 2026 10:04:09 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=linaro.org; s=google; t=1776963850; x=1777568650; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=RrWv8gw/u68HSJbd/POGgEkEDudbWbGUOlVbg7Qyl6w=;\n b=nGn0SSrqsxYb4gNkZgaYMe8+7TeYcPVj3TR2+XSGmx7IqWNwkvXjKTgo0oJtgIAXxi\n jG5KigKuBhE+vj1+Is/2oWCISvfER6yzrsSFO+Y1d2bAPaV6Kh/wrgude5Vlehi2OSX8\n p2E/PR5WjOPb+jC87we0K0EOD4xyOqWLn5SmJ0cGpjEn82DYzDMFHcOLkLH8mve14tHN\n tCyieQJMkSa79t2u6Prj1lf8+QIGGev7UWmSCGVJkcGIGZ65zGcIQPyO2PcjHwnZBcRa\n qYA0zfWnXWz356rI1j1p9dztt2DVdrKXBr12wwSry5lY5fhJ2p/4PdN2/d7aw35dVKJD\n QqVQ==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776963850; x=1777568650;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=RrWv8gw/u68HSJbd/POGgEkEDudbWbGUOlVbg7Qyl6w=;\n b=GmPleOsxfjlyTbj8lr1X/msdQW6LaJnzYCwUdJk1dlBFDzqXG/cmA+uLe53kjNGcAF\n G0TBE3ph5TCFCAuafeokTZt+PCqX9wa4VfF7U9LmKnmGi1+rd+vsh/4cike5274hYgaA\n GDvmmTu61NVhjMTawS84174y6hK98gsBn9ReoNzXRVkNUrt4g9nCSOmYyUQ1moRZcY9v\n MGoFNhHz0PQKLwJJKYKCwCO3pKZjUj4r5ddGW5yxAmyVq7t9/n26B0B72MSD/1BjOfa+\n 1EbGxyTPldI7tKhh5SJMU/SKYNC+eXJRtzu+RRMZBSeLFthOxl7lf0g9g2rlGaplGCcC\n 7VkA==", "X-Gm-Message-State": "AOJu0YyvAkBtZ69EIOOu+m3Lbrh7Oym9ItyE6xuJPREHVG76jFHIJh3O\n vRbcOFnUbctiL3UGsBxuGm9uYcQnyDgpdGtbr9LzCN/sNT6aBTjOguxvsdism8tWYEKSe8+yKYT\n RXUgehYM=", "X-Gm-Gg": "AeBDievQcAUDRss01LzXrUgJ2tFols1FAbRBUbYPopyr2f3TKgLrEaQljNzHuxpzT+o\n gqZDanNIUPEVND3g88gAaMwyxIth0pwGBhydCzFbbTPbEVycrk2uSfSnQEs5vkxrpNCW5iKkGt9\n WiwgArwjl3vsTAx3cgxCPKw5uPjiJfOfiNFPsDfx5XQ2XHV4DeTbc/sbKYN2fD2Ad43oPL8ZfU0\n SKyd4UZkjPaGHkrj/nz4P58EekcvU/LuCndGyVoKd2mzxUE2+kXR+yK5iAy/ectQRuIGPrYY9Ho\n ZKwyN+bIwb5i7WaRnRxeh1QEmxzMuymAa/L2asu+R3hDHyntva94pyS0KTlOI3RS9ubX316KgLd\n rpMa5Qs0PeBC5Z+ZHeuWoO1IJMlN1I15kVPA8w+GCNR7G/ZNSVsYaMd5w8vMtG+7xALNRGvXFMu\n b42UZOLcD/VdoxejKjxUaUYLEhs4ri9hEIeu7kXiXwq5ReSaRBGrLWE900RViZ5B707KH/0FLmK\n vn5Mf9427E=", "X-Received": "by 2002:a05:600c:3150:b0:485:3cef:d6ea with SMTP id\n 5b1f17b1804b1-488fb8b9deamr320043925e9.13.1776963849896;\n Thu, 23 Apr 2026 10:04:09 -0700 (PDT)", "From": "=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>", "To": "qemu-devel@nongnu.org", "Cc": "Roman Bolshakov <rbolshakov@ddn.com>,\n Jonathan Cameron <jonathan.cameron@huawei.com>, Mads Ynddal <mads@ynddal.dk>,\n qemu-arm@nongnu.org, Mohamed Mediouni <mohamed@unpredictable.fr>,\n Peter Maydell <peter.maydell@linaro.org>,\n Richard Henderson <richard.henderson@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>, Alexander Graf <agraf@csgraf.de>,\n \"Scott J. Goldman\" <scottjgo@gmail.com>, =?utf-8?q?Philippe_Mathieu-Daud?=\n\t=?utf-8?q?=C3=A9?= <philmd@linaro.org>,\n Phil Dennis-Jordan <phil@philjordan.eu>", "Subject": "[PATCH 13/16] target/arm/hvf: Fix WFI halting to stop idle vCPU\n spinning", "Date": "Thu, 23 Apr 2026 19:02:25 +0200", "Message-ID": "<20260423170229.64655-14-philmd@linaro.org>", "X-Mailer": "git-send-email 2.53.0", "In-Reply-To": "<20260423170229.64655-1-philmd@linaro.org>", "References": "<20260423170229.64655-1-philmd@linaro.org>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2a00:1450:4864:20::334;\n envelope-from=philmd@linaro.org; helo=mail-wm1-x334.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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n 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 <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "From: \"Scott J. Goldman\" <scottjgo@gmail.com>\n\nCommit b5f8f77271 (\"accel/hvf: Implement WFI without using pselect()\")\nchanged hvf_wfi() from blocking the vCPU thread with pselect() to\nreturning EXCP_HLT, intending QEMU's main event loop to handle the\nidle wait. However, cpu->halted was never set, so cpu_thread_is_idle()\nalways returns false and the vCPU thread spins at 100% CPU per core\nwhile the guest is idle.\n\nFix this by:\n\n1. Setting cpu->halted = 1 in hvf_wfi() so the vCPU thread sleeps on\n halt_cond in qemu_process_cpu_events().\n\n2. Arming a host-side QEMU_CLOCK_HOST timer to fire when the guest's\n virtual timer (CNTV_CVAL_EL0) would expire. This is necessary\n because HVF only delivers HV_EXIT_REASON_VTIMER_ACTIVATED during\n hv_vcpu_run(), which is not called while the CPU is halted. The\n timer callback mirrors the VTIMER_ACTIVATED handler: it raises the\n vtimer IRQ through the GIC and marks vtimer_masked, causing the\n interrupt delivery chain to wake the vCPU via qemu_cpu_kick().\n\n3. Clearing cpu->halted in hvf_arch_vcpu_exec() when cpu_has_work()\n indicates a pending interrupt, and cancelling the WFI timer.\n\nFixes: b5f8f77271 (\"accel/hvf: Implement WFI without using pselect()\")\nSigned-off-by: Scott J. Goldman <scottjgo@gmail.com>\nReviewed-by: Mohamed Mediouni <mohamed@unpredictable.fr>\nMessage-ID: <20260410055045.63001-1-scottjgo@gmail.com>\nSigned-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>\n---\n include/system/hvf_int.h | 1 +\n target/arm/hvf/hvf.c | 65 +++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 65 insertions(+), 1 deletion(-)", "diff": "diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h\nindex 2621164cb22..df13cc650fd 100644\n--- a/include/system/hvf_int.h\n+++ b/include/system/hvf_int.h\n@@ -48,6 +48,7 @@ struct AccelCPUState {\n hv_vcpu_exit_t *exit;\n bool vtimer_masked;\n bool guest_debug_enabled;\n+ QEMUTimer *wfi_timer;\n #endif\n };\n \ndiff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c\nindex f2c5bde5983..33595bac72c 100644\n--- a/target/arm/hvf/hvf.c\n+++ b/target/arm/hvf/hvf.c\n@@ -28,6 +28,7 @@\n #include \"hw/core/boards.h\"\n #include \"hw/core/irq.h\"\n #include \"qemu/main-loop.h\"\n+#include \"qemu/timer.h\"\n #include \"system/cpus.h\"\n #include \"arm-powerctl.h\"\n #include \"target/arm/cpu.h\"\n@@ -301,6 +302,8 @@ void hvf_arm_init_debug(void)\n #define TMR_CTL_IMASK (1 << 1)\n #define TMR_CTL_ISTATUS (1 << 2)\n \n+static void hvf_wfi_timer_cb(void *opaque);\n+\n static uint32_t chosen_ipa_bit_size;\n \n typedef struct HVFVTimer {\n@@ -1218,6 +1221,9 @@ void hvf_arch_vcpu_destroy(CPUState *cpu)\n {\n hv_return_t ret;\n \n+ timer_free(cpu->accel->wfi_timer);\n+ cpu->accel->wfi_timer = NULL;\n+\n ret = hv_vcpu_destroy(cpu->accel->fd);\n assert_hvf_ok(ret);\n }\n@@ -1356,6 +1362,9 @@ int hvf_arch_init_vcpu(CPUState *cpu)\n arm_cpu->isar.idregs[ID_AA64MMFR0_EL1_IDX]);\n assert_hvf_ok(ret);\n \n+ cpu->accel->wfi_timer = timer_new_ns(QEMU_CLOCK_HOST,\n+ hvf_wfi_timer_cb, cpu);\n+\n aarch64_add_sme_properties(OBJECT(cpu));\n return 0;\n }\n@@ -2031,8 +2040,30 @@ static uint64_t hvf_vtimer_val_raw(void)\n return mach_absolute_time() - hvf_state->vtimer_offset;\n }\n \n+static void hvf_wfi_timer_cb(void *opaque)\n+{\n+ CPUState *cpu = opaque;\n+ ARMCPU *arm_cpu = ARM_CPU(cpu);\n+\n+ /*\n+ * vtimer expired while the CPU was halted for WFI.\n+ * Mirror HV_EXIT_REASON_VTIMER_ACTIVATED: raise the vtimer\n+ * interrupt and mark as masked so hvf_sync_vtimer() will\n+ * check and unmask when the guest handles it.\n+ *\n+ * The interrupt delivery chain (GIC -> cpu_interrupt ->\n+ * qemu_cpu_kick) wakes the vCPU thread from halt_cond.\n+ */\n+ qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);\n+ cpu->accel->vtimer_masked = true;\n+}\n+\n static int hvf_wfi(CPUState *cpu)\n {\n+ ARMCPU *arm_cpu = ARM_CPU(cpu);\n+ uint64_t ctl, cval;\n+ hv_return_t r;\n+\n if (cpu_has_work(cpu)) {\n /*\n * Don't bother to go into our \"low power state\" if\n@@ -2041,6 +2072,34 @@ static int hvf_wfi(CPUState *cpu)\n return 0;\n }\n \n+ /*\n+ * Set up a host-side timer to wake us when the vtimer expires.\n+ * HVF only delivers HV_EXIT_REASON_VTIMER_ACTIVATED during\n+ * hv_vcpu_run(), which we won't call while halted.\n+ */\n+ r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);\n+ assert_hvf_ok(r);\n+\n+ if ((ctl & TMR_CTL_ENABLE) && !(ctl & TMR_CTL_IMASK)) {\n+ r = hv_vcpu_get_sys_reg(cpu->accel->fd,\n+ HV_SYS_REG_CNTV_CVAL_EL0, &cval);\n+ assert_hvf_ok(r);\n+\n+ uint64_t now = hvf_vtimer_val_raw();\n+ if (cval <= now) {\n+ /* Timer already expired, don't halt */\n+ return 0;\n+ }\n+\n+ uint64_t delta_ticks = cval - now;\n+ int64_t delta_ns = delta_ticks * NANOSECONDS_PER_SECOND\n+ / arm_cpu->gt_cntfrq_hz;\n+ int64_t deadline = qemu_clock_get_ns(QEMU_CLOCK_HOST) + delta_ns;\n+\n+ timer_mod(cpu->accel->wfi_timer, deadline);\n+ }\n+\n+ cpu->halted = 1;\n return EXCP_HLT;\n }\n \n@@ -2334,7 +2393,11 @@ int hvf_arch_vcpu_exec(CPUState *cpu)\n hv_return_t r;\n \n if (cpu->halted) {\n- return EXCP_HLT;\n+ if (!cpu_has_work(cpu)) {\n+ return EXCP_HLT;\n+ }\n+ cpu->halted = 0;\n+ timer_del(cpu->accel->wfi_timer);\n }\n \n flush_cpu_state(cpu);\n", "prefixes": [ "13/16" ] }