From nobody Wed Apr 26 08:38:55 2023 X-Original-To: dev-commits-src-main@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 4Q5sjC2YWQz47h2Q; Wed, 26 Apr 2023 08:38:55 +0000 (UTC) (envelope-from git@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 4Q5sjC28M4z3Dr3; Wed, 26 Apr 2023 08:38:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682498335; 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=U+JRebYcjAlUyhjKFq6VRKhr55fV8TzwIvcKDz80KR0=; b=eyazeVMoMN5hDVva5L0eykSFMCSMMHJ1gpuR5aq88C6Th00CsZZKMitb+IdG/VBmCkmQjq wK4WG+dr7axx83SzW+wpvjKAOw0qbQHl2G2zEv1CLwfcsSMnQdSjIGp/BgAFfUYzYH3n8G gNFaCcGjbr3dqFRd9UK7YPKzDTpp4BL5MuqPwsBC5FlhkWO022MGtkSFoQjg3Y3gDRWDqN UgnYR8M0OZDSRXYwNOED04Dd7gMyoNh+LRTeKWj2aInUJSkpdHcWQ9w4BfqmgLiZYNt5Iu UzPl3ZYkih6nWycae7i47bKt+fhpgw8piUERA/+IDWSKgkCj3qVeSoZKdp8SiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682498335; 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=U+JRebYcjAlUyhjKFq6VRKhr55fV8TzwIvcKDz80KR0=; b=pXWhHlrw4xWD7hAlR7al9mMwXbFsOLQmJ5SyRDjHZRxAq7gkxja4asKmlGvjsvpHVIJcps 5FQLabfclVLnvrQdCAt1CrtIz4+K3Qx1ERd1z8joZofCYECZzMTaxsCtU/76ZjS534sKQo wN8ZjgXtdDmtMdqd2B6n2jzfUFtSNMM8F/8Xx+maHIWfqkxD1NS43lSWKwrFuJ3Z2+fOMh nu5kY4j+O4+wm3N7vACfJKa5t31aCjlRdHJ2T8ZukWvmHN4bxmoi5vh7Qh72iyKpU9Niz9 gwJFjyEi4sv5iIahCqELg5HnOhriY7Ii4J0uGzjUa/nQrz2n3tVhK8qG0rXg7Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682498335; a=rsa-sha256; cv=none; b=sZcHAYQoTOh/lIKCWv33s854T1j+TXG9M3cZAQln50v+Yg1AXpXMyIBdbpFbKHTZsoMRU2 PyXMqAlY0LW97qlMqRHcz9DpUx2dPZVciZMLXEtFFuGODzgUQKB3NdS6a8mW2oyxyn8rsd GlWLzR+nXLn8S4IqL1ZD+TGxHkznlNiUiJ1YJKtpMzd2vKjJHjNXGCJPMjjr9k/y5unukm 0TeLB7ci37QPYT6H5hbDstSmsX1bLIP4enzIh4sxbMQniMjKXbWwja5OW1jphYVI1oexft vL/7yKCSF7YZT4GgkentEMR6hPZGaN6m7g2x+Vb6D/oNSZy+F84kJfE/G0Oobw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 4Q5sjC1DGCzSDq; Wed, 26 Apr 2023 08:38:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33Q8ct8b025889; Wed, 26 Apr 2023 08:38:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33Q8ctq2025888; Wed, 26 Apr 2023 08:38:55 GMT (envelope-from git) Date: Wed, 26 Apr 2023 08:38:55 GMT Message-Id: <202304260838.33Q8ctq2025888@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 0912408a281f - main - vmm: fix HLT loop while vcpu has requested virtual interrupts List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0912408a281f203c43d0b3f73c38117336588342 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=0912408a281f203c43d0b3f73c38117336588342 commit 0912408a281f203c43d0b3f73c38117336588342 Author: Vitaliy Gusev AuthorDate: 2023-04-26 08:17:50 +0000 Commit: Corvin Köhne CommitDate: 2023-04-26 08:38:46 +0000 vmm: fix HLT loop while vcpu has requested virtual interrupts This fixes the detection of pending interrupts when pirval is 0 and the pending bit is set More information how this situation occurs, can be found here: https://github.com/freebsd/freebsd-src/blob/c5b5f2d8086f540fefe4826da013dd31d4e45fe8/sys/amd64/vmm/intel/vmx.c#L4016-L4031 Reviewed by: corvink, markj Fixes: 02cc877968bbcd57695035c67114a67427f54549 ("Recognize a pending virtual interrupt while emulating the halt instruction.") MFC after: 1 week Sponsored by: vStack Differential Revision: https://reviews.freebsd.org/D39620 --- sys/amd64/vmm/intel/vmx.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index 91406f0614ce..32e53de4e8ee 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -3763,7 +3763,8 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr) struct pir_desc *pir_desc; struct LAPIC *lapic; uint64_t pending, pirval; - uint32_t ppr, vpr; + uint8_t ppr, vpr, rvi; + struct vm_exit *vmexit; int i; /* @@ -3774,31 +3775,26 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr) vlapic_vtx = (struct vlapic_vtx *)vlapic; pir_desc = vlapic_vtx->pir_desc; + lapic = vlapic->apic_page; - pending = atomic_load_acq_long(&pir_desc->pending); - if (!pending) { - /* - * While a virtual interrupt may have already been - * processed the actual delivery maybe pending the - * interruptibility of the guest. Recognize a pending - * interrupt by reevaluating virtual interrupts - * following Section 29.2.1 in the Intel SDM Volume 3. - */ - struct vm_exit *vmexit; - uint8_t rvi, ppr; - - vmexit = vm_exitinfo(vlapic->vcpu); - KASSERT(vmexit->exitcode == VM_EXITCODE_HLT, - ("vmx_pending_intr: exitcode not 'HLT'")); - rvi = vmexit->u.hlt.intr_status & APIC_TPR_INT; - lapic = vlapic->apic_page; - ppr = lapic->ppr & APIC_TPR_INT; - if (rvi > ppr) { - return (1); - } + /* + * While a virtual interrupt may have already been + * processed the actual delivery maybe pending the + * interruptibility of the guest. Recognize a pending + * interrupt by reevaluating virtual interrupts + * following Section 30.2.1 in the Intel SDM Volume 3. + */ + vmexit = vm_exitinfo(vlapic->vcpu); + KASSERT(vmexit->exitcode == VM_EXITCODE_HLT, + ("vmx_pending_intr: exitcode not 'HLT'")); + rvi = vmexit->u.hlt.intr_status & APIC_TPR_INT; + ppr = lapic->ppr & APIC_TPR_INT; + if (rvi > ppr) + return (1); + pending = atomic_load_acq_long(&pir_desc->pending); + if (!pending) return (0); - } /* * If there is an interrupt pending then it will be recognized only @@ -3807,8 +3803,6 @@ vmx_pending_intr(struct vlapic *vlapic, int *vecptr) * Special case: if the processor priority is zero then any pending * interrupt will be recognized. */ - lapic = vlapic->apic_page; - ppr = lapic->ppr & APIC_TPR_INT; if (ppr == 0) return (1);