From nobody Mon Nov 25 07:25:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1716321728; cv=none; d=zohomail.com; s=zohoarc; b=BSqpuT1X+rUn9T7UsYeW4mZE/OmMUKb8ypPaLf5PHt6I78R8gNR3DuK/Bqah2VsiKeuV/rfXQsRdMLZuGGDSKLX07vBfU6fjfDmsZJWsWFxJngW2nVf4rzy+8CiAIfpIxOqdU7zAY2i+rT9bbksGG5CRSne2Zh6iLD4o646rWM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716321728; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2rgBTJHAU1FJEJqebTznDkvBSJKO8YZnFMbGqqvbB4c=; b=kWmBLJt0bV+KtLdJg21dGU0AOk+qptAVXL/9eB9IbHZyuYlxFmP0wmVvkcvT6MI1wvTU3VhmdVZoiJQHKWQ1j9KMUfkRU+K4l+rfuB9mze+FrJC7Jv3Q0W21mts+C2q8nUIibKVv9J5KaZ95uYOsGFO/GSDMeRLjUuPsnzmwt3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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 1716321728328332.2430044879527; Tue, 21 May 2024 13:02:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9Vfu-0004XQ-LY; Tue, 21 May 2024 16:01:30 -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 1s9Vfs-0004Wz-G6 for qemu-devel@nongnu.org; Tue, 21 May 2024 16:01:28 -0400 Received: from mgamail.intel.com ([192.198.163.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9Vfn-0004AV-Jd for qemu-devel@nongnu.org; Tue, 21 May 2024 16:01:28 -0400 Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 13:01:19 -0700 Received: from gnr-001.sh.intel.com ([10.112.230.245]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 13:01:17 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716321684; x=1747857684; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5hRHTKyOiFHWSga18cyb+QOYsVtMlm2MGPirkcEPe8Q=; b=m2IkHSV5FEM9hd5rpz2ABDFnGMLZKFop5ShgTCL1NNdZP01VFt9avxy8 YR3GcITUSUCw84lCk1taiWLujSj3yb3hpId5C63YGvJs2/pIwGZlW/i/A JR7f5DKD8EQ6UiOlqTCAPv4PAWwz+AOylpM9TEWfJYhzr/5SrTCkh0mvi bZXewiZKkmeHkDuxpw/2ATgNJuSSeEH59wb9r6FO8Yd4JWh1s86iP/ZBF u3DvokwkZTsq34UC7Wix1cF8MTS3zDj1q3CmsR0vn+I+nObpFlSpXDeJq DOm1qJ2dD1Wf0DJMgw6OJjxw1u2bJbT1LWfOtAUw5dSGr+x4QOWkyjZJm g==; X-CSE-ConnectionGUID: 8EbRbke2RlOA83OwlGo2Ug== X-CSE-MsgGUID: T63qj/QIQz2Kp34W5wXdcA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="12381643" X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="12381643" X-CSE-ConnectionGUID: 8cahG3s7QyKNXJpFU2yU3w== X-CSE-MsgGUID: aKvHKE+uTB2ybJMEup5L9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,178,1712646000"; d="scan'208";a="37531778" From: Dongsheng Zhang To: qemu-devel@nongnu.org Cc: rkagan@amazon.de, pbonzini@redhat.com, mtosatti@redhat.com Subject: [PATCH] Hyperv: Correct kvm_hv_handle_exit return value Date: Wed, 22 May 2024 04:01:14 +0800 Message-ID: <20240521200114.11588-1-dongsheng.x.zhang@intel.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=192.198.163.19; envelope-from=dongsheng.x.zhang@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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 @intel.com) X-ZM-MESSAGEID: 1716321729557100001 From: donsheng This bug fix addresses the incorrect return value of kvm_hv_handle_exit for KVM_EXIT_HYPERV_SYNIC, which should be EXCP_INTERRUPT. Handling of KVM_EXIT_HYPERV_SYNIC in QEMU needs to be synchronous. This means that async_synic_update should run in the current QEMU vCPU thread before returning to KVM, returning EXCP_INTERRUPT to guarantee this. Returning 0 can cause async_synic_update to run asynchronously. One problem (kvm-unit-tests's hyperv_synic test fails with timeout error) caused by this bug: When a guest VM writes to the HV_X64_MSR_SCONTROL MSR to enable Hyper-V Syn= IC, a VM exit is triggered and processed by the kvm_hv_handle_exit function of = the QEMU vCPU. This function then calls the async_synic_update function to set synic->sctl_enabled to true. A true value of synic->sctl_enabled is required before creating SINT routes using the hyperv_sint_route_new() function. If kvm_hv_handle_exit returns 0 for KVM_EXIT_HYPERV_SYNIC, the current QEMU vCPU thread may return to KVM and enter the guest VM before running async_synic_update. In such case, the hyperv_synic test=E2=80=99s subsequen= t call to synic_ctl(HV_TEST_DEV_SINT_ROUTE_CREATE, ...) immediately after writing to HV_X64_MSR_SCONTROL can cause QEMU=E2=80=99s hyperv_sint_route_new() functi= on to return prematurely (because synic->sctl_enabled is false). If the SINT route is not created successfully, the SINT interrupt will not = be fired, resulting in a timeout error in the hyperv_synic test. Fixes: 267e071bd6d6 (=E2=80=9Chyperv: make overlay pages for SynIC=E2=80=9D) Suggested-by: Chao Gao Signed-off-by: Dongsheng Zhang --- target/i386/kvm/hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm/hyperv.c b/target/i386/kvm/hyperv.c index f2a3fe650a18..b94f12acc2c9 100644 --- a/target/i386/kvm/hyperv.c +++ b/target/i386/kvm/hyperv.c @@ -81,7 +81,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exi= t *exit) */ async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NUL= L); =20 - return 0; + return EXCP_INTERRUPT; case KVM_EXIT_HYPERV_HCALL: { uint16_t code =3D exit->u.hcall.input & 0xffff; bool fast =3D exit->u.hcall.input & HV_HYPERCALL_FAST; --=20 2.43.0