Skip to content

Commit 004d2e2

Browse files
junjiemao1lijinxia
authored andcommitted
HV: treewide: give names to unnamed structs/unions
According to the syntax defined in C99, each struct/union field must have an identifier. This patch adds names to the previously unnamed fields for C99 compatibility. Here is a summary of the names (marked with a pair of *stars*) added. struct trusty_mem: union { struct { struct key_info key_info; struct trusty_startup_param startup_param; } *data*; uint8_t page[CPU_PAGE_SIZE]; } first_page; struct ptdev_remapping_info: union { struct ptdev_msi_info msi; struct ptdev_intx_info intx; } *ptdev_intr_info*; union code_segment_descriptor: uint64_t value; struct { union { ... } low32; union { ... } high32; } *fields*; similar changes are made to the following structures. * union data_segment_descriptor, * union system_segment_descriptor, * union tss_64_descriptor, and * union idt_64_descriptor struct trace_entry: union { struct { uint32_t a, b, c, d; } *fields_32*; struct { uint8_t a1, a2, a3, a4; uint8_t b1, b2, b3, b4; uint8_t c1, c2, c3, c4; uint8_t d1, d2, d3, d4; } *fields_8*; struct { uint64_t e; uint64_t f; } *fields_64*; char str[16]; } *payload*; Signed-off-by: Junjie Mao <junjie.mao@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
1 parent ef3cb5b commit 004d2e2

File tree

7 files changed

+129
-100
lines changed

7 files changed

+129
-100
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 87 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ entry_id(struct ptdev_remapping_info *entry)
7777
uint32_t id;
7878

7979
if (entry->type == PTDEV_INTR_INTX)
80-
id = entry_id_from_intx(entry->intx.phys_pin);
80+
id = entry_id_from_intx(entry->ptdev_intr_info.intx.phys_pin);
8181
else
8282
id = entry_id_from_msix(entry->phys_bdf,
83-
entry->msi.msix_entry_index);
83+
entry->ptdev_intr_info.msi.msix_entry_index);
8484

8585
return id;
8686
}
@@ -138,7 +138,8 @@ _lookup_entry_by_vmsi(struct vm *vm, uint16_t vbdf, int32_t index)
138138
if ((entry->type == PTDEV_INTR_MSI)
139139
&& (entry->vm == vm)
140140
&& (entry->virt_bdf == vbdf)
141-
&& (entry->msi.msix_entry_index == index))
141+
&& (entry->ptdev_intr_info.msi.msix_entry_index
142+
== index))
142143
return entry;
143144
}
144145

@@ -169,8 +170,8 @@ _lookup_entry_by_vintx(struct vm *vm, uint8_t vpin,
169170
entry_node);
170171
if ((entry->type == PTDEV_INTR_INTX)
171172
&& (entry->vm == vm)
172-
&& (entry->intx.virt_pin == vpin)
173-
&& (entry->intx.vpin_src == vpin_src))
173+
&& (entry->ptdev_intr_info.intx.virt_pin == vpin)
174+
&& (entry->ptdev_intr_info.intx.vpin_src == vpin_src))
174175
return entry;
175176
}
176177

@@ -299,12 +300,13 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
299300
}
300301
/* update irq handler for IOAPIC */
301302
if ((entry->type == PTDEV_INTR_INTX)
302-
&& (entry->intx.vpin_src == PTDEV_VPIN_IOAPIC)) {
303+
&& (entry->ptdev_intr_info.intx.vpin_src
304+
== PTDEV_VPIN_IOAPIC)) {
303305
uint64_t rte;
304306
bool trigger_lvl = false;
305307

306308
/* VPIN_IOAPIC src means we have vioapic enabled */
307-
vioapic_get_rte(vm, entry->intx.virt_pin, &rte);
309+
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
308310
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL)
309311
trigger_lvl = true;
310312

