From nobody Sat Nov 15 01:19:59 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1758041733; cv=none; d=zohomail.com; s=zohoarc; b=mNj17JW8yoHwhwlxnaQiJo8mvyc/5VlRXMYazJbt50RjlkbU4m+9kzt06GXs66Z1razRvvhWbnQgE1kXoKawWzWoPlTr8PAeE7BX/9CFbSgVgYcALE3HYH43efZj+NIX1mhOxHWIkICoVhgQmAocQxtSoEEB9DDXl5XiMbeglTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758041733; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wKIrYgnVlsn75fWz2V59r5YrRWXYNGAzP0qi6BqD+/4=; b=SmF7Pybn5es9uPLsSk6NCPzxsqWxLyZLIh6amtC14kLVquoPM6r0w1srIaOQQZsPrhy40oevMa6qRu+CKLFd0GdjghIZvzeLaao1wa40VyAWK9HED7/jOjcFVLhgw+tBgDezC5WgTOAhKF/4U1ayEDSII7GLmypjnm55k04x93Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1758041732993429.76105836341617; Tue, 16 Sep 2025 09:55:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uyYso-0001DT-ID; Tue, 16 Sep 2025 12:50:22 -0400 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 1uyYsn-0001Ak-3q for qemu-devel@nongnu.org; Tue, 16 Sep 2025 12:50:21 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uyYsl-0006lu-A2 for qemu-devel@nongnu.org; Tue, 16 Sep 2025 12:50:20 -0400 Received: from localhost.localdomain (unknown [167.220.208.43]) by linux.microsoft.com (Postfix) with ESMTPSA id 662B620154FA; Tue, 16 Sep 2025 09:50:13 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 662B620154FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1758041417; bh=wKIrYgnVlsn75fWz2V59r5YrRWXYNGAzP0qi6BqD+/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOqx7wKjOtVmRNRFkP6cyXwtg4eEDP64TWizUhMrFlmZsholeV3GH1sEXJo5YkleT L305590LCcovxnUKvzx7WOfwTWmoMBqR8mDDJcEpVbjN9k/vhI59Fd+A2o4gq94TEV kweBkJO/BXvPDcTWCvTecNHvbVGJijx0uxK7PBY8= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cameron Esfahani , Paolo Bonzini , Thomas Huth , Richard Henderson , Wei Liu , Cornelia Huck , "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , Roman Bolshakov , Phil Dennis-Jordan , Marcel Apfelbaum , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Zhao Liu , Eduardo Habkost , Magnus Kulke , Wei Liu , Eric Blake , Yanan Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v4 11/27] accel/mshv: Add vCPU signal handling Date: Tue, 16 Sep 2025 18:48:31 +0200 Message-Id: <20250916164847.77883-12-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250916164847.77883-1-magnuskulke@linux.microsoft.com> References: <20250916164847.77883-1-magnuskulke@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=magnuskulke@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linux.microsoft.com) X-ZM-MESSAGEID: 1758041734614116600 Content-Type: text/plain; charset="utf-8" Implement signal handling for MSHV vCPUs to support asynchronous interrupts from the main thread. Signed-off-by: Magnus Kulke --- accel/mshv/mshv-all.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index b49988d294..cc4d47f8f5 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -525,6 +525,35 @@ static int mshv_cpu_exec(CPUState *cpu) return ret; } =20 +/* + * The signal handler is triggered when QEMU's main thread receives a SIG_= IPI + * (SIGUSR1). This signal causes the current CPU thread to be kicked, forc= ing a + * VM exit on the CPU. The VM exit generates an exit reason that breaks th= e loop + * (see mshv_cpu_exec). If the exit is due to a Ctrl+A+x command, the syst= em + * will shut down. For other cases, the system will continue running. + */ +static void sa_ipi_handler(int sig) +{ + /* TODO: call IOCTL to set_immediate_exit, once implemented. */ + + qemu_cpu_kick_self(); +} + +static void init_signal(CPUState *cpu) +{ + /* init cpu signals */ + struct sigaction sigact; + sigset_t set; + + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler =3D sa_ipi_handler; + sigaction(SIG_IPI, &sigact, NULL); + + pthread_sigmask(SIG_BLOCK, NULL, &set); + sigdelset(&set, SIG_IPI); + pthread_sigmask(SIG_SETMASK, &set, NULL); +} + static void *mshv_vcpu_thread(void *arg) { CPUState *cpu =3D arg; @@ -541,6 +570,7 @@ static void *mshv_vcpu_thread(void *arg) error_report("Failed to init vcpu %d", cpu->cpu_index); goto cleanup; } + init_signal(cpu); =20 /* signal CPU creation */ cpu_thread_signal_created(cpu); --=20 2.34.1