From nobody Fri Nov 18 18:26:54 2022 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 4NDQH76Lh7z4d8WS; Fri, 18 Nov 2022 18:26:59 +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 4NDQH70w5Gz4JRQ; Fri, 18 Nov 2022 18:26:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668796019; 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=kMvG7kNAPvGGrEZqpplTWY2P7nNoXBzIfRNnbQH8ItM=; b=cxWPDG8q5yz7DpYH0GruT+zm3TcL1qUHyvRvnY5KJ938VjfeAELR/pQS2wvOw/WefG1zxg gseQfN/WVjyS8/+kq9NrVqtCeUZr1aO1Li+KEjdpVuldSYyV63/MFY3z07QnE9h/++cQg6 2E0H4ZOLt07z6fAYaE+4b1dKQb8+kd+tUEh0kPKl8MJhrQoyrzCTeTE54/3k6OFiSV+OOO i5vwe8NvCd0JZbukDP0pE+CEKDlI8lO3tK2QinTa1VAQUnR4QRB5yh1jTG4hIipQy1H2ir A7llLk0OgFk0nLyeq43nCBkqSEJak2PGm7mLqcZeSajh0MN/9YrX0chN2aGrFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668796019; 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=kMvG7kNAPvGGrEZqpplTWY2P7nNoXBzIfRNnbQH8ItM=; b=DmA/oZKpIB7GzM3OFKZNjypD+wp5J18rIdxqvD3u0CWebVnnAfIKAQWmhjwnku3l8SCLjV p8WA78u2ZMuFMq44MROPF7tyaot8cduyuSx3bSsVsoCgB0+4nE29HaCFnh/i4yD66QMRjc pd94pGMjOWLIb9K4nJn9ziIh8BRm5tvItmTtude3LtpW6uh3SEOvho9rO/vtQdbepFO2Yk VIDQNbJIsKChrOF9WmbM2vFxBX8phlG8QS6pgIsIheZuniDP3gQK1mFI5m2SiA+f9pTvAx iGWqGZ8SxPDcQUhu8oZS9OH2v74dBddxEIVNYJbUr4bFyvnGoPW6M/3Z83rFtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668796019; a=rsa-sha256; cv=none; b=w2b0kzA/tLrdKwdMXqil/Lke1mPGRkuPi0lT30blwiKU8+vssNAHpCBeaxBNd2uFPNWphH o55hsyNRVAVxiZXHNcC6Ckg8BlKjDyuC3QvnemD8oB3yhBGVdNrgk55txvVkbS8Bvvwlue PukSpAM42ryifJfbA7j3aCQ749yg6vUEHrQ7YV3jHOcq10MP1Td+VYIflGy3sq6xlgW6Pk 89YEX1+caDfjoHb/9rsql25cWAymZHxTkoO/wDyRdeueYjOYU2YaSXa4uz7FvbXNBIE8j0 j9g3mf1NExaGOc6vQSay/0WjfH3NHSD02OjJ8vmUZeh7t92O1tSeD1cC6cYbLQ== 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 4NDQH26nJ1zG3G; Fri, 18 Nov 2022 18:26:54 +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 2AIIQsKE030760; Fri, 18 Nov 2022 18:26:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AIIQssl030757; Fri, 18 Nov 2022 18:26:54 GMT (envelope-from git) Date: Fri, 18 Nov 2022 18:26:54 GMT Message-Id: <202211181826.2AIIQssl030757@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: c0f35dbf19c3 - main - vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c0f35dbf19c3c8825bd2b321d8efd582807d1940 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c0f35dbf19c3c8825bd2b321d8efd582807d1940 commit c0f35dbf19c3c8825bd2b321d8efd582807d1940 Author: John Baldwin AuthorDate: 2022-11-18 18:05:10 +0000 Commit: John Baldwin CommitDate: 2022-11-18 18:25:38 +0000 vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs. Retire the boot_state member of struct vlapic and instead use a cpuset in the VM to track vCPUs waiting for STARTUP IPIs. INIT IPIs add vCPUs to this set, and STARTUP IPIs remove vCPUs from the set. STARTUP IPIs are only reported to userland for vCPUs that were removed from the set. In particular, this permits a subsequent change to allocate vCPUs on demand when the vCPU may not be allocated until after a STARTUP IPI is reported to userland. Reviewed by: corvink, markj Differential Revision: https://reviews.freebsd.org/D37173 --- sys/amd64/include/vmm.h | 3 +++ sys/amd64/vmm/io/vlapic.c | 46 ++++++++++-------------------------------- sys/amd64/vmm/io/vlapic_priv.h | 7 ------- sys/amd64/vmm/vmm.c | 27 +++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 42 deletions(-) diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h index b4f3312794dd..713c4a8b46e9 100644 --- a/sys/amd64/include/vmm.h +++ b/sys/amd64/include/vmm.h @@ -319,9 +319,12 @@ int vm_restore_time(struct vm *vm); typedef void (*vm_rendezvous_func_t)(struct vcpu *vcpu, void *arg); int vm_smp_rendezvous(struct vcpu *vcpu, cpuset_t dest, vm_rendezvous_func_t func, void *arg); + cpuset_t vm_active_cpus(struct vm *vm); cpuset_t vm_debug_cpus(struct vm *vm); cpuset_t vm_suspended_cpus(struct vm *vm); +cpuset_t vm_start_cpus(struct vm *vm, const cpuset_t *tostart); +void vm_await_start(struct vm *vm, const cpuset_t *waiting); #endif /* _SYS__CPUSET_H_ */ static __inline int diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c index 1a8b54bba3bf..e13cdcc63d57 100644 --- a/sys/amd64/vmm/io/vlapic.c +++ b/sys/amd64/vmm/io/vlapic.c @@ -1039,7 +1039,6 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu) cpuset_t dmask, ipimask; uint64_t icrval; uint32_t dest, vec, mode, shorthand; - struct vlapic *vlapic2; struct vcpu *vcpu; struct vm_exit *vmexit; struct LAPIC *lapic; @@ -1128,14 +1127,9 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu) i == vlapic->vcpuid) break; - /* - * Userland which doesn't support the IPI exit - * requires that the boot state is set to SIPI - * here. - */ - vcpu = vm_vcpu(vlapic->vm, i); - vlapic2 = vm_lapic(vcpu); - vlapic2->boot_state = BS_SIPI; + /* vCPU i is waiting for SIPI. */ + CPU_SETOF(i, &dmask); + vm_await_start(vlapic->vm, &dmask); break; } @@ -1158,11 +1152,10 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu) /* * Ignore SIPIs in any state other than wait-for-SIPI */ - vcpu = vm_vcpu(vlapic->vm, i); - vlapic2 = vm_lapic(vcpu); - if (vlapic2->boot_state != BS_SIPI) + CPU_SETOF(i, &dmask); + dmask = vm_start_cpus(vlapic->vm, &dmask); + if (CPU_EMPTY(&dmask)) break; - vlapic2->boot_state = BS_RUNNING; vmexit = vm_exitinfo(vlapic->vcpu); vmexit->exitcode = VM_EXITCODE_SPINUP_AP; @@ -1173,19 +1166,10 @@ vlapic_icrlo_write_handler(struct vlapic *vlapic, bool *retu) break; } - CPU_FOREACH_ISSET(i, &dmask) { - vcpu = vm_vcpu(vlapic->vm, i); - vlapic2 = vm_lapic(vcpu); - - /* - * Ignore SIPIs in any state other than wait-for-SIPI - */ - if (vlapic2->boot_state != BS_SIPI) - continue; - vlapic2->boot_state = BS_RUNNING; - CPU_SET(i, &ipimask); - } - + /* + * Ignore SIPIs in any state other than wait-for-SIPI + */ + ipimask = vm_start_cpus(vlapic->vm, &dmask); break; default: return (1); @@ -1210,9 +1194,6 @@ vlapic_handle_init(struct vcpu *vcpu, void *arg) struct vlapic *vlapic = vm_lapic(vcpu); vlapic_reset(vlapic); - - /* vlapic_reset modifies the boot state. */ - vlapic->boot_state = BS_SIPI; } int @@ -1223,6 +1204,7 @@ vm_handle_ipi(struct vcpu *vcpu, struct vm_exit *vme, bool *retu) case APIC_DELMODE_INIT: vm_smp_rendezvous(vcpu, vme->u.ipi.dmask, vlapic_handle_init, NULL); + vm_await_start(vcpu_vm(vcpu), &vme->u.ipi.dmask); break; case APIC_DELMODE_STARTUP: break; @@ -1598,11 +1580,6 @@ vlapic_reset(struct vlapic *vlapic) lapic->dcr_timer = 0; vlapic_dcr_write_handler(vlapic); - if (vlapic->vcpuid == 0) - vlapic->boot_state = BS_RUNNING; /* BSP */ - else - vlapic->boot_state = BS_INIT; /* AP */ - vlapic->svr_last = lapic->svr; } @@ -1900,7 +1877,6 @@ vlapic_snapshot(struct vm *vm, struct vm_snapshot_meta *meta) sizeof(vlapic->isrvec_stk), meta, ret, done); SNAPSHOT_VAR_OR_LEAVE(vlapic->isrvec_stk_top, meta, ret, done); - SNAPSHOT_VAR_OR_LEAVE(vlapic->boot_state, meta, ret, done); SNAPSHOT_BUF_OR_LEAVE(vlapic->lvt_last, sizeof(vlapic->lvt_last), diff --git a/sys/amd64/vmm/io/vlapic_priv.h b/sys/amd64/vmm/io/vlapic_priv.h index 2ac0cbf68117..ccae4b748880 100644 --- a/sys/amd64/vmm/io/vlapic_priv.h +++ b/sys/amd64/vmm/io/vlapic_priv.h @@ -125,12 +125,6 @@ do { \ VLAPIC_CTR1((vlapic), msg " isr7 0x%08x", isrptr[7 << 2]); \ } while (0) -enum boot_state { - BS_INIT, - BS_SIPI, - BS_RUNNING -}; - /* * 16 priority levels with at most one vector injected per level. */ @@ -175,7 +169,6 @@ struct vlapic { int isrvec_stk_top; uint64_t msr_apicbase; - enum boot_state boot_state; /* * Copies of some registers in the virtual APIC page. We do this for diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index 89e406efcdb0..ec6504772db3 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -173,6 +173,7 @@ struct vm { struct vrtc *vrtc; /* (o) virtual RTC */ volatile cpuset_t active_cpus; /* (i) active vcpus */ volatile cpuset_t debug_cpus; /* (i) vcpus stopped for debug */ + cpuset_t startup_cpus; /* (i) [r] waiting for startup */ int suspend; /* (i) stop VM execution */ volatile cpuset_t suspended_cpus; /* (i) suspended vcpus */ volatile cpuset_t halted_cpus; /* (x) cpus in a hard halt */ @@ -486,6 +487,7 @@ vm_init(struct vm *vm, bool create) CPU_ZERO(&vm->active_cpus); CPU_ZERO(&vm->debug_cpus); + CPU_ZERO(&vm->startup_cpus); vm->suspend = 0; CPU_ZERO(&vm->suspended_cpus); @@ -2421,6 +2423,30 @@ vm_suspended_cpus(struct vm *vm) return (vm->suspended_cpus); } +/* + * Returns the subset of vCPUs in tostart that are awaiting startup. + * These vCPUs are also marked as no longer awaiting startup. + */ +cpuset_t +vm_start_cpus(struct vm *vm, const cpuset_t *tostart) +{ + cpuset_t set; + + mtx_lock(&vm->rendezvous_mtx); + CPU_AND(&set, &vm->startup_cpus, tostart); + CPU_ANDNOT(&vm->startup_cpus, &vm->startup_cpus, &set); + mtx_unlock(&vm->rendezvous_mtx); + return (set); +} + +void +vm_await_start(struct vm *vm, const cpuset_t *waiting) +{ + mtx_lock(&vm->rendezvous_mtx); + CPU_OR(&vm->startup_cpus, &vm->startup_cpus, waiting); + mtx_unlock(&vm->rendezvous_mtx); +} + void * vcpu_stats(struct vcpu *vcpu) { @@ -2769,6 +2795,7 @@ vm_snapshot_vm(struct vm *vm, struct vm_snapshot_meta *meta) if (ret != 0) goto done; + SNAPSHOT_VAR_OR_LEAVE(vm->startup_cpus, meta, ret, done); done: return (ret); }