From nobody Thu Feb 9 21:15:20 2023 X-Original-To: dev-commits-src-all@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 4PCV550kgkz3nkQK; Thu, 9 Feb 2023 21:15:21 +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 4PCV5471Lvz44yk; Thu, 9 Feb 2023 21:15:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977321; 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=OcR6pN/47y+iiGL/pCQdZsOJwKfqrCgpByCDq8XreJg=; b=vHuXpH7Y+TJ2vqDZyVru7nxc0GZvzXD/k5yO2My2UWcaYW0HE6ja2d4WOLEPqodV5FfLtr /XH80HZiJf4PLFAPrKQyOOyPMj3jKKRl1CkrQMVDhNz3dfi8qH4mhzWO8zdnqRWAxiFAWJ pqVcvhP7GWA23Mz9kWGWwC2k3V1RBNHTMC5K2hNFcvtBsxkpjNUXQ0ZbS0BWKUSS3X8lCl q2pQSPkhWmUv/NZb9OofTkZ7DvbmhSRH09t1kbRWS0RwJAB0kj/7315JoqOPAR5SlZeKdp jCJYnPPvIYbXp89ciWzDjJymRuDmvcQbMKAwscnhcnVvojwFOnTJdMcwt9kgBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675977321; 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=OcR6pN/47y+iiGL/pCQdZsOJwKfqrCgpByCDq8XreJg=; b=oPRFhNHpL++IwGCdsmGjIgtmysQ+5EUPgxbLdaFq1B455suVy4cCIZGc8j44ATGtMixtT3 1SzF+XZWLkEXVVTe7NTxHgEeP9456WrHtYBe4Ooyp/m5HFQBF9RTWXjAq0whhRptU2fQeW IofsG+AKymVpx6+9/cvRqWnodRlsA5PnQtfUhJiASCe3d6JKIz9QCOTUX3sTzGy0Zr05Lx B33JP7Eq8fNjjRCQsqraXJRuk2UsKhCrVD0/mou0UhgNeAkLQP+B8Mq9VdDOh3eosUSgbU Y2XEVBoQrPmyXBLAOMmTzoGR2rJGqZsRz4gyGxSlsX97wa0jFNL2+kUe3r0RDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675977321; a=rsa-sha256; cv=none; b=jTSQ3Pkiw1lRMLt/aLdUm/nymr3Y7Xzv9MMzcW3ZYOlFN7v2t/2B1RA7WOoJqbwEYSbvjl fGe84eAUywi1DG26kp5nBOoY+IaqSape7QtdTT+vUvhI7SMlNdasAtncjdIPOeclcMBwdS Z1zcQUCuemAOHtNaftHwmBFnN4T8DdP4sS+07+XCBPIDdDOjnHsO2uLBx07Jmh6pa3QoE7 oqfwC2Q2J0Nbo+jWlyQrZDJuK1aYJfjcdm84EodcqG9zC3m41HZTnU5R+6h3y03dKa/3dB WzGx1Ci+inaRZFvS3/Rz4IZfSepj6hgnkrD8biVoBG0pIhMqBJRE3tHFTmKW9A== 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 4PCV545n4jzs0s; Thu, 9 Feb 2023 21:15:20 +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 319LFKZd043010; Thu, 9 Feb 2023 21:15:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 319LFKSQ043009; Thu, 9 Feb 2023 21:15:20 GMT (envelope-from git) Date: Thu, 9 Feb 2023 21:15:20 GMT Message-Id: <202302092115.319LFKSQ043009@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: b265a2e0d764 - main - vmm: Fix AP startup compatibility for old bhyve executables List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b265a2e0d76422f4007e96dd7295ed0aeb846e2d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b265a2e0d76422f4007e96dd7295ed0aeb846e2d commit b265a2e0d76422f4007e96dd7295ed0aeb846e2d Author: Mark Johnston AuthorDate: 2023-02-09 20:52:35 +0000 Commit: Mark Johnston CommitDate: 2023-02-09 21:14:33 +0000 vmm: Fix AP startup compatibility for old bhyve executables These changes unbreak AP startup when using a 13.1-RELEASE bhyve executable with a newer kernel: - Correct the destination mask for the VM_EXITCODE_IPI message generated by an INIT or STARTUP IPI in vlapic_icrlo_write_handler(). - Only initialize vlapics on active vCPUs. 13.1-RELEASE bhyve activates AP vCPUs only after the BSP starts them with an IPI, and vmm now allocates vcpu structures lazily, so the STARTUP handling in vm_handle_ipi() could trigger a page fault. - Fix an off-by-one setting the vcpuid in a VM_EXITCODE_SPINUP_AP message. Fixes: 7c326ab5bb9a ("vmm: don't lock a mtx in the icr_low write handler") Reviewed by: jhb, corvink MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38446 --- sys/amd64/vmm/io/vlapic.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c index a68c68073893..884e232b1422 100644 --- a/sys/amd64/vmm/io/vlapic.c +++ b/sys/amd64/vmm/io/vlapic.c @@ -1144,7 +1144,7 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu) vmexit->exitcode = VM_EXITCODE_IPI; vmexit->u.ipi.mode = mode; vmexit->u.ipi.vector = vec; - vmexit->u.ipi.dmask = dmask; + vmexit->u.ipi.dmask = ipimask; *retu = true; } @@ -1169,16 +1169,22 @@ vm_handle_ipi(struct vcpu *vcpu, struct vm_exit *vme, bool *retu) *retu = true; switch (vme->u.ipi.mode) { - case APIC_DELMODE_INIT: - vm_smp_rendezvous(vcpu, *dmask, vlapic_handle_init, - NULL); + case APIC_DELMODE_INIT: { + cpuset_t active, reinit; + + active = vm_active_cpus(vcpu_vm(vcpu)); + CPU_AND(&reinit, &active, dmask); + if (!CPU_EMPTY(&reinit)) { + vm_smp_rendezvous(vcpu, reinit, vlapic_handle_init, + NULL); + } vm_await_start(vcpu_vm(vcpu), dmask); - if (!vlapic->ipi_exit) { + if (!vlapic->ipi_exit) *retu = false; - } break; + } case APIC_DELMODE_STARTUP: /* * Ignore SIPIs in any state other than wait-for-SIPI @@ -1196,13 +1202,13 @@ vm_handle_ipi(struct vcpu *vcpu, struct vm_exit *vme, bool *retu) */ if (!vlapic->ipi_exit) { vme->exitcode = VM_EXITCODE_SPINUP_AP; - vme->u.spinup_ap.vcpu = CPU_FFS(dmask); + vme->u.spinup_ap.vcpu = CPU_FFS(dmask) - 1; vme->u.spinup_ap.rip = vec << PAGE_SHIFT; } break; default: - return (1); + __assert_unreachable(); } return (0);