From nobody Fri Jan 06 23:56:44 2023 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NpgH15g8pz2r5WL for ; Fri, 6 Jan 2023 23:56:45 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NpgH12wfqz47qv for ; Fri, 6 Jan 2023 23:56:45 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673049405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=y4E3rSrYUWfVaNtayaKQMGlZQoh81LLNQhY3unXMe78=; b=QarRYkV1UrzFbJdUZxzLr7wyJ1arF9EUI4+Jm01+mPlYZBaSygj9xGq0JunDkr2FlHbbNr t0TAaHSzUQzv0bkgR+GttGWvBIRMklR8OGjvnwfosKLeCtDHbqfu0NVKkFJtPGfl6eL1rG sZAg0BbMMEd45HfrpEFN+MmoyuUhP43oqJ3OPyx4eqvIMMxTYvzSrN+NybOTXCa0tyQvss Uwmjc812YBKdxFCzsCI+xKUx60zvfejUo5mFmdzGNGcf+Vz6N8OZTo6Ld+owtk/evw+uU+ mH8ZKS3H10aEXpZVbxx1XlsbXylUAjdDUerxvtPLd5H854YYmTapChOCsJ1Ijw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673049405; a=rsa-sha256; cv=none; b=IoyGKHa65iH75NPwuvnIz0hZxWLP8lHa8Tkk2WXIAr6gcnz2TKW/Chu/vDB4sSxe5tRMIz /xq49WB9r3e6JTGss7qD2e+vX2uNtdMfGXdqOrwoHDe4RHxVNP9Jcc17NjTVD2OxT8mmpR I96tOtoFSy7MI+KLNPb4fho02RbRB0M9rejzwdsQeRXmSC4skKnj3SoDODXAEnZQLr/hzB uoM9tpkzYIAS5VP7xHfd82mU+Bllu4qlpP6YdTZWn2GDPNgTBzmYsKk8ZONRWYCXE9Mgfs sjYdq1+89Wcd+mpnhDE/HJDb8xxG6qSBFN61uQZHzh3Mw4JJgsSEcRMuhDZgww== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NpgH11zRKzpYj for ; Fri, 6 Jan 2023 23:56:45 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 306NujRk090899 for ; Fri, 6 Jan 2023 23:56:45 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 306NujhM090898 for virtualization@FreeBSD.org; Fri, 6 Jan 2023 23:56:45 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: virtualization@FreeBSD.org Subject: [Bug 268794] Simultaneous vcpu_lock_all() and vm_handle_rendezvous() can deadlock vmm Date: Fri, 06 Jan 2023 23:56:44 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bhyve X-Bugzilla-Version: 13.1-STABLE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: crowston@protonmail.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: virtualization@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D268794 Bug ID: 268794 Summary: Simultaneous vcpu_lock_all() and vm_handle_rendezvous() can deadlock vmm Product: Base System Version: 13.1-STABLE Hardware: amd64 OS: Any Status: New Severity: Affects Only Me Priority: --- Component: bhyve Assignee: virtualization@FreeBSD.org Reporter: crowston@protonmail.com Guest is Windows 11 22H2. This only happens with a PCI device passed-throug= h, only very early into the boot, and only if there's more than one vCPU. It d= oes not happen reliably, maybe 90% of boots. It happens even on the installer image. I am running on an AMD Ryzen 1700. This does not happen with Windows 10 nor Windows Server 2022, which suggest= s to me a recent change to the NT kernel might have exposed it. Action: 1. Windows writes to the APIC on vCPU x. 1a. That vCPU exits, and its state toggles to VCPU_FROZEN. 1b. That vCPU goes into vm_handle_inst_emul() -> emulate_mov() -> vioapic_mmio_write() -> vioapic_write() -> vm_smp_handle_rendezvous(). 1c. vm_handle_rendezvous() waits for all vCPU threads to handle the rendezv= ous. 2. Simultaneously, from userland's pci_passthru.c, either vm_map_pptdev_mmi= o() or vm_unmap_pptdev_mmio() is called. 2a. vmmdev_ioctl() invokes vcpu_lock_all(). 2b. vcpu_lock_all() iterates through the vCPUs, calling vcpu_lock_one() on = each vCPU, eventually reaching vCPU x (the APIC one). 2c. vCPU x is already in the VCPU_FROZEN state, from (1a). vcpu_set_state_locked() hangs waiting for it to transition to the VCPU_IDLE sate. 3. All the other vCPUs eventually end up either in vm_handle_rendezvous() o= r in vcpu_set_state_locked(), and hang there. It's not clear to me what the fix should be. Should we check and run the rendezvous func while waiting for the VCPU_IDLE transition in vcpu_set_state_locked()? That will presumably require a strong contract on = the kind of rendezvous functions that can be invoked. --=20 You are receiving this mail because: You are the assignee for the bug.=