Date: Sat, 14 Mar 2015 02:32:09 +0000 (UTC) From: Neel Natu <neel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279971 - in head/sys: amd64/amd64 amd64/include amd64/vmm amd64/vmm/intel amd64/vmm/io modules/vmm Message-ID: <201503140232.t2E2W9VJ062472@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: neel Date: Sat Mar 14 02:32:08 2015 New Revision: 279971 URL: https://svnweb.freebsd.org/changeset/base/279971 Log: Use lapic_ipi_alloc() to dynamically allocate IPI slots needed by bhyve when vmm.ko is loaded. Also relocate the 'justreturn' IPI handler to be alongside all other handlers. Requested by: kib Deleted: head/sys/amd64/vmm/vmm_ipi.c head/sys/amd64/vmm/vmm_ipi.h head/sys/amd64/vmm/vmm_support.S Modified: head/sys/amd64/amd64/apic_vector.S head/sys/amd64/include/smp.h head/sys/amd64/vmm/intel/ept.c head/sys/amd64/vmm/intel/vmx.c head/sys/amd64/vmm/io/vlapic.c head/sys/amd64/vmm/vmm.c head/sys/amd64/vmm/vmm_lapic.c head/sys/modules/vmm/Makefile Modified: head/sys/amd64/amd64/apic_vector.S ============================================================================== --- head/sys/amd64/amd64/apic_vector.S Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/amd64/apic_vector.S Sat Mar 14 02:32:08 2015 (r279971) @@ -301,4 +301,35 @@ IDTVEC(rendezvous) call smp_rendezvous_action call as_lapic_eoi jmp doreti + +/* + * IPI handler whose purpose is to interrupt the CPU with minimum overhead. + * This is used by bhyve to force a host cpu executing in guest context to + * trap into the hypervisor. + * + * This handler is different from other IPI handlers in the following aspects: + * + * 1. It doesn't push a trapframe on the stack. + * + * This implies that a DDB backtrace involving 'justreturn' will skip the + * function that was interrupted by this handler. + * + * 2. It doesn't 'swapgs' when userspace is interrupted. + * + * The 'justreturn' handler does not access any pcpu data so it is not an + * issue. Moreover the 'justreturn' handler can only be interrupted by an NMI + * whose handler already doesn't trust GS.base when kernel code is interrupted. + */ + .text + SUPERALIGN_TEXT +IDTVEC(justreturn) + pushq %rax + pushq %rcx + pushq %rdx + call as_lapic_eoi + popq %rdx + popq %rcx + popq %rax + jmp doreti_iret + #endif /* SMP */ Modified: head/sys/amd64/include/smp.h ============================================================================== --- head/sys/amd64/include/smp.h Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/include/smp.h Sat Mar 14 02:32:08 2015 (r279971) @@ -54,6 +54,7 @@ inthand_t IDTVEC(ipi_intr_bitmap_handler), /* Bitmap based IPIs */ IDTVEC(cpustop), /* CPU stops & waits to be restarted */ IDTVEC(cpususpend), /* CPU suspends & waits to be resumed */ + IDTVEC(justreturn), /* interrupt CPU with minimum overhead */ IDTVEC(rendezvous); /* handle CPU rendezvous */ struct pmap; Modified: head/sys/amd64/vmm/intel/ept.c ============================================================================== --- head/sys/amd64/vmm/intel/ept.c Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/vmm/intel/ept.c Sat Mar 14 02:32:08 2015 (r279971) @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$"); #include <machine/vmm.h> #include "vmx_cpufunc.h" -#include "vmm_ipi.h" #include "ept.h" #define EPT_SUPPORTS_EXEC_ONLY(cap) ((cap) & (1UL << 0)) Modified: head/sys/amd64/vmm/intel/vmx.c ============================================================================== --- head/sys/amd64/vmm/intel/vmx.c Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/vmm/intel/vmx.c Sat Mar 14 02:32:08 2015 (r279971) @@ -55,7 +55,6 @@ __FBSDID("$FreeBSD$"); #include "vmm_lapic.h" #include "vmm_host.h" #include "vmm_ioport.h" -#include "vmm_ipi.h" #include "vmm_ktr.h" #include "vmm_stat.h" #include "vatpic.h" @@ -175,7 +174,7 @@ static int posted_interrupts; SYSCTL_INT(_hw_vmm_vmx_cap, OID_AUTO, posted_interrupts, CTLFLAG_RD, &posted_interrupts, 0, "APICv posted interrupt support"); -static int pirvec; +static int pirvec = -1; SYSCTL_INT(_hw_vmm_vmx, OID_AUTO, posted_interrupt_vector, CTLFLAG_RD, &pirvec, 0, "APICv posted interrupt vector"); @@ -485,8 +484,8 @@ static int vmx_cleanup(void) { - if (pirvec != 0) - vmm_ipi_free(pirvec); + if (pirvec >= 0) + lapic_ipi_free(pirvec); if (vpid_unr != NULL) { delete_unrhdr(vpid_unr); @@ -694,8 +693,8 @@ vmx_init(int ipinum) MSR_VMX_TRUE_PINBASED_CTLS, PINBASED_POSTED_INTERRUPT, 0, &tmp); if (error == 0) { - pirvec = vmm_ipi_alloc(); - if (pirvec == 0) { + pirvec = lapic_ipi_alloc(&IDTVEC(justreturn)); + if (pirvec < 0) { if (bootverbose) { printf("vmx_init: unable to allocate " "posted interrupt vector\n"); Modified: head/sys/amd64/vmm/io/vlapic.c ============================================================================== --- head/sys/amd64/vmm/io/vlapic.c Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/vmm/io/vlapic.c Sat Mar 14 02:32:08 2015 (r279971) @@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$"); #include <machine/vmm.h> -#include "vmm_ipi.h" #include "vmm_lapic.h" #include "vmm_ktr.h" #include "vmm_stat.h" Modified: head/sys/amd64/vmm/vmm.c ============================================================================== --- head/sys/amd64/vmm/vmm.c Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/vmm/vmm.c Sat Mar 14 02:32:08 2015 (r279971) @@ -76,7 +76,6 @@ __FBSDID("$FreeBSD$"); #include "vlapic.h" #include "vpmtmr.h" #include "vrtc.h" -#include "vmm_ipi.h" #include "vmm_stat.h" #include "vmm_lapic.h" @@ -298,8 +297,8 @@ vmm_init(void) vmm_host_state_init(); - vmm_ipinum = vmm_ipi_alloc(); - if (vmm_ipinum == 0) + vmm_ipinum = lapic_ipi_alloc(&IDTVEC(justreturn)); + if (vmm_ipinum < 0) vmm_ipinum = IPI_AST; error = vmm_mem_init(); @@ -338,7 +337,7 @@ vmm_handler(module_t mod, int what, void vmm_resume_p = NULL; iommu_cleanup(); if (vmm_ipinum != IPI_AST) - vmm_ipi_free(vmm_ipinum); + lapic_ipi_free(vmm_ipinum); error = VMM_CLEANUP(); /* * Something bad happened - prevent new Modified: head/sys/amd64/vmm/vmm_lapic.c ============================================================================== --- head/sys/amd64/vmm/vmm_lapic.c Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/amd64/vmm/vmm_lapic.c Sat Mar 14 02:32:08 2015 (r279971) @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include <x86/apicreg.h> #include <machine/vmm.h> -#include "vmm_ipi.h" #include "vmm_ktr.h" #include "vmm_lapic.h" #include "vlapic.h" Modified: head/sys/modules/vmm/Makefile ============================================================================== --- head/sys/modules/vmm/Makefile Sat Mar 14 00:30:41 2015 (r279970) +++ head/sys/modules/vmm/Makefile Sat Mar 14 02:32:08 2015 (r279971) @@ -19,13 +19,11 @@ SRCS+= vmm.c \ vmm_host.c \ vmm_instruction_emul.c \ vmm_ioport.c \ - vmm_ipi.c \ vmm_lapic.c \ vmm_mem.c \ vmm_stat.c \ vmm_util.c \ - x86.c \ - vmm_support.S + x86.c .PATH: ${.CURDIR}/../../amd64/vmm/io SRCS+= iommu.c \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503140232.t2E2W9VJ062472>