From nobody Sat Nov 15 04:16:34 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=yadro.com ARC-Seal: i=1; a=rsa-sha256; t=1593039944; cv=none; d=zohomail.com; s=zohoarc; b=VpdShBRyq470DCFnjuSx5Q3tAy+t7jSHsdynPElHJ5Zwgq+fsa8Vbse0WoI/dFvKzcWtHBpRifPzZ9EyXw5v0YPqGdoL/Lpv/ocEu0NfEv+Z0GjgxRGWTcPaVAT8TJWw2sWs7/cEu6Hd2zituOYucG2mMCTIGz01qWYN4oIBA4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593039944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s4odE67H/+F1I24OBntPyUBowoKfhTe6ZbT3rTF3wo0=; b=BXBkbzv2Y7jx6Ool7ls+4Udn0iLp3zyD8Z3bio3zy4IHazSrU7LPfX9oOFTvonEKM0+a6JcdELSm1I5j/CC7bkZqBi+0+SmpeIqhl8PKNpCJGlkfKOc/rT2zilIKCbXlPidXVnPJj66Hf39O/sKCHuNGuh+1/96Iz6xAUQE1gCA= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593039944572124.21236235418576; Wed, 24 Jun 2020 16:05:44 -0700 (PDT) Received: from localhost ([::1]:35326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joESd-0006BF-9E for importer@patchew.org; Wed, 24 Jun 2020 19:05:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joEO9-00081z-UK for qemu-devel@nongnu.org; Wed, 24 Jun 2020 19:01:05 -0400 Received: from mta-02.yadro.com ([89.207.88.252]:32906 helo=mta-01.yadro.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joEO6-0006mU-6l for qemu-devel@nongnu.org; Wed, 24 Jun 2020 19:01:05 -0400 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id D0DAA4C8B1; Wed, 24 Jun 2020 23:01:00 +0000 (UTC) Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JLYubegpmftb; Thu, 25 Jun 2020 02:00:59 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id DF0334C8AD; Thu, 25 Jun 2020 02:00:57 +0300 (MSK) Received: from localhost (172.17.204.212) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Thu, 25 Jun 2020 02:00:57 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1593039659; x=1594854060; bh=5eLzJTuOmT/x7yLO7cQ7PGZ56UuXWSdJnvj 6AQTqRfo=; b=Xxlc8UHtHofSP3SdkU26CTt1TdrFyo1B5zsDTqbTBEh3KU96fC6 CUkFVHxMmNYoVyuQcdrf+PLAM8brlyHM8cgrpfVdlgQWodmMWKzIAB0d4a93J8c8 dDYCbCGniZVYc/gWYJOdVX6h8tTDPf5jq4ZKIHpfAAE7CyHqc7zfWW84= X-Virus-Scanned: amavisd-new at yadro.com From: Roman Bolshakov To: Subject: [PATCH 4/8] i386: hvf: Implement CPU kick Date: Thu, 25 Jun 2020 01:58:47 +0300 Message-ID: <20200624225850.16982-5-r.bolshakov@yadro.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200624225850.16982-1-r.bolshakov@yadro.com> References: <20200624225850.16982-1-r.bolshakov@yadro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.17.204.212] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) 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=89.207.88.252; envelope-from=r.bolshakov@yadro.com; helo=mta-01.yadro.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/24 19:00:57 X-ACL-Warn: Detected OS = Linux 3.11 and newer 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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Cameron Esfahani , Roman Bolshakov , Claudio Fontana , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @yadro.com) Content-Type: text/plain; charset="utf-8" HVF doesn't have a CPU kick and without it it's not possible to perform an action on CPU thread until a VMEXIT happens. The kick is also needed for timely interrupt delivery. Existing implementation of CPU kick sends SIG_IPI (aka SIGUSR1) to vCPU thread, but it's different from what hv_vcpu_interrupt does. The latter one results in invocation of mp_cpus_kick() in XNU kernel [1]. While at it, correct type of hvf_fd to the type of hv_vcpuid_t to avoid compilation warnings. 1. https://opensource.apple.com/source/xnu/xnu-6153.81.5/osfmk/i386/mp.c Cc: Cameron Esfahani Signed-off-by: Roman Bolshakov --- cpus.c | 13 +++++++++---- include/hw/core/cpu.h | 2 +- include/sysemu/hvf.h | 1 + target/i386/hvf/hvf.c | 11 +++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cpus.c b/cpus.c index 26709677d3..36f38ce5c8 100644 --- a/cpus.c +++ b/cpus.c @@ -1783,10 +1783,15 @@ static void qemu_cpu_kick_thread(CPUState *cpu) return; } cpu->thread_kicked =3D true; - err =3D pthread_kill(cpu->thread->thread, SIG_IPI); - if (err && err !=3D ESRCH) { - fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); - exit(1); + + if (hvf_enabled()) { + hvf_vcpu_kick(cpu); + } else { + err =3D pthread_kill(cpu->thread->thread, SIG_IPI); + if (err && err !=3D ESRCH) { + fprintf(stderr, "qemu:%s: %s", __func__, strerror(err)); + exit(1); + } } #else /* _WIN32 */ if (!qemu_cpu_is_self(cpu)) { diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index b3f4b79318..288a2bd57e 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -438,7 +438,7 @@ struct CPUState { =20 struct hax_vcpu_state *hax_vcpu; =20 - int hvf_fd; + unsigned hvf_fd; =20 /* track IOMMUs whose translations we've cached in the TCG TLB */ GArray *iommu_notifiers; diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h index 1d40a8ec01..aaa00cbf05 100644 --- a/include/sysemu/hvf.h +++ b/include/sysemu/hvf.h @@ -25,6 +25,7 @@ extern bool hvf_allowed; =20 int hvf_init_vcpu(CPUState *); int hvf_vcpu_exec(CPUState *); +void hvf_vcpu_kick(CPUState *); void hvf_cpu_synchronize_state(CPUState *); void hvf_cpu_synchronize_post_reset(CPUState *); void hvf_cpu_synchronize_post_init(CPUState *); diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c index efe9802962..4d254a477a 100644 --- a/target/i386/hvf/hvf.c +++ b/target/i386/hvf/hvf.c @@ -966,6 +966,17 @@ int hvf_vcpu_exec(CPUState *cpu) return ret; } =20 +void hvf_vcpu_kick(CPUState *cpu) +{ + hv_return_t err; + + err =3D hv_vcpu_interrupt(&cpu->hvf_fd, 1); + if (err) { + fprintf(stderr, "qemu:%s error %#x\n", __func__, err); + exit(1); + } +} + bool hvf_allowed; =20 static int hvf_accel_init(MachineState *ms) --=20 2.26.1