Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2221677/?format=api
{ "id": 2221677, "url": "http://patchwork.ozlabs.org/api/patches/2221677/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410055045.63001-1-scottjgo@gmail.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/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": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260410055045.63001-1-scottjgo@gmail.com>", "list_archive_url": null, "date": "2026-04-10T05:50:26", "name": "[v2] target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "1d7f23eebf5bcb08f6271f623586166726727079", "submitter": { "id": 93060, "url": "http://patchwork.ozlabs.org/api/people/93060/?format=api", "name": "Scott J. Goldman", "email": "scottjgo@gmail.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410055045.63001-1-scottjgo@gmail.com/mbox/", "series": [ { "id": 499399, "url": "http://patchwork.ozlabs.org/api/series/499399/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499399", "date": "2026-04-10T05:50:26", "name": "[v2] target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/499399/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2221677/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2221677/checks/", "tags": {}, "related": [], "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=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=P4gojteK;\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=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.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 4fsQsz3SBVz20HT\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 15:51:49 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wB4lh-0003qb-5b; Fri, 10 Apr 2026 01:51:01 -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 <scottjgo@gmail.com>)\n id 1wB4lf-0003q6-C8\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 01:50:59 -0400", "from mail-dl1-x1231.google.com ([2607:f8b0:4864:20::1231])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <scottjgo@gmail.com>)\n id 1wB4lc-0006Kv-8g\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 01:50:59 -0400", "by mail-dl1-x1231.google.com with SMTP id\n a92af1059eb24-1271195d2a7so1414263c88.0\n for <qemu-devel@nongnu.org>; Thu, 09 Apr 2026 22:50:55 -0700 (PDT)", "from localhost.localdomain ([2601:645:8200:47:ade2:73a1:54c5:e0fe])\n by smtp.gmail.com with ESMTPSA id\n a92af1059eb24-12c346fb031sm2132117c88.13.2026.04.09.22.50.53\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Thu, 09 Apr 2026 22:50:53 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775800254; x=1776405054; 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=TKYjpnBzm9b6R7ZTmGA7hRa20prfMvO0wbO3fSp1aeo=;\n b=P4gojteKrCybMWzpD5NdYyfEeIsEpZd3GPY4hctXQOt1HnLp50EQbp69TQfhei4vLf\n wwU+eGJb+B8zup9KsK5Hvw0h/Hq4kV9+d62fCNx5hbhoaaMmXVQVTPzL06PtAhF3HZjR\n yzmACTnwW0AtA7LtfF1vRTGQPHHSZIbDNkVZRovW79uAK/KrHEgFC6HueaVzg1nKbQuj\n JRBel5E3Ud8O3liUPuh5ZlK4zlgZPxtAHGLmCb/Kh0D45s8j77NOaJ8hypoGR9+6pBqf\n wbPCSgUD65X+gpzQ6HGstQBWx+Fl70/Co8Re+oT37tJQB/u0TnC04LX3AYhpUU483Elq\n 9VaA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775800254; x=1776405054;\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=TKYjpnBzm9b6R7ZTmGA7hRa20prfMvO0wbO3fSp1aeo=;\n b=NRhPHDfnaMpiJWG6+c/cnsgIyoPMjOojF2o55QMvqj3ks66ZPdOn4lEPh5MzltJK2w\n ZXZrF8o4xJ/4NsmzxkNXk2XOv3JEZhQCRKhImvqGw0dOntZmb4gvDfxhJrmn/10Wd9nH\n uKswYZNhqmqmVVjj8zC2wMyqce4sLgHilQzqPrLxkGmhtxwBDYvUgKBa4hxcHEVqxs8Z\n f9+sueCxtis7Xa2CpoX5gE1qsbRtvXpIf+hpHhCIJBbC/FHMEzXcMfpzpJfyaWHm5u/N\n tHE9EHTCKYmJSY2PKNEVY1hy9yCSNeORZ0kXRfpSyT7LGP7jbJBEfcfBw6twJrcTIvYW\n R4ag==", "X-Gm-Message-State": "AOJu0Yyrdo60o5whihnBATKRoJNkdMUAj11lUh7hxxr8M3HXFeBh2Zo3\n GaOG7SSif0YjTYr1sT/j3KSJ3UXD/Au2A/uRBh15ZC4pxs5JTYssIjxxJIhA1XAQYwk=", "X-Gm-Gg": "AeBDieuy9wX/qs6cJ1D28fBDD3goxtH2kyerASeNwF6wO7TEZdXguIgATn6WWDokbxv\n OSSOQqZmDH6vVnyD/qLdKr2nBCcUMHf5+X1EqU3mgKYYmQmcFrZNymS1oXQahilZSRAtj0XenJ8\n U3Hr58aFPxH/Fk4RybdwwiK3WIJRPpW3UwqgzrWhlCbqeal3YyA4op/TEyIUhF8X6SKgz0ia2Qu\n SBNh/Ux6LLeHNJbjFY40yq63nKJ+p9GTw8DFSePd+lfLGO1rbQNAnJzN6plhQaYRnu7sVfd1gv7\n YVKtpswfIpYdGVFyGIMmE0GakJ5Gm7JZcU8rNwakv4n0+Nv41mRA6aTLwpmeY0DeUA2YiL4DeqA\n hzcVffEnqi+M3Qm6ObTQS5n/safTjcnApExRIUsuvn2DkR96FoTFD+m3WQ6+U91X1yiwt+Lej6V\n k23qw42Yh8me3KkouEuH8SVuR97WkXg7eKADG6LoT9p6ZRZ/A+F7MBT6UdFY+td5hRQoDu+pUNJ\n NIPevK8sFzWKPC10CB5JjUsE7I=", "X-Received": "by 2002:a05:7022:6a9:b0:128:cf86:d1cb with SMTP id\n a92af1059eb24-12c34f16faamr1215214c88.31.1775800254186;\n Thu, 09 Apr 2026 22:50:54 -0700 (PDT)", "From": "\"Scott J. Goldman\" <scottjgo@gmail.com>", "To": "qemu-devel@nongnu.org", "Cc": "qemu-arm@nongnu.org, rbolshakov@ddn.com, phil@philjordan.eu,\n agraf@csgraf.de, peter.maydell@linaro.org,\n \"Scott J. Goldman\" <scottjgo@gmail.com>", "Subject": "[PATCH v2] target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "Date": "Thu, 9 Apr 2026 22:50:26 -0700", "Message-ID": "<20260410055045.63001-1-scottjgo@gmail.com>", "X-Mailer": "git-send-email 2.50.1", "In-Reply-To": "<20260410044726.61853-1-scottjgo@gmail.com>", "References": "<20260410044726.61853-1-scottjgo@gmail.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2607:f8b0:4864:20::1231;\n envelope-from=scottjgo@gmail.com; helo=mail-dl1-x1231.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, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=unavailable 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": "Commit 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>\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 2621164cb2..58fb865eba 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+ struct QEMUTimer *wfi_timer;\n #endif\n };\n \ndiff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c\nindex 5fc8f6bbbd..f5d7221845 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@@ -1214,6 +1217,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@@ -1352,6 +1358,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@@ -2027,8 +2036,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@@ -2037,6 +2068,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@@ -2332,7 +2391,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": [ "v2" ] }