From 1467e8758e0ee9f2b355b16b59f80d963cdfb659 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 11 Jul 2021 13:14:20 +0800 Subject: [PATCH] nvmm: Various minor style tweaks --- sys/dev/virtual/nvmm/nvmm_os.c | 4 +--- sys/dev/virtual/nvmm/nvmm_os.h | 18 ++--------------- sys/dev/virtual/nvmm/x86/nvmm_x86.h | 14 ++----------- sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 26 ++++++++++++------------- sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 26 ++++++++++++------------- 5 files changed, 31 insertions(+), 57 deletions(-) diff --git a/sys/dev/virtual/nvmm/nvmm_os.c b/sys/dev/virtual/nvmm/nvmm_os.c index 88be46dc38..a4b11e6a18 100644 --- a/sys/dev/virtual/nvmm/nvmm_os.c +++ b/sys/dev/virtual/nvmm/nvmm_os.c @@ -35,9 +35,7 @@ #if defined(__DragonFly__) MALLOC_DEFINE(M_NVMM, "nvmm", "NVMM data"); -#endif -#if defined(__DragonFly__) /* * NVMM expects VM functions to return 0 on success, but DragonFly's VM * functions return KERN_SUCCESS. Although it's also defined to be 0, @@ -388,7 +386,7 @@ error: *va = (vaddr_t)addr; *pa = vtophys(addr); return 0; -#endif /* __NetBSD__ */ +#endif } void diff --git a/sys/dev/virtual/nvmm/nvmm_os.h b/sys/dev/virtual/nvmm/nvmm_os.h index 882eef17fb..1b61cd9dff 100644 --- a/sys/dev/virtual/nvmm/nvmm_os.h +++ b/sys/dev/virtual/nvmm/nvmm_os.h @@ -58,7 +58,6 @@ #include /* ffsl, ffs, etc. */ #endif -/* -------------------------------------------------------------------------- */ /* Types. */ #if defined(__NetBSD__) typedef struct vmspace os_vmspace_t; @@ -77,7 +76,6 @@ typedef vm_size_t vsize_t; typedef vm_paddr_t paddr_t; #endif -/* -------------------------------------------------------------------------- */ /* Attributes. */ #if defined(__DragonFly__) #define DIAGNOSTIC INVARIANTS @@ -85,14 +83,12 @@ typedef vm_paddr_t paddr_t; #define __diagused __debugvar #endif -/* -------------------------------------------------------------------------- */ /* Macros. */ #if defined(__DragonFly__) #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) #define __insn_barrier() __asm __volatile("":::"memory") #endif -/* -------------------------------------------------------------------------- */ /* Bitops. */ #if defined(__NetBSD__) #include @@ -106,14 +102,12 @@ typedef vm_paddr_t paddr_t; #endif /* __x86_64__ */ #endif -/* -------------------------------------------------------------------------- */ /* Maps. */ #if defined(__NetBSD__) || defined(__DragonFly__) #define os_kernel_map kernel_map #define os_curproc_map &curproc->p_vmspace->vm_map #endif -/* -------------------------------------------------------------------------- */ /* R/W locks. */ #if defined(__NetBSD__) #define os_rwl_init(lock) rw_init(lock) @@ -131,7 +125,6 @@ typedef vm_paddr_t paddr_t; #define os_rwl_wheld(lock) (lockstatus(lock, curthread) == LK_EXCLUSIVE) #endif -/* -------------------------------------------------------------------------- */ /* Mutexes. */ #if defined(__NetBSD__) #define os_mtx_init(lock) mutex_init(lock, MUTEX_DEFAULT, IPL_NONE) @@ -147,7 +140,6 @@ typedef vm_paddr_t paddr_t; #define os_mtx_owned(lock) (lockstatus(lock, curthread) == LK_EXCLUSIVE) #endif -/* -------------------------------------------------------------------------- */ /* Malloc. */ #if defined(__NetBSD__) #include @@ -162,7 +154,6 @@ MALLOC_DECLARE(M_NVMM); #define os_mem_free(ptr, size) kfree(ptr, M_NVMM) #endif -/* -------------------------------------------------------------------------- */ /* Printf. */ #if defined(__NetBSD__) #define os_printf printf @@ -170,7 +161,6 @@ MALLOC_DECLARE(M_NVMM); #define os_printf kprintf #endif -/* -------------------------------------------------------------------------- */ /* Atomics. */ #if defined(__NetBSD__) #include @@ -186,7 +176,6 @@ MALLOC_DECLARE(M_NVMM); #define os_atomic_inc_64(x) atomic_add_64(x, 1) #endif -/* -------------------------------------------------------------------------- */ /* Pmap. */ #if defined(__NetBSD__) #define os_vmspace_pdirpa(vm) ((vm)->vm_map.pmap->pm_pdirpa[0]) @@ -195,7 +184,6 @@ MALLOC_DECLARE(M_NVMM); #define os_vmspace_pdirpa(vm) (vtophys(vmspace_pmap(vm)->pm_pml4)) #endif -/* -------------------------------------------------------------------------- */ /* CPU. */ #if defined(__NetBSD__) #include @@ -227,7 +215,6 @@ typedef struct globaldata os_cpu_t; #define os_curcpu_idt() r_idt_arr[mycpuid].rd_base #endif -/* -------------------------------------------------------------------------- */ /* Cpusets. */ #if defined(__NetBSD__) #include @@ -249,7 +236,6 @@ typedef cpumask_t os_cpuset_t; #define os_cpuset_setrunning(s) ATOMIC_CPUMASK_ORMASK(*(s), smp_active_mask) #endif -/* -------------------------------------------------------------------------- */ /* Preemption. */ #if defined(__NetBSD__) #define os_preempt_disable() kpreempt_disable() @@ -269,7 +255,6 @@ typedef cpumask_t os_cpuset_t; #define os_preempt_disabled() true #endif -/* -------------------------------------------------------------------------- */ /* Asserts. */ #if defined(__NetBSD__) #define OS_ASSERT KASSERT @@ -277,7 +262,6 @@ typedef cpumask_t os_cpuset_t; #define OS_ASSERT KKASSERT #endif -/* -------------------------------------------------------------------------- */ /* Misc. */ #if defined(__DragonFly__) #define ilog2(n) ((sizeof(n) > 4 ? ffsl(n) : ffs(n)) - 1) @@ -285,6 +269,7 @@ typedef cpumask_t os_cpuset_t; #endif /* -------------------------------------------------------------------------- */ + os_vmspace_t * os_vmspace_create(vaddr_t, vaddr_t); void os_vmspace_destroy(os_vmspace_t *); int os_vmspace_fault(os_vmspace_t *, vaddr_t, vm_prot_t); @@ -329,6 +314,7 @@ os_return_needed(void) } /* -------------------------------------------------------------------------- */ + /* IPIs. */ #if defined(__NetBSD__) diff --git a/sys/dev/virtual/nvmm/x86/nvmm_x86.h b/sys/dev/virtual/nvmm/x86/nvmm_x86.h index 33d886868c..3c5e054428 100644 --- a/sys/dev/virtual/nvmm/x86/nvmm_x86.h +++ b/sys/dev/virtual/nvmm/x86/nvmm_x86.h @@ -747,7 +747,6 @@ typedef struct { #define x86_get_cpuid2(l, c, d) cpuid_count(l, c, (uint32_t *)d) #endif -/* -------------------------------------------------------------------------- */ /* Control registers. */ #if defined(__NetBSD__) #define x86_get_cr0() rcr0() @@ -767,9 +766,7 @@ typedef struct { #define x86_set_cr4(v) load_cr4(v) #endif -/* -------------------------------------------------------------------------- */ /* Debug registers. */ - #if defined(__NetBSD__) #define x86_get_dr0() rdr0() #define x86_get_dr1() rdr1() @@ -796,7 +793,7 @@ typedef struct { #define x86_set_dr3(v) load_dr3(v) #define x86_set_dr6(v) load_dr6(v) #define x86_set_dr7(v) load_dr7(v) -#endif /* __NetBSD__ */ +#endif static inline void x86_curthread_save_dbregs(uint64_t *drs) @@ -820,18 +817,13 @@ x86_curthread_restore_dbregs(uint64_t *drs) x86_set_dr7(drs[NVMM_X64_DR_DR7]); } -/* -------------------------------------------------------------------------- */ /* FPU. */ - #if defined(__NetBSD__) - #define x86_curthread_save_fpu() fpu_kern_enter() #define x86_curthread_restore_fpu() fpu_kern_leave() #define x86_save_fpu(a, m) fpu_area_save(a, m, true) #define x86_restore_fpu(a, m) fpu_area_restore(a, m, true) - #elif defined(__DragonFly__) - #define x86_curthread_save_fpu() /* TODO */ #define x86_curthread_restore_fpu() /* TODO */ #define x86_save_fpu(a, m) \ @@ -844,10 +836,8 @@ x86_curthread_restore_dbregs(uint64_t *drs) __asm volatile("clts" ::: "memory"); \ fpurstor((union savefpu *)(a), m); \ }) +#endif -#endif /* __NetBSD__ */ - -/* -------------------------------------------------------------------------- */ /* XCRs. */ static inline uint64_t x86_get_xcr(uint32_t xcr) diff --git a/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c b/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c index 73e5db8504..596dca761c 100644 --- a/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c +++ b/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c @@ -1372,9 +1372,9 @@ svm_vcpu_guest_fpu_enter(struct nvmm_cpu *vcpu) { struct svm_cpudata *cpudata = vcpu->cpudata; -#ifdef __NetBSD__ +#if defined(__NetBSD__) x86_curthread_save_fpu(); -#else /* DragonFly */ +#elif defined(__DragonFly__) /* * NOTE: Host FPU state depends on whether the user program used the * FPU or not. Need to use npxpush()/npxpop() to handle this. @@ -1398,9 +1398,9 @@ svm_vcpu_guest_fpu_leave(struct nvmm_cpu *vcpu) } x86_save_fpu(&cpudata->gxsave, svm_xcr0_mask); -#ifdef __NetBSD__ +#if defined(__NetBSD__) x86_curthread_restore_fpu(); -#else /* DragonFly */ +#elif defined(__DragonFly__) npxpop(&cpudata->hstate.hmctx); #endif } @@ -2444,7 +2444,7 @@ svm_tlb_flush(struct pmap *pm) */ os_ipi_kickall(); } -#endif /* __NetBSD__ */ +#endif static void svm_machine_create(struct nvmm_machine *mach) @@ -2459,7 +2459,7 @@ svm_machine_create(struct nvmm_machine *mach) /* Fill in pmap info. */ pmap->pm_data = (void *)mach; pmap->pm_tlb_flush = svm_tlb_flush; -#endif /* __NetBSD__ */ +#endif machdata = os_mem_zalloc(sizeof(struct svm_machdata)); mach->machdata = machdata; @@ -2593,7 +2593,7 @@ OS_IPI_FUNC(svm_change_cpu) #ifdef __DragonFly__ if (atomic_fetchadd_int(&svm_change_cpu_count, -1) == 1) wakeup(&svm_change_cpu_count); -#endif /* __DragonFly__ */ +#endif } static void @@ -2639,9 +2639,9 @@ svm_init(void) hsave[os_cpu_number(cpu)].pa = os_pa_zalloc(); } -#ifdef __NetBSD__ +#if defined(__NetBSD__) os_ipi_broadcast(svm_change_cpu, (void *)true); -#else /* DragonFly */ +#elif defined(__DragonFly__) atomic_swap_int(&svm_change_cpu_count, ncpus); lwkt_send_ipiq_mask(smp_active_mask, svm_change_cpu, (void *)true); do { @@ -2650,7 +2650,7 @@ svm_init(void) if (svm_change_cpu_count) tsleep(&svm_change_cpu_count, PINTERLOCKED, "vmx", hz); } while (svm_change_cpu_count != 0); -#endif /* __NetBSD__ */ +#endif } static void @@ -2669,9 +2669,9 @@ svm_fini(void) { size_t i; -#ifdef __NetBSD__ +#if defined(__NetBSD__) os_ipi_broadcast(svm_change_cpu, (void *)false); -#else /* DragonFly */ +#elif defined(__DragonFly__) atomic_swap_int(&svm_change_cpu_count, ncpus); lwkt_send_ipiq_mask(smp_active_mask, svm_change_cpu, (void *)false); do { @@ -2680,7 +2680,7 @@ svm_fini(void) if (svm_change_cpu_count) tsleep(&svm_change_cpu_count, PINTERLOCKED, "vmx", hz); } while (svm_change_cpu_count != 0); -#endif /* __NetBSD__ */ +#endif for (i = 0; i < OS_MAXCPUS; i++) { if (hsave[i].pa != 0) diff --git a/sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c b/sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c index d79531538b..c7c411e842 100644 --- a/sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c +++ b/sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c @@ -2051,9 +2051,9 @@ vmx_vcpu_guest_fpu_enter(struct nvmm_cpu *vcpu) { struct vmx_cpudata *cpudata = vcpu->cpudata; -#ifdef __NetBSD__ +#if defined(__NetBSD__) x86_curthread_save_fpu(); -#else /* DragonFly */ +#elif defined(__DragonFly__) /* * NOTE: Host FPU state depends on whether the user program used the * FPU or not. Need to use npxpush()/npxpop() to handle this. @@ -2077,9 +2077,9 @@ vmx_vcpu_guest_fpu_leave(struct nvmm_cpu *vcpu) } x86_save_fpu(&cpudata->gxsave, vmx_xcr0_mask); -#ifdef __NetBSD__ +#if defined(__NetBSD__) x86_curthread_restore_fpu(); -#else /* DragonFly */ +#elif defined(__DragonFly__) npxpop(&cpudata->hstate.hmctx); #endif } @@ -3215,7 +3215,7 @@ vmx_tlb_flush(struct pmap *pm) */ os_ipi_kickall(); } -#endif /* __NetBSD__ */ +#endif static void vmx_machine_create(struct nvmm_machine *mach) @@ -3230,7 +3230,7 @@ vmx_machine_create(struct nvmm_machine *mach) /* Fill in pmap info. */ pmap->pm_data = (void *)mach; pmap->pm_tlb_flush = vmx_tlb_flush; -#endif /* __NetBSD__ */ +#endif machdata = os_mem_zalloc(sizeof(struct vmx_machdata)); mach->machdata = machdata; @@ -3508,7 +3508,7 @@ OS_IPI_FUNC(vmx_change_cpu) #ifdef __DragonFly__ if (atomic_fetchadd_int(&vmx_change_cpu_count, -1) == 1) wakeup(&vmx_change_cpu_count); -#endif /* __DragonFly__ */ +#endif } static void @@ -3609,9 +3609,9 @@ vmx_init(void) vmxon->ident = __SHIFTIN(revision, VMXON_IDENT_REVISION); } -#ifdef __NetBSD__ +#if defined(__NetBSD__) os_ipi_broadcast(vmx_change_cpu, (void *)true); -#else /* DragonFly */ +#elif defined(__DragonFly__) atomic_swap_int(&vmx_change_cpu_count, ncpus); lwkt_send_ipiq_mask(smp_active_mask, vmx_change_cpu, (void *)true); do { @@ -3620,7 +3620,7 @@ vmx_init(void) if (vmx_change_cpu_count) tsleep(&vmx_change_cpu_count, PINTERLOCKED, "vmx", hz); } while (vmx_change_cpu_count != 0); -#endif /* __NetBSD__ */ +#endif } static void @@ -3639,9 +3639,9 @@ vmx_fini(void) { size_t i; -#ifdef __NetBSD__ +#if defined(__NetBSD__) os_ipi_broadcast(vmx_change_cpu, (void *)false); -#else /* DragonFly */ +#elif defined(__DragonFly__) atomic_swap_int(&vmx_change_cpu_count, ncpus); lwkt_send_ipiq_mask(smp_active_mask, vmx_change_cpu, (void *)false); do { @@ -3650,7 +3650,7 @@ vmx_fini(void) if (vmx_change_cpu_count) tsleep(&vmx_change_cpu_count, PINTERLOCKED, "vmx", hz); } while (vmx_change_cpu_count != 0); -#endif /* __NetBSD__ */ +#endif for (i = 0; i < OS_MAXCPUS; i++) { if (vmxoncpu[i].pa != 0) -- 2.41.0