From: dlg Date: Tue, 8 Nov 2022 19:18:47 +0000 (+0000) Subject: further speed up delivery of interrupts to a running vcpu. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0d8b5945bad2cf707e51761352bff6611f56316b;p=openbsd further speed up delivery of interrupts to a running vcpu. this records which physical cpu a vcpu is running on. this is used by the code that marks a vcpu as having a pending interrupt to check if the vcpu is currently running. if it thinks the vcpu is running, it sends a nop IPI to the physical cpu it is running on to trigger a vmexit, which in turn runs interrupt handling in the guest. ok mlarkin@ --- diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 2defbd045a9..5ef771bbe52 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.327 2022/11/08 18:08:43 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.328 2022/11/08 19:18:47 dlg Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -878,6 +878,7 @@ vm_intr_pending(struct vm_intr_params *vip) { struct vm *vm; struct vcpu *vcpu; + struct cpu_info *ci; int error, ret = 0; /* Find the desired VM */ @@ -895,6 +896,9 @@ vm_intr_pending(struct vm_intr_params *vip) } vcpu->vc_intr = vip->vip_intr; + ci = READ_ONCE(vcpu->vc_curcpu); + if (ci != NULL) + x86_send_ipi(ci, X86_IPI_NOP); refcnt_rele_wake(&vcpu->vc_refcnt); out: @@ -4559,6 +4563,7 @@ vm_run(struct vm_run_params *vrp) } } + WRITE_ONCE(vcpu->vc_curcpu, curcpu()); /* Run the VCPU specified in vrp */ if (vcpu->vc_virt_mode == VMM_MODE_VMX || vcpu->vc_virt_mode == VMM_MODE_EPT) { @@ -4567,6 +4572,7 @@ vm_run(struct vm_run_params *vrp) vcpu->vc_virt_mode == VMM_MODE_RVI) { ret = vcpu_run_svm(vcpu, vrp); } + WRITE_ONCE(vcpu->vc_curcpu, NULL); atomic_dec_int(&vm->vm_vcpus_running); if (ret == 0 || ret == EAGAIN) { diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index 6a5296d08e4..cbe901580de 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.81 2022/09/01 22:01:40 dv Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.82 2022/11/08 19:18:47 dlg Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -934,6 +934,7 @@ struct vcpu { struct rwlock vc_lock; struct refcnt vc_refcnt; /* [a] */ + struct cpu_info *vc_curcpu; /* [a] */ struct cpu_info *vc_last_pcpu; /* [v] */ struct vm_exit vc_exit; /* [v] */