Skip to content

Commit 69ebf4c

Browse files
junjiemao1lijinxia
authored andcommitted
HV: vioapic: cleaning up integral-type-related violations
This patch cleans up the integral-type-related violations after the access pattern to RTEs is unified. Major changes include: 1. vioapic_mmio_read(), vioapic_mmio_write() and vioapic_mmio_rw() assumes the size of the register to be accessed is always 4, which is checked in vioapic_mmio_access_handler(). Thus they no longer takes the unused ''size'' parameter. 2. Typical integral-type-related violation fixes including 'U' suffixes, type of local variables, conversion specification in format strings, etc. v1 -> v2: * Drop duplicated definitions to IOAPIC register offsets. * Drop the ''size'' parameter of vioapic_mmio_[read|write] and vioapic_mmio_rw since vioapic_mmio_access_handler() ensures that size is always 4. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent a1069a5 commit 69ebf4c

File tree

4 files changed

+48
-62
lines changed

4 files changed

+48
-62
lines changed

hypervisor/arch/x86/guest/vioapic.c

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,11 @@
3232

3333
#include <hypervisor.h>
3434

35-
#define IOREGSEL 0x00
36-
#define IOWIN 0x10
37-
#define IOEOI 0x40
38-
3935
#define REDIR_ENTRIES_HW 120U /* SOS align with native ioapic */
4036
#define RTBL_RO_BITS (uint32_t)(IOAPIC_RTE_REM_IRR | IOAPIC_RTE_DELIVS)
4137
#define NEED_TMR_UPDATE (~(IOAPIC_RTE_INTMASK | IOAPIC_RTE_INTPOL))
4238

43-
#define ACRN_DBG_IOAPIC 6
39+
#define ACRN_DBG_IOAPIC 6U
4440

4541
struct vioapic {
4642
struct vm *vm;
@@ -432,34 +428,34 @@ vioapic_write(struct vioapic *vioapic, uint32_t addr, uint32_t data)
432428
}
433429
}
434430