@@ -315,11 +317,12 @@ ptdev_update_irq_handler(struct vm *vm, struct ptdev_remapping_info *entry)
315317
}
316318
/* update irq handler for PIC */
317319
if ((entry->type == PTDEV_INTR_INTX) && (phys_irq < NR_LEGACY_IRQ)
318-
&& (entry->intx.vpin_src == PTDEV_VPIN_PIC)) {
320+
&& (entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_PIC)) {
319321
enum vpic_trigger trigger;
320322

321323
/* VPIN_PIC src means we have vpic enabled */
322-
vpic_get_irq_trigger(vm, entry->intx.virt_pin, &trigger);
324+
vpic_get_irq_trigger(vm,
325+
entry->ptdev_intr_info.intx.virt_pin, &trigger);
323326
if (trigger == LEVEL_TRIGGER)
324327
update_irq_handler(phys_irq, common_dev_handler_level);
325328
else
@@ -413,12 +416,12 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
413416
int phys_irq = dev_to_irq(entry->node);
414417
int vector = dev_to_vector(entry->node);
415418

416-
if (entry->intx.vpin_src == PTDEV_VPIN_IOAPIC) {
419+
if (entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_IOAPIC) {
417420
uint64_t vdmask, pdmask;
418421
uint32_t dest, low, high, delmode;
419422
bool phys;
420423

421-
vioapic_get_rte(vm, entry->intx.virt_pin, &rte);
424+
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
422425
low = rte;
423426
high = rte >> 32;
424427

@@ -456,7 +459,8 @@ static uint64_t ptdev_build_physical_rte(struct vm *vm,
456459
ioapic_get_rte(phys_irq, &physical_rte);
457460
rte = physical_rte;
458461
rte &= ~IOAPIC_RTE_TRGRMOD;
459-
vpic_get_irq_trigger(vm, entry->intx.virt_pin, &trigger);
462+
vpic_get_irq_trigger(vm,
463+
entry->ptdev_intr_info.intx.virt_pin, &trigger);
460464
if (trigger == LEVEL_TRIGGER)
461465
rte |= IOAPIC_RTE_TRGRLVL;
462466

@@ -492,14 +496,15 @@ add_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint16_t phys_bdf,
492496
entry = alloc_entry(vm, PTDEV_INTR_MSI);
493497
entry->virt_bdf = virt_bdf;
494498
entry->phys_bdf = phys_bdf;
495-
entry->msi.msix_entry_index = msix_entry_index;
499+
entry->ptdev_intr_info.msi.msix_entry_index = msix_entry_index;
496500
} else if ((entry->vm != vm) && is_vm0(entry->vm)) {
497501
entry->vm = vm;
498502
entry->virt_bdf = virt_bdf;
499503
} else if ((entry->vm != vm) && !is_vm0(entry->vm)) {
500504
pr_err("MSIX pbdf%x idx=%d already in vm%d with vbdf%x, not "
501505
"able to add into vm%d with vbdf%x", entry->phys_bdf,
502-
entry->msi.msix_entry_index, entry->vm->attr.id,
506+
entry->ptdev_intr_info.msi.msix_entry_index,
507+
entry->vm->attr.id,
503508
entry->virt_bdf, vm->attr.id, virt_bdf);
504509
ASSERT(0, "msix entry pbdf%x idx%d already in vm%d",
505510
phys_bdf, msix_entry_index, entry->vm->attr.id);
@@ -565,17 +570,19 @@ add_intx_remapping(struct vm *vm, uint8_t virt_pin,
565570
return &invalid_entry;
566571
}
567572
entry = alloc_entry(vm, PTDEV_INTR_INTX);
568-
entry->intx.phys_pin = phys_pin;
569-
entry->intx.virt_pin = virt_pin;
570-
entry->intx.vpin_src = vpin_src;
573+
entry->ptdev_intr_info.intx.phys_pin = phys_pin;
574+
entry->ptdev_intr_info.intx.virt_pin = virt_pin;
575+
entry->ptdev_intr_info.intx.vpin_src = vpin_src;
571576
} else if ((entry->vm != vm) && is_vm0(entry->vm)) {
572577
entry->vm = vm;
573-
entry->intx.virt_pin = virt_pin;
574-
entry->intx.vpin_src = vpin_src;
578+
entry->ptdev_intr_info.intx.virt_pin = virt_pin;
579+
entry->ptdev_intr_info.intx.vpin_src = vpin_src;
575580
} else if ((entry->vm != vm) && !is_vm0(entry->vm)) {
576581
pr_err("INTX pin%d already in vm%d with vpin%d, not able to "
577-
"add into vm%d with vpin%d", entry->intx.phys_pin,
578-
entry->vm->attr.id, entry->intx.virt_pin,
582+
"add into vm%d with vpin%d",
583+
entry->ptdev_intr_info.intx.phys_pin,
584+
entry->vm->attr.id,
585+
entry->ptdev_intr_info.intx.virt_pin,
579586
vm->attr.id, virt_pin);
580587
ASSERT(0, "intx entry pin%d already vm%d",
581588
phys_pin, entry->vm->attr.id);
@@ -617,10 +624,12 @@ void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
617624
ptdev_deactivate_entry(entry);
618625
dev_dbg(ACRN_DBG_IRQ,
619626
"deactive %s intx entry:ppin=%d, pirq=%d ",
620-
entry->intx.vpin_src == PTDEV_VPIN_PIC ?
621-
"vPIC" : "vIOAPIC", entry->intx.phys_pin, phys_irq);
627+
entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_PIC ?
628+
"vPIC" : "vIOAPIC",
629+
entry->ptdev_intr_info.intx.phys_pin, phys_irq);
622630
dev_dbg(ACRN_DBG_IRQ, "from vm%d vpin=%d\n",
623-
entry->vm->attr.id, entry->intx.virt_pin);
631+
entry->vm->attr.id,
632+
entry->ptdev_intr_info.intx.virt_pin);
624633
}
625634

626635
release_entry(entry);
@@ -632,21 +641,23 @@ void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
632641
static void ptdev_intr_handle_irq(struct vm *vm,
633642
struct ptdev_remapping_info *entry)
634643
{
635-
switch (entry->intx.vpin_src) {
644+
switch (entry->ptdev_intr_info.intx.vpin_src) {
636645
case PTDEV_VPIN_IOAPIC:
637646
{
638647
uint64_t rte;
639648
bool trigger_lvl = false;
640649

641650
/* VPIN_IOAPIC src means we have vioapic enabled */
642-
vioapic_get_rte(vm, entry->intx.virt_pin, &rte);
651+
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
643652
if ((rte & IOAPIC_RTE_TRGRMOD) == IOAPIC_RTE_TRGRLVL)
644653
trigger_lvl = true;
645654

646655
if (trigger_lvl)
647-
vioapic_assert_irq(vm, entry->intx.virt_pin);
656+
vioapic_assert_irq(vm,
657+
entry->ptdev_intr_info.intx.virt_pin);
648658
else
649-
vioapic_pulse_irq(vm, entry->intx.virt_pin);
659+
vioapic_pulse_irq(vm,
660+
entry->ptdev_intr_info.intx.virt_pin);
650661

651662
dev_dbg(ACRN_DBG_PTIRQ,
652663
"dev-assign: irq=0x%x assert vr: 0x%x vRTE=0x%x",
@@ -659,11 +670,14 @@ static void ptdev_intr_handle_irq(struct vm *vm,
659670
enum vpic_trigger trigger;
660671

661672
/* VPIN_PIC src means we have vpic enabled */
662-
vpic_get_irq_trigger(vm, entry->intx.virt_pin, &trigger);
673+
vpic_get_irq_trigger(vm,
674+
entry->ptdev_intr_info.intx.virt_pin, &trigger);
663675
if (trigger == LEVEL_TRIGGER)
664-
vpic_assert_irq(vm, entry->intx.virt_pin);
676+
vpic_assert_irq(vm,
677+
entry->ptdev_intr_info.intx.virt_pin);
665678
else
666-
vpic_pulse_irq(vm, entry->intx.virt_pin);
679+
vpic_pulse_irq(vm,
680+
entry->ptdev_intr_info.intx.virt_pin);
667681
break;
668682
}
669683
default:
@@ -694,16 +708,18 @@ void ptdev_softirq(__unused int cpu)
694708
ptdev_intr_handle_irq(vm, entry);
695709
else {
696710
/* TODO: msi destmode check required */
697-
vlapic_intr_msi(vm, entry->msi.vmsi_addr,
698-
entry->msi.vmsi_data);
711+
vlapic_intr_msi(vm,
712+
entry->ptdev_intr_info.msi.vmsi_addr,
713+
entry->ptdev_intr_info.msi.vmsi_data);
699714
dev_dbg(ACRN_DBG_PTIRQ,
700715
"dev-assign: irq=0x%x MSI VR: 0x%x-0x%x",
701716
dev_to_irq(entry->node),
702-
entry->msi.virt_vector,
717+
entry->ptdev_intr_info.msi.virt_vector,
703718
irq_to_vector(dev_to_irq(entry->node)));
704719
dev_dbg(ACRN_DBG_PTIRQ,
705720
" vmsi_addr: 0x%x vmsi_data: 0x%x",
706-
entry->msi.vmsi_addr, entry->msi.vmsi_data);
721+
entry->ptdev_intr_info.msi.vmsi_addr,
722+
entry->ptdev_intr_info.msi.vmsi_data);
707723
}
708724
}
709725
}
@@ -719,15 +735,15 @@ void ptdev_intx_ack(struct vm *vm, int virt_pin,
719735
if (!entry)
720736
return;
721737

722-
phys_pin = entry->intx.phys_pin;
738+
phys_pin = entry->ptdev_intr_info.intx.phys_pin;
723739
phys_irq = pin_to_irq(phys_pin);
724740
if (!irq_is_gsi(phys_irq))
725741
return;
726742

727743
/* NOTE: only Level trigger will process EOI/ACK and if we got here
728744
* means we have this vioapic or vpic or both enabled
729745
*/
730-
switch (entry->intx.vpin_src) {
746+
switch (entry->ptdev_intr_info.intx.vpin_src) {
731747
case PTDEV_VPIN_IOAPIC:
732748
vioapic_deassert_irq(vm, virt_pin);
733749
break;
@@ -798,9 +814,9 @@ int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf,
798814

799815
/* build physical config MSI, update to info->pmsi_xxx */
800816
ptdev_build_physical_msi(vm, info, dev_to_vector(entry->node));
801-
entry->msi = *info;
802-
entry->msi.virt_vector = info->vmsi_data & 0xFF;
803-
entry->msi.phys_vector = dev_to_vector(entry->node);
817+
entry->ptdev_intr_info.msi = *info;
818+
entry->ptdev_intr_info.msi.virt_vector = info->vmsi_data & 0xFF;
819+
entry->ptdev_intr_info.msi.phys_vector = dev_to_vector(entry->node);
804820

805821
/* update irq handler according to info in guest */
806822
ptdev_update_irq_handler(vm, entry);
@@ -809,8 +825,10 @@ int ptdev_msix_remap(struct vm *vm, uint16_t virt_bdf,
809825
"PCI %x:%x.%x MSI VR[%d] 0x%x->0x%x assigned to vm%d",
810826
(entry->virt_bdf >> 8) & 0xFF,
811827
(entry->virt_bdf >> 3) & 0x1F,
812-
(entry->virt_bdf) & 0x7, entry->msi.msix_entry_index,
813-
entry->msi.virt_vector, entry->msi.phys_vector,
828+
(entry->virt_bdf) & 0x7,
829+
entry->ptdev_intr_info.msi.msix_entry_index,
830+
entry->ptdev_intr_info.msi.virt_vector,
831+
entry->ptdev_intr_info.msi.phys_vector,
814832
entry->vm->attr.id);
815833
END:
816834
return 0;
@@ -938,7 +956,7 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
938956
goto END;
939957

940958
/* phys_pin from physical IOAPIC */
941-
phys_pin = entry->intx.phys_pin;
959+
phys_pin = entry->ptdev_intr_info.intx.phys_pin;
942960
phys_irq = pin_to_irq(phys_pin);
943961
if (!irq_is_gsi(phys_irq))
944962
goto END;
@@ -952,18 +970,21 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
952970
dev_dbg(ACRN_DBG_IRQ,
953971
"IOAPIC pin=%d pirq=%d vpin=%d switch from %s to %s "
954972
"vpin=%d for vm%d", phys_pin, phys_irq,
955-
entry->intx.virt_pin,
956-
entry->intx.vpin_src ? "vPIC" : "vIOAPIC",
957-
entry->intx.vpin_src ? "vIOPIC" : "vPIC",
973+
entry->ptdev_intr_info.intx.virt_pin,
974+
entry->ptdev_intr_info.intx.vpin_src ?
975+
"vPIC" : "vIOAPIC",
976+
entry->ptdev_intr_info.intx.vpin_src ?
977+
"vIOPIC" : "vPIC",
958978
info->virt_pin,
959979
entry->vm->attr.id);
960-
entry->intx.vpin_src = info->vpin_src;
961-
entry->intx.virt_pin = info->virt_pin;
980+
entry->ptdev_intr_info.intx.vpin_src = info->vpin_src;
981+
entry->ptdev_intr_info.intx.virt_pin = info->virt_pin;
962982
}
963983

964984
if (is_entry_active(entry)
965-
&& (entry->intx.vpin_src == PTDEV_VPIN_IOAPIC)) {
966-
vioapic_get_rte(vm, entry->intx.virt_pin, &rte);
985+
&& (entry->ptdev_intr_info.intx.vpin_src
986+
== PTDEV_VPIN_IOAPIC)) {
987+
vioapic_get_rte(vm, entry->ptdev_intr_info.intx.virt_pin, &rte);
967988
if (((uint32_t)rte) == 0x10000) {
968989
/* disable interrupt */
969990
GSI_MASK_IRQ(phys_irq);
@@ -972,14 +993,15 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
972993
"IOAPIC pin=%d pirq=%d deassigned ",
973994
phys_pin, phys_irq);
974995
dev_dbg(ACRN_DBG_IRQ, "from vm%d vIOAPIC vpin=%d",
975-
entry->vm->attr.id, entry->intx.virt_pin);
996+
entry->vm->attr.id,
997+
entry->ptdev_intr_info.intx.virt_pin);
976998
goto END;
977999
} else {
9781000
/*update rte*/
9791001
activate_physical_ioapic(vm, entry);
9801002
}
9811003
} else if (is_entry_active(entry)
982-
&& (entry->intx.vpin_src == PTDEV_VPIN_PIC)) {
1004+
&& (entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_PIC)) {
9831005
/* only update here
9841006
* deactive vPIC entry when IOAPIC take it over
9851007
*/
@@ -993,8 +1015,9 @@ int ptdev_intx_pin_remap(struct vm *vm, struct ptdev_intx_info *info)
9931015
dev_dbg(ACRN_DBG_IRQ,
9941016
"IOAPIC pin=%d pirq=%d assigned to vm%d %s vpin=%d",
9951017
phys_pin, phys_irq, entry->vm->attr.id,
996-
entry->intx.vpin_src == PTDEV_VPIN_PIC ?
997-
"vPIC" : "vIOAPIC", entry->intx.virt_pin);
1018+
entry->ptdev_intr_info.intx.vpin_src == PTDEV_VPIN_PIC ?
1019+
"vPIC" : "vIOAPIC",
1020+
entry->ptdev_intr_info.intx.virt_pin);
9981021
}
9991022
END:
10001023
return 0;
@@ -1095,8 +1118,10 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
10951118
if (is_entry_active(entry)) {
10961119
if (entry->type == PTDEV_INTR_MSI) {
10971120
strcpy_s(type, 16, "MSI");
1098-
*dest = (entry->msi.pmsi_addr & 0xFF000) >> 12;
1099-
if (entry->msi.pmsi_data & APIC_TRIGMOD_LEVEL)
1121+
*dest = (entry->ptdev_intr_info.msi.pmsi_addr & 0xFF000)
1122+
>> 12;
1123+
if (entry->ptdev_intr_info.msi.pmsi_data &
1124+
APIC_TRIGMOD_LEVEL)
11001125
*lvl_tm = true;
11011126
else
11021127
*lvl_tm = false;
@@ -1105,10 +1130,12 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
11051130
*bdf = entry->phys_bdf;
11061131
*vbdf = entry->virt_bdf;
11071132
} else {
1108-
int phys_irq = pin_to_irq(entry->intx.phys_pin);
1133+
int phys_irq = pin_to_irq(
1134+
entry->ptdev_intr_info.intx.phys_pin);
11091135
uint64_t rte = 0;
11101136

1111-
if (entry->intx.vpin_src == PTDEV_VPIN_IOAPIC)
1137+
if (entry->ptdev_intr_info.intx.vpin_src
1138+
== PTDEV_VPIN_IOAPIC)
11121139
strcpy_s(type, 16, "IOAPIC");
11131140
else
11141141
strcpy_s(type, 16, "PIC");
@@ -1118,8 +1145,8 @@ static void get_entry_info(struct ptdev_remapping_info *entry, char *type,
11181145
*lvl_tm = true;
11191146
else
11201147
*lvl_tm = false;
1121-
*pin = entry->intx.phys_pin;
1122-
*vpin = entry->intx.virt_pin;
1148+
*pin = entry->ptdev_intr_info.intx.phys_pin;
1149+
*vpin = entry->ptdev_intr_info.intx.virt_pin;
11231150
*bdf = 0;
11241151
*vbdf = 0;
11251152
}

hypervisor/arch/x86/gdt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ static void set_tss_desc(union tss_64_descriptor *desc,
4646
u3 = ((uint64_t)tss & 0x00FF0000) >> 16;
4747

4848

49-
desc->low32.value = u1 | (tss_limit & 0xFFFF);
50-
desc->base_addr_63_32 = (uint32_t)((uint64_t)tss >> 32);
51-
desc->high32.value = (u2 | ((uint32_t)type << 8) | 0x8000 | u3);
49+
desc->fields.low32.value = u1 | (tss_limit & 0xFFFF);
50+
desc->fields.base_addr_63_32 = (uint32_t)((uint64_t)tss >> 32);
51+
desc->fields.high32.value = (u2 | ((uint32_t)type << 8) | 0x8000 | u3);
5252
}
5353

5454
void load_gdtr_and_tr(void)

0 commit comments

Comments
 (0)