Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2221656/?format=api
{ "id": 2221656, "url": "http://patchwork.ozlabs.org/api/patches/2221656/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260410044726.61853-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": "<20260410044726.61853-1-scottjgo@gmail.com>", "list_archive_url": null, "date": "2026-04-10T04:47:26", "name": "target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "619f73d7f0732c6da926b6bed3b845953220585c", "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/20260410044726.61853-1-scottjgo@gmail.com/mbox/", "series": [ { "id": 499390, "url": "http://patchwork.ozlabs.org/api/series/499390/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499390", "date": "2026-04-10T04:47:26", "name": "target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/499390/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2221656/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2221656/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=IyNWCiiO;\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 4fsPTK1KlHz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 10 Apr 2026 14:48:51 +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 1wB3mt-00088V-Qn; Fri, 10 Apr 2026 00:48:11 -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 1wB3mr-00088E-TN\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 00:48:09 -0400", "from mail-dy1-x132d.google.com ([2607:f8b0:4864:20::132d])\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 1wB3mq-0001jN-0Y\n for qemu-devel@nongnu.org; Fri, 10 Apr 2026 00:48:09 -0400", "by mail-dy1-x132d.google.com with SMTP id\n 5a478bee46e88-2bd9a485bd6so3424539eec.1\n for <qemu-devel@nongnu.org>; Thu, 09 Apr 2026 21:48:07 -0700 (PDT)", "from localhost.localdomain ([2601:645:8200:47:ade2:73a1:54c5:e0fe])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2d562ac344csm2595695eec.25.2026.04.09.21.48.04\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Thu, 09 Apr 2026 21:48:04 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775796486; x=1776401286; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:from:to:cc:subject:date:message-id:reply-to;\n bh=Mwb6/+4nupu7Ja3YoA04YyvuT85Zlgd+oi3tYb3mgHQ=;\n b=IyNWCiiOdZ34DC/yW+B1kPWQ1urCELKdHcopueblvAdeYvxYpf8EAIdCDxYcaaQJR9\n j4NAcH5T4m/pbYpW0Br5mV8mdM9nLgN5VqqSPq65rxLpF1TevquSOFtTkZJMwDkAg8vA\n sI8ntWMbliFGTBH2L42M2Af0TP7rUdco1RUO2xalVg+sxjNH/v77GAm2YepALbvRM52Y\n 1IUGTZjts9z0jslXyJ+IkTigzhhcHLcRAfNTHvbzsbMbgdAcReEvtU2FI1EDfZWRBNwE\n eYATKtXSVWTxgEB8T96xsQpL8uV5cceFJqbjetAAFB11VZGhrcmC4M5O3iCdQtMQxLC4\n R8kQ==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775796486; x=1776401286;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=Mwb6/+4nupu7Ja3YoA04YyvuT85Zlgd+oi3tYb3mgHQ=;\n b=JN3LqawN5r0taZ580hHFAzKECYhEqBOu4GZGlutYWzP8kbJXpbO93gkQgK626hT8ic\n BEUjCAsYA6nkwCPJk736P6/KXKYI6Uf7GTUZfniSjHEFH/1B2kSnzP5JEd4US5VjDI/V\n 2KfPRXWQy2Bx2pA/AknhUEPwtiw4/UP9pCF9qGWi/rF9Z/EwIVIq9MLY/RJe18w8IXTv\n oFP4AbvPIFrrmoeYJXa6STifofSd3KgMfof8W9aL+x85N9/0SjEWGbAisfSD5O3pD3ow\n K73sfWn5NNDpLn0wwg4n8b7N5UjCuSCs9rEDnPZ9+/cv06P2Q6zU7Oit3o6EGOPzBtpc\n eI3Q==", "X-Gm-Message-State": "AOJu0YyX78kiMEwI0I7ba2eYV8BvAbBb6I1Kyth+cwSIJz5JFaPUSUsF\n RfnEKr40bQndhafknEK76h0RGr8Fwb/ociI8Y6+IasqiUuyuiEAb71PA2GEzOrmlFa8=", "X-Gm-Gg": "AeBDieuIct8oxPs9VLFFyAxmhcfUukq/dodUtZAkaxAbnO/HqeXmIU4TmsEVVY4/K5n\n uoF+prZWoRmAmpccnOebwPR24vOQ1HWOCXHuvYDuXNzTsgf/bP5mxpEmugTPYTvXfbGnXssZGqL\n z35UQ/syv1K4r4F1BuUT+JxlXb4hd+/bneWM37HZEmEfRUcZ4Ay+YNvem44QCb1v89w4HKY/Ou8\n z5u6cg0iPZmH3SmYdW/4mxiFzCEUoFw7BTS6AHVJ19jMHhyavfOvqOA5iI+YSmL9/hkQ5ZBt5n/\n 4S3UnAhkSQOl71tGToR+lhvpAvwHfC7paOYCHn7vfq9NoPZmDaNPAeJ7vnJkouWUhDzhDPbwXho\n z3dE7yiruy5hFeBtY5vEpPJeqWAkTrhQ8mvdY02BS9l3aaG4ImRFD9hlJJTlfDAtXBxSuKV3GcY\n mWdJRbyuF23jhfCB5erSIriuvagx6rjy/v6BuCIHxHrPAQWLHGa6SDbcwvJwUWVIMeuThsrFNT/\n bf6rNyw3ZBoiqz64NeDEDfl//0=", "X-Received": "by 2002:a05:7300:8c14:b0:2c4:ec89:bd3 with SMTP id\n 5a478bee46e88-2d5898aa893mr966553eec.24.1775796485592;\n Thu, 09 Apr 2026 21:48:05 -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] target/arm/hvf: Fix WFI halting to stop idle vCPU spinning", "Date": "Thu, 9 Apr 2026 21:47:26 -0700", "Message-ID": "<20260410044726.61853-1-scottjgo@gmail.com>", "X-Mailer": "git-send-email 2.50.1", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2607:f8b0:4864:20::132d;\n envelope-from=scottjgo@gmail.com; helo=mail-dy1-x132d.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=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": "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()\")\nResolves: https://gitlab.com/qemu-project/qemu/-/issues/959\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..0e737d3583 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,29 @@ 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+ 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 +2067,35 @@ 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+ mach_timebase_info_data_t timebase;\n+ mach_timebase_info(&timebase);\n+ int64_t delta_ns = delta_ticks * timebase.numer / timebase.denom;\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": [] }