435-
static int
431+
static void
436432
vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
437-
uint64_t *data, int size, bool doread)
433+
uint32_t *data, bool doread)
438434
{
439-
uint64_t offset;
435+
uint32_t offset;
440436

441-
offset = gpa - VIOAPIC_BASE;
437+
offset = (uint32_t)(gpa - VIOAPIC_BASE);
442438

443439
/*
444440
* The IOAPIC specification allows 32-bit wide accesses to the
445-
* IOREGSEL (offset 0) and IOWIN (offset 16) registers.
441+
* IOAPIC_REGSEL (offset 0) and IOAPIC_WINDOW (offset 16) registers.
446442
*/
447-
if (size != 4 || (offset != IOREGSEL && offset != IOWIN &&
448-
offset != IOEOI)) {
443+
if (offset != IOAPIC_REGSEL &&
444+
offset != IOAPIC_WINDOW &&
445+
offset != IOAPIC_EOIR) {
449446
if (doread) {
450-
*data = 0UL;
447+
*data = 0U;
451448
}
452-
return 0;
453449
}
454450

455451
VIOAPIC_LOCK(vioapic);
456-
if (offset == IOREGSEL) {
452+
if (offset == IOAPIC_REGSEL) {
457453
if (doread) {
458454
*data = vioapic->ioregsel;
459455
} else {
460456
vioapic->ioregsel = *data;
461457
}
462-
} else if (offset == IOEOI) {
458+
} else if (offset == IOAPIC_EOIR) {
463459
/* only need to handle write operation */
464460
if (!doread) {
465461
vioapic_write_eoi(vioapic, *data);
@@ -473,32 +469,24 @@ vioapic_mmio_rw(struct vioapic *vioapic, uint64_t gpa,
473469
}
474470
}
475471
VIOAPIC_UNLOCK(vioapic);
476-
477-
return 0;
478472
}
479473

480-
int
481-
vioapic_mmio_read(void *vm, uint64_t gpa, uint64_t *rval,
482-
int size)
474+
void
475+
vioapic_mmio_read(struct vm *vm, uint64_t gpa, uint32_t *rval)
483476
{
484-
int error;
485477
struct vioapic *vioapic;
486478

487479
vioapic = vm_ioapic(vm);
488-
error = vioapic_mmio_rw(vioapic, gpa, rval, size, true);
489-
return error;
480+
vioapic_mmio_rw(vioapic, gpa, rval, true);
490481
}
491482

492-
int
493-
vioapic_mmio_write(void *vm, uint64_t gpa, uint64_t wval,
494-
int size)
483+
void
484+
vioapic_mmio_write(struct vm *vm, uint64_t gpa, uint32_t wval)
495485
{
496-
int error;
497486
struct vioapic *vioapic;
498487

499488
vioapic = vm_ioapic(vm);
500-
error = vioapic_mmio_rw(vioapic, gpa, &wval, size, false);
501-
return error;
489+
vioapic_mmio_rw(vioapic, gpa, &wval, false);
502490
}
503491

504492
void
@@ -569,7 +557,7 @@ vioapic_init(struct vm *vm)
569557
{
570558
struct vioapic *vioapic;
571559

572-
vioapic = calloc(1, sizeof(struct vioapic));
560+
vioapic = calloc(1U, sizeof(struct vioapic));
573561
ASSERT(vioapic != NULL, "");
574562

575563
vioapic->vm = vm;
@@ -581,7 +569,7 @@ vioapic_init(struct vm *vm)
581569
vioapic_mmio_access_handler,
582570
(uint64_t)VIOAPIC_BASE,
583571
(uint64_t)VIOAPIC_BASE + VIOAPIC_SIZE,
584-
(void *) 0);
572+
NULL);
585573

586574
return vioapic;
587575
}
@@ -613,23 +601,26 @@ int vioapic_mmio_access_handler(struct vcpu *vcpu, struct mem_io *mmio,
613601
int ret = 0;
614602

615603
/* Note all RW to IOAPIC are 32-Bit in size */
616-
ASSERT(mmio->access_size == 4U,
617-
"All RW to LAPIC must be 32-bits in size");
618-
619-
if (mmio->read_write == HV_MEM_IO_READ) {
620-
ret = vioapic_mmio_read(vm,
621-
gpa,
622-
&mmio->value,
623-
mmio->access_size);
624-
mmio->mmio_status = MMIO_TRANS_VALID;
625-
626-
} else if (mmio->read_write == HV_MEM_IO_WRITE) {
627-
ret = vioapic_mmio_write(vm,
628-
gpa,
629-
mmio->value,
630-
mmio->access_size);
631-
632-
mmio->mmio_status = MMIO_TRANS_VALID;
604+
if (mmio->access_size == 4U) {
605+
uint32_t data = mmio->value;
606+
607+
if (mmio->read_write == HV_MEM_IO_READ) {
608+
vioapic_mmio_read(vm,
609+
gpa,
610+
&data);
611+
mmio->value = (uint64_t)data;
612+
mmio->mmio_status = MMIO_TRANS_VALID;
613+
614+
} else if (mmio->read_write == HV_MEM_IO_WRITE) {
615+
vioapic_mmio_write(vm,
616+
gpa,
617+
data);
618+
619+
mmio->mmio_status = MMIO_TRANS_VALID;
620+
}
621+
} else {
622+
pr_err("All RW to IOAPIC must be 32-bits in size");
623+
ret = -EINVAL;
633624
}
634625

635626
return ret;

hypervisor/arch/x86/ioapic.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
#include <hypervisor.h>
88

9-
/* Register offsets */
10-
#define IOAPIC_REGSEL_OFFSET 0
11-
#define IOAPIC_WINSWL_OFFSET 0x10
12-
13-
#define IOAPIC_MAX_PIN 240U
9+
#define IOAPIC_MAX_PIN 240U
1410
#define IOAPIC_INVALID_PIN 0xffU
1511

1612
struct gsi_table {
@@ -103,9 +99,9 @@ ioapic_read_reg32(const void *ioapic_base, const uint32_t offset)
10399
spinlock_irqsave_obtain(&ioapic_lock);
104100

105101
/* Write IOREGSEL */
106-
mmio_write_long(offset, (void *)ioapic_base + IOAPIC_REGSEL_OFFSET);
102+
mmio_write_long(offset, (void *)ioapic_base + IOAPIC_REGSEL);
107103
/* Read IOWIN */
108-
v = mmio_read_long((void *)ioapic_base + IOAPIC_WINSWL_OFFSET);
104+
v = mmio_read_long((void *)ioapic_base + IOAPIC_WINDOW);
109105

110106
spinlock_irqrestore_release(&ioapic_lock);
111107
return v;
@@ -120,9 +116,9 @@ ioapic_write_reg32(const void *ioapic_base,
120116
spinlock_irqsave_obtain(&ioapic_lock);
121117

122118
/* Write IOREGSEL */
123-
mmio_write_long(offset, (void *)ioapic_base + IOAPIC_REGSEL_OFFSET);
119+
mmio_write_long(offset, (void *)ioapic_base + IOAPIC_REGSEL);
124120
/* Write IOWIN */
125-
mmio_write_long(value, (void *)ioapic_base + IOAPIC_WINSWL_OFFSET);
121+
mmio_write_long(value, (void *)ioapic_base + IOAPIC_WINDOW);
126122

127123
spinlock_irqrestore_release(&ioapic_lock);
128124
}

hypervisor/include/arch/x86/apicreg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ union ioapic_rte {
449449
#define DEFAULT_IO_APIC_BASE 0xfec00000UL
450450

451451
/* window register offset */
452+
#define IOAPIC_REGSEL 0x00U
452453
#define IOAPIC_WINDOW 0x10U
453454
#define IOAPIC_EOIR 0x40U
454455

hypervisor/include/arch/x86/guest/vioapic.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ int vioapic_deassert_irq(struct vm *vm, uint32_t irq);
4646
int vioapic_pulse_irq(struct vm *vm, uint32_t irq);
4747
void vioapic_update_tmr(struct vcpu *vcpu);
4848

49-
int vioapic_mmio_write(void *vm, uint64_t gpa,
50-
uint64_t wval, int size);
51-
int vioapic_mmio_read(void *vm, uint64_t gpa,
52-
uint64_t *rval, int size);
49+
void vioapic_mmio_write(struct vm *vm, uint64_t gpa, uint32_t wval);
50+
void vioapic_mmio_read(struct vm *vm, uint64_t gpa, uint32_t *rval);
5351

5452
uint8_t vioapic_pincount(struct vm *vm);
5553
void vioapic_process_eoi(struct vm *vm, uint32_t vector);

0 commit comments

Comments
 (0)