From nobody Sun Nov 24 09:52:27 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1724072581; cv=none; d=zohomail.com; s=zohoarc; b=eu+EP8JpzjZ7zoSWKcyhk1lY8bvNyZi7Nwd735eS2/RlPGqq0TfAqdsNW8EpOAV3hMASfDf86u+taq7sMOkqCzZmVTO6LAR1D9nr/eWgEfnQRpTJyyEbdTyTZx+hhlU3KiBR3zWQnVFKBqZc5HDNc9zE2gQBC0Z9BSMePLkobac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724072581; 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=CQ57VPFhj0J7dTLtPr/fFqy6l9Ee5cMcJ/yzr5U87U0=; b=Gkv928LYpHpknjYrQ7O1rWIZKZ7nEeVY2+vUZASChqbqtozzDfBBzbboTV9AC9Om1ZI3NYUrBVk+vRiht3KTnMJKXeE0uzu224/BJfAjoq2Syd0U5FhzQvwurMgw6QezOHtBlQZJTLJZERDff94VSMc2K0DEUYBK7BHI2rSbt6c= 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 17240725813771004.375358607767; Mon, 19 Aug 2024 06:03:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sg21i-0001sl-HN; Mon, 19 Aug 2024 09:02:28 -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 1sg21N-0000jK-Bx for qemu-devel@nongnu.org; Mon, 19 Aug 2024 09:02:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sg21L-0005vL-ED for qemu-devel@nongnu.org; Mon, 19 Aug 2024 09:02:04 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-x_53zHMkPnSqXP2C8WMdxQ-1; Mon, 19 Aug 2024 09:00:11 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DAF951955BEE for ; Mon, 19 Aug 2024 13:00:10 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.192.126]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A40C330001A1; Mon, 19 Aug 2024 13:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724072521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CQ57VPFhj0J7dTLtPr/fFqy6l9Ee5cMcJ/yzr5U87U0=; b=fQTNtZf6x3da+acyWIrK7q7qni90kCHEHdx9NJISYTQNgzsnKon+30XUc0AUr3gY6bm+qc TCyarK6DKnbB7nZjis7UwDmDymCG7bqNULqQdV6LI+u+KXhXeDxDNRKd3Dfz9axV3ccZ2Z g1uFaWNq5AQNy3dvQTNNzckHyUWSv2Q= X-MC-Unique: x_53zHMkPnSqXP2C8WMdxQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org, Paolo Bonzini Cc: Jan Richter Subject: [PATCH] hyperv: Make sure SynIC state is really updated before KVM_RUN Date: Mon, 19 Aug 2024 16:00:06 +0300 Message-ID: <20240819130007.33088-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=170.10.133.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.134, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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 @redhat.com) X-ZM-MESSAGEID: 1724072582433116600 Content-Type: text/plain; charset="utf-8" 'hyperv_synic' test from KVM unittests was observed to be flaky on certain hardware (hangs sometimes). Debugging shows that the problem happens in hyperv_sint_route_new() when the test tries to set up a new SynIC route. The function bails out on: if (!synic->sctl_enabled) { goto cleanup; } but the test writes to HV_X64_MSR_SCONTROL just before it starts establishing SINT routes. Further investigation shows that synic_update() (called from async_synic_update()) happens after the SINT setup attempt and not before. Apparently, the comment before async_safe_run_on_cpu() in kvm_hv_handle_exit() does not correctly describe the guarantees async_safe_run_on_cpu() gives. In particular, async worked added to a CPU is actually processed from qemu_wait_io_event() which is not always called before KVM_RUN, i.e. kvm_cpu_exec() checks whether an exit request is pending for a CPU and if not, keeps running the vCPU until it meets an exit it can't handle internally. Hyper-V specific MSR writes are not automatically trigger an exit. Fix the issue by simply raising an exit request for the vCPU where SynIC update was queued. This is not a performance critical path as SynIC state does not get updated so often (and async_safe_run_on_cpu() is a big hammer anyways). Reported-by: Jan Richter Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm/hyperv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/target/i386/kvm/hyperv.c b/target/i386/kvm/hyperv.c index b94f12acc2c9..70b89cacf94b 100644 --- a/target/i386/kvm/hyperv.c +++ b/target/i386/kvm/hyperv.c @@ -80,6 +80,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exi= t *exit) * necessary because memory hierarchy is being changed */ async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NUL= L); + cpu_exit(CPU(cpu)); =20 return EXCP_INTERRUPT; case KVM_EXIT_HYPERV_HCALL: { --=20 2.46.0