From 490d56c52760f9df9fa0200cf359bd14d742926f Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Thu, 1 Aug 2019 02:16:48 +0000 Subject: [PATCH] vmx: use C99 bool, not boolean_t Bhyve's vmm is a self-contained modern component and thus a good candidate for use of C99 types. Reviewed by: jhb, kib, markj, Patrick Mooney MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21036 --- sys/amd64/include/vmm.h | 6 +++--- sys/amd64/vmm/intel/vmx.c | 10 +++++----- sys/amd64/vmm/intel/vmx_msr.c | 21 ++++++--------------- sys/amd64/vmm/io/ppt.c | 6 +++--- sys/amd64/vmm/io/ppt.h | 2 +- sys/amd64/vmm/vmm.c | 28 ++++++++++++++-------------- sys/amd64/vmm/vmm_lapic.c | 14 ++++---------- sys/amd64/vmm/vmm_lapic.h | 2 +- sys/amd64/vmm/vmm_util.c | 20 +++++++------------- sys/amd64/vmm/vmm_util.h | 6 +++--- 10 files changed, 47 insertions(+), 68 deletions(-) diff --git a/sys/amd64/include/vmm.h b/sys/amd64/include/vmm.h index 57eb53a1264d..798d70b4d5c0 100644 --- a/sys/amd64/include/vmm.h +++ b/sys/amd64/include/vmm.h @@ -319,12 +319,12 @@ vcpu_reqidle(struct vm_eventinfo *info) int vcpu_debugged(struct vm *vm, int vcpuid); /* - * Return 1 if device indicated by bus/slot/func is supposed to be a + * Return true if device indicated by bus/slot/func is supposed to be a * pci passthrough device. * - * Return 0 otherwise. + * Return false otherwise. */ -int vmm_is_pptdev(int bus, int slot, int func); +bool vmm_is_pptdev(int bus, int slot, int func); void *vm_iommu_domain(struct vm *vm); diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c index ed5f0ea097dc..4a7d412b214c 100644 --- a/sys/amd64/vmm/intel/vmx.c +++ b/sys/amd64/vmm/intel/vmx.c @@ -1973,20 +1973,20 @@ ept_fault_type(uint64_t ept_qual) return (fault_type); } -static boolean_t +static bool ept_emulation_fault(uint64_t ept_qual) { int read, write; /* EPT fault on an instruction fetch doesn't make sense here */ if (ept_qual & EPT_VIOLATION_INST_FETCH) - return (FALSE); + return (false); /* EPT fault must be a read fault or a write fault */ read = ept_qual & EPT_VIOLATION_DATA_READ ? 1 : 0; write = ept_qual & EPT_VIOLATION_DATA_WRITE ? 1 : 0; if ((read | write) == 0) - return (FALSE); + return (false); /* * The EPT violation must have been caused by accessing a @@ -1995,10 +1995,10 @@ ept_emulation_fault(uint64_t ept_qual) */ if ((ept_qual & EPT_VIOLATION_GLA_VALID) == 0 || (ept_qual & EPT_VIOLATION_XLAT_VALID) == 0) { - return (FALSE); + return (false); } - return (TRUE); + return (true); } static __inline int diff --git a/sys/amd64/vmm/intel/vmx_msr.c b/sys/amd64/vmm/intel/vmx_msr.c index 726df43ad8fc..a9e51871d600 100644 --- a/sys/amd64/vmm/intel/vmx_msr.c +++ b/sys/amd64/vmm/intel/vmx_msr.c @@ -45,24 +45,18 @@ __FBSDID("$FreeBSD$"); #include "vmx.h" #include "vmx_msr.h" -static boolean_t +static bool vmx_ctl_allows_one_setting(uint64_t msr_val, int bitpos) { - if (msr_val & (1UL << (bitpos + 32))) - return (TRUE); - else - return (FALSE); + return ((msr_val & (1UL << (bitpos + 32))) != 0); } -static boolean_t +static bool vmx_ctl_allows_zero_setting(uint64_t msr_val, int bitpos) { - if ((msr_val & (1UL << bitpos)) == 0) - return (TRUE); - else - return (FALSE); + return ((msr_val & (1UL << bitpos)) == 0); } uint32_t @@ -89,16 +83,13 @@ vmx_set_ctlreg(int ctl_reg, int true_ctl_reg, uint32_t ones_mask, { int i; uint64_t val, trueval; - boolean_t true_ctls_avail, one_allowed, zero_allowed; + bool true_ctls_avail, one_allowed, zero_allowed; /* We cannot ask the same bit to be set to both '1' and '0' */ if ((ones_mask ^ zeros_mask) != (ones_mask | zeros_mask)) return (EINVAL); - if (rdmsr(MSR_VMX_BASIC) & (1UL << 55)) - true_ctls_avail = TRUE; - else - true_ctls_avail = FALSE; + true_ctls_avail = (rdmsr(MSR_VMX_BASIC) & (1UL << 55)) != 0; val = rdmsr(ctl_reg); if (true_ctls_avail) diff --git a/sys/amd64/vmm/io/ppt.c b/sys/amd64/vmm/io/ppt.c index e8afc38592a8..73fd576c0930 100644 --- a/sys/amd64/vmm/io/ppt.c +++ b/sys/amd64/vmm/io/ppt.c @@ -339,7 +339,7 @@ ppt_assigned_devices(struct vm *vm) return (num); } -boolean_t +bool ppt_is_mmio(struct vm *vm, vm_paddr_t gpa) { int i; @@ -355,11 +355,11 @@ ppt_is_mmio(struct vm *vm, vm_paddr_t gpa) if (seg->len == 0) continue; if (gpa >= seg->gpa && gpa < seg->gpa + seg->len) - return (TRUE); + return (true); } } - return (FALSE); + return (false); } static void diff --git a/sys/amd64/vmm/io/ppt.h b/sys/amd64/vmm/io/ppt.h index 686b15db49af..df8413031167 100644 --- a/sys/amd64/vmm/io/ppt.h +++ b/sys/amd64/vmm/io/ppt.h @@ -39,7 +39,7 @@ int ppt_setup_msi(struct vm *vm, int vcpu, int bus, int slot, int func, int ppt_setup_msix(struct vm *vm, int vcpu, int bus, int slot, int func, int idx, uint64_t addr, uint64_t msg, uint32_t vector_control); int ppt_assigned_devices(struct vm *vm); -boolean_t ppt_is_mmio(struct vm *vm, vm_paddr_t gpa); +bool ppt_is_mmio(struct vm *vm, vm_paddr_t gpa); /* * Returns the number of devices sequestered by the ppt driver for assignment diff --git a/sys/amd64/vmm/vmm.c b/sys/amd64/vmm/vmm.c index 5f845609009e..6dfc62659a3e 100644 --- a/sys/amd64/vmm/vmm.c +++ b/sys/amd64/vmm/vmm.c @@ -847,7 +847,7 @@ vmm_sysmem_maxaddr(struct vm *vm) } static void -vm_iommu_modify(struct vm *vm, boolean_t map) +vm_iommu_modify(struct vm *vm, bool map) { int i, sz; vm_paddr_t gpa, hpa; @@ -910,8 +910,8 @@ vm_iommu_modify(struct vm *vm, boolean_t map) iommu_invalidate_tlb(vm->iommu); } -#define vm_iommu_unmap(vm) vm_iommu_modify((vm), FALSE) -#define vm_iommu_map(vm) vm_iommu_modify((vm), TRUE) +#define vm_iommu_unmap(vm) vm_iommu_modify((vm), false) +#define vm_iommu_map(vm) vm_iommu_modify((vm), true) int vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func) @@ -1043,20 +1043,20 @@ vm_set_register(struct vm *vm, int vcpuid, int reg, uint64_t val) return (0); } -static boolean_t +static bool is_descriptor_table(int reg) { switch (reg) { case VM_REG_GUEST_IDTR: case VM_REG_GUEST_GDTR: - return (TRUE); + return (true); default: - return (FALSE); + return (false); } } -static boolean_t +static bool is_segment_register(int reg) { @@ -1069,9 +1069,9 @@ is_segment_register(int reg) case VM_REG_GUEST_GS: case VM_REG_GUEST_TR: case VM_REG_GUEST_LDTR: - return (TRUE); + return (true); default: - return (FALSE); + return (false); } } @@ -2233,12 +2233,12 @@ vm_hpet(struct vm *vm) return (vm->vhpet); } -boolean_t +bool vmm_is_pptdev(int bus, int slot, int func) { - int found, i, n; - int b, s, f; + int b, f, i, n, s; char *val, *cp, *cp2; + bool found; /* * XXX @@ -2252,7 +2252,7 @@ vmm_is_pptdev(int bus, int slot, int func) const char *names[] = { "pptdevs", "pptdevs2", "pptdevs3", NULL }; /* set pptdevs="1/2/3 4/5/6 7/8/9 10/11/12" */ - found = 0; + found = false; for (i = 0; names[i] != NULL && !found; i++) { cp = val = kern_getenv(names[i]); while (cp != NULL && *cp != '\0') { @@ -2261,7 +2261,7 @@ vmm_is_pptdev(int bus, int slot, int func) n = sscanf(cp, "%d/%d/%d", &b, &s, &f); if (n == 3 && bus == b && slot == s && func == f) { - found = 1; + found = true; break; } diff --git a/sys/amd64/vmm/vmm_lapic.c b/sys/amd64/vmm/vmm_lapic.c index 6bf013aea180..89a1ebc8eff9 100644 --- a/sys/amd64/vmm/vmm_lapic.c +++ b/sys/amd64/vmm/vmm_lapic.c @@ -137,13 +137,10 @@ lapic_intr_msi(struct vm *vm, uint64_t addr, uint64_t msg) return (0); } -static boolean_t +static bool x2apic_msr(u_int msr) { - if (msr >= 0x800 && msr <= 0xBFF) - return (TRUE); - else - return (FALSE); + return (msr >= 0x800 && msr <= 0xBFF); } static u_int @@ -153,14 +150,11 @@ x2apic_msr_to_regoff(u_int msr) return ((msr - 0x800) << 4); } -boolean_t +bool lapic_msr(u_int msr) { - if (x2apic_msr(msr) || (msr == MSR_APICBASE)) - return (TRUE); - else - return (FALSE); + return (x2apic_msr(msr) || msr == MSR_APICBASE); } int diff --git a/sys/amd64/vmm/vmm_lapic.h b/sys/amd64/vmm/vmm_lapic.h index 94f2c769122b..5fa6c4ef4f32 100644 --- a/sys/amd64/vmm/vmm_lapic.h +++ b/sys/amd64/vmm/vmm_lapic.h @@ -33,7 +33,7 @@ struct vm; -boolean_t lapic_msr(u_int num); +bool lapic_msr(u_int num); int lapic_rdmsr(struct vm *vm, int cpu, u_int msr, uint64_t *rval, bool *retu); int lapic_wrmsr(struct vm *vm, int cpu, u_int msr, uint64_t wval, diff --git a/sys/amd64/vmm/vmm_util.c b/sys/amd64/vmm/vmm_util.c index 25dac0da4d0b..257854f62785 100644 --- a/sys/amd64/vmm/vmm_util.c +++ b/sys/amd64/vmm/vmm_util.c @@ -38,26 +38,20 @@ __FBSDID("$FreeBSD$"); #include "vmm_util.h" -boolean_t +bool vmm_is_intel(void) { - if (strcmp(cpu_vendor, "GenuineIntel") == 0) - return (TRUE); - else - return (FALSE); + return (strcmp(cpu_vendor, "GenuineIntel") == 0); } -boolean_t +bool vmm_is_amd(void) { - if (strcmp(cpu_vendor, "AuthenticAMD") == 0) - return (TRUE); - else - return (FALSE); + return (strcmp(cpu_vendor, "AuthenticAMD") == 0); } -boolean_t +bool vmm_supports_1G_pages(void) { unsigned int regs[4]; @@ -70,9 +64,9 @@ vmm_supports_1G_pages(void) if (cpu_exthigh >= 0x80000001) { do_cpuid(0x80000001, regs); if (regs[3] & (1 << 26)) - return (TRUE); + return (true); } - return (FALSE); + return (false); } #include diff --git a/sys/amd64/vmm/vmm_util.h b/sys/amd64/vmm/vmm_util.h index fc7e7364c784..8c65e7e3a61e 100644 --- a/sys/amd64/vmm/vmm_util.h +++ b/sys/amd64/vmm/vmm_util.h @@ -33,9 +33,9 @@ struct trapframe; -boolean_t vmm_is_intel(void); -boolean_t vmm_is_amd(void); -boolean_t vmm_supports_1G_pages(void); +bool vmm_is_intel(void); +bool vmm_is_amd(void); +bool vmm_supports_1G_pages(void); void dump_trapframe(struct trapframe *tf);