From cc50165018ec7b5dce4beb5fd3932c2b4ede000f Mon Sep 17 00:00:00 2001 From: Xiangyang Wu Date: Sat, 30 Jun 2018 00:17:34 +0800 Subject: [PATCH] HV:treewide:Cleanup the type for parameters of bitmap operations For reducing sign conversion in hypervisor: Update parameters of bitmap operations as unsigned type; Update the input of related caller as unsigned type when the caller's input parameter is const variable or the variable is only used by bitmap operations. V1-->V2: (1) Explicit casting for the first parameter of all bitmap operations; (2) Remove mask operation for explicit casting of all bitmap operations, since masking is useless. Otherwise, this trucation is dangerous. V2-->V3: (1) Explicit casting for all bitmap operations parameter; (2) Masking bit offset with 6-bit; (3) Add few comments about bit offset. V3-->V4: add '\' for some statement of bitmap macro Signed-off-by: Xiangyang Wu Acked-by: Eddie Dong --- hypervisor/arch/x86/cpu.c | 2 +- hypervisor/arch/x86/guest/vcpu.c | 2 +- hypervisor/include/arch/x86/cpu.h | 2 +- hypervisor/include/arch/x86/guest/vcpu.h | 2 +- hypervisor/include/arch/x86/softirq.h | 2 +- hypervisor/include/common/schedule.h | 4 +- hypervisor/include/lib/bits.h | 52 +++++++++++++++--------- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 62f6de48b..337ec560a 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -541,7 +541,7 @@ static void bsp_boot_post(void) start_cpus(); /* Trigger event to allow secondary CPUs to continue */ - __bitmap_set(0, &pcpu_sync); + __bitmap_set(0U, &pcpu_sync); ASSERT(get_cpu_id() == CPU_BOOT_ID, ""); diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index 98286dc2f..814e4e1d4 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -387,7 +387,7 @@ int prepare_vcpu(struct vm *vm, uint16_t pcpu_id) return ret; } -void request_vcpu_pre_work(struct vcpu *vcpu, int pre_work_id) +void request_vcpu_pre_work(struct vcpu *vcpu, uint16_t pre_work_id) { bitmap_set(pre_work_id, &vcpu->pending_pre_work); } diff --git a/hypervisor/include/arch/x86/cpu.h b/hypervisor/include/arch/x86/cpu.h index 2365ba767..b93739c90 100644 --- a/hypervisor/include/arch/x86/cpu.h +++ b/hypervisor/include/arch/x86/cpu.h @@ -130,7 +130,7 @@ #define CPU_MHZ_TO_KHZ 1000 /* Boot CPU ID */ -#define CPU_BOOT_ID 0 +#define CPU_BOOT_ID 0U /* CPU states defined */ #define CPU_STATE_RESET 0 diff --git a/hypervisor/include/arch/x86/guest/vcpu.h b/hypervisor/include/arch/x86/guest/vcpu.h index ec7442bcf..9343dba3d 100644 --- a/hypervisor/include/arch/x86/guest/vcpu.h +++ b/hypervisor/include/arch/x86/guest/vcpu.h @@ -287,7 +287,7 @@ void resume_vcpu(struct vcpu *vcpu); void schedule_vcpu(struct vcpu *vcpu); int prepare_vcpu(struct vm *vm, uint16_t pcpu_id); -void request_vcpu_pre_work(struct vcpu *vcpu, int pre_work_id); +void request_vcpu_pre_work(struct vcpu *vcpu, uint16_t pre_work_id); #endif diff --git a/hypervisor/include/arch/x86/softirq.h b/hypervisor/include/arch/x86/softirq.h index 99bb24a52..9d81987a4 100644 --- a/hypervisor/include/arch/x86/softirq.h +++ b/hypervisor/include/arch/x86/softirq.h @@ -13,7 +13,7 @@ #define SOFTIRQ_MASK ((1UL<=64, it will be truncated. */ #define build_bitmap_set(name, lock, nr, addr) \ -static inline void name(int nr, volatile unsigned long *addr) \ +static inline void name(uint16_t nr, volatile uint64_t *addr) \ { \ - asm volatile(lock "orq %1,%0" \ + nr = nr & 0x3fU; \ + asm volatile(lock "orq %q1,%0" \ : "+m" (*addr) \ - : "r" (1UL<=64, it will be truncated. */ #define build_bitmap_clear(name, lock, nr, addr) \ -static inline void name(int nr, volatile unsigned long *addr) \ +static inline void name(uint16_t nr, volatile uint64_t *addr) \ { \ - asm volatile(lock "andq %1,%0" \ + nr = nr & 0x3fU; \ + asm volatile(lock "andq %q1,%0" \ : "+m" (*addr) \ - : "r" (~(1UL<=64, it will + * be truncated. */ -static inline bool bitmap_test(int nr, volatile unsigned long *addr) +static inline bool bitmap_test(uint16_t nr, volatile uint64_t *addr) { - int32_t ret; - - asm volatile("btq %2,%1\n\tsbbl %0, %0" + int32_t ret=0; + nr = nr & 0x3fU; + asm volatile("btq %q2,%1\n\tsbbl %0, %0" : "=r" (ret), "=m" (*addr) - : "r" ((long)(nr & 0x3f)) + : "r" ((uint64_t)nr) : "cc", "memory"); return (ret != 0); } @@ -187,14 +195,17 @@ static inline bool bitmap_test(int nr, volatile unsigned long *addr) * bool ret = (*addr) & (1UL<=64, it + * will be truncated. */ #define build_bitmap_testandset(name, lock, nr, addr) \ -static inline bool name(int nr, volatile unsigned long *addr) \ +static inline bool name(uint16_t nr, volatile uint64_t *addr) \ { \ - int32_t ret; \ - asm volatile(lock "btsq %2,%1\n\tsbbl %0,%0" \ + int32_t ret=0; \ + nr = nr & 0x3fU; \ + asm volatile(lock "btsq %q2,%1\n\tsbbl %0,%0" \ : "=r" (ret), "=m" (*addr) \ - : "r" ((long)(nr & 0x3f)) \ + : "r" ((uint64_t)nr) \ : "cc", "memory"); \ return (ret != 0); \ } @@ -205,14 +216,17 @@ build_bitmap_testandset(bitmap_test_and_set, BUS_LOCK, nr, addr) * bool ret = (*addr) & (1UL<=64, + * it will be truncated. */ #define build_bitmap_testandclear(name, lock, nr, addr) \ -static inline bool name(int nr, volatile unsigned long *addr) \ +static inline bool name(uint16_t nr, volatile uint64_t *addr) \ { \ - int32_t ret; \ - asm volatile(lock "btrq %2,%1\n\tsbbl %0,%0" \ + int32_t ret=0; \ + nr = nr & 0x3fU; \ + asm volatile(lock "btrq %q2,%1\n\tsbbl %0,%0" \ : "=r" (ret), "=m" (*addr) \ - : "r" ((long)(nr & 0x3f)) \ + : "r" ((uint64_t)nr) \ : "cc", "memory"); \ return (ret != 0); \ }