Skip to content

Commit 70d4dba

Browse files
JasonChenCJjren1
authored andcommitted
ptdev: change the ptdev_lock from per-vm to global
this patch is a preparation for changing ptdev remapping entry from virtual to physical based, it changes the ptdev_lock from per-vm to global, as entries based on physical mode are global resource. Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent 9d02932 commit 70d4dba

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

hypervisor/arch/x86/assign.c

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242
static struct list_head softirq_dev_entry_list;
4343
/* passthrough device link */
4444
static struct list_head ptdev_list;
45+
static spinlock_t ptdev_lock;
4546

4647
/*
4748
* entry could both be in ptdev_list and softirq_dev_entry_list.
4849
* When release entry, we need make sure entry deleted from both
4950
* lists. We have to require two locks and the lock sequence is:
50-
* vm->ptdev_lock
51+
* ptdev_lock
5152
* softirq_dev_lock
5253
*/
5354
static spinlock_t softirq_dev_lock;
@@ -115,9 +116,9 @@ get_remapping_entry(struct vm *vm, uint32_t id)
115116
{
116117
struct ptdev_remapping_info *entry;
117118

118-
spinlock_obtain(&vm->ptdev_lock);
119+
spinlock_obtain(&ptdev_lock);
119120
entry = _get_remapping_entry(vm, id);
120-
spinlock_release(&vm->ptdev_lock);
121+
spinlock_release(&ptdev_lock);
121122
return entry;
122123
}
123124

@@ -297,7 +298,7 @@ static void check_deactive_pic_intx(struct vm *vm, uint8_t phys_pin)
297298
if (phys_pin >= NR_LEGACY_IRQ)
298299
return;
299300

300-
spinlock_obtain(&vm->ptdev_lock);
301+
spinlock_obtain(&ptdev_lock);
301302
list_for_each(pos, &ptdev_list) {
302303
entry = list_entry(pos, struct ptdev_remapping_info,
303304
entry_node);
@@ -315,7 +316,7 @@ static void check_deactive_pic_intx(struct vm *vm, uint8_t phys_pin)
315316
entry->vm->attr.id, entry->intx.virt_pin);
316317
}
317318
}
318-
spinlock_release(&vm->ptdev_lock);
319+
spinlock_release(&ptdev_lock);
319320
}
320321

321322
static bool ptdev_native_owned_intx(struct vm *vm, struct ptdev_intx_info *info)
@@ -430,7 +431,7 @@ add_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint16_t phys_bdf,
430431
{
431432
struct ptdev_remapping_info *entry;
432433

433-
spinlock_obtain(&vm->ptdev_lock);
434+
spinlock_obtain(&ptdev_lock);
434435
entry = _get_remapping_entry(vm,
435436
entry_id_from_msix(virt_bdf, msix_entry_index));
436437
if (!entry) {
@@ -439,7 +440,7 @@ add_msix_remapping(struct vm *vm, uint16_t virt_bdf, uint16_t phys_bdf,
439440
entry->phys_bdf = phys_bdf;
440441
entry->msi.msix_entry_index = msix_entry_index;
441442
}
442-
spinlock_release(&vm->ptdev_lock);
443+
spinlock_release(&ptdev_lock);
443444

444445
dev_dbg(ACRN_DBG_IRQ,
445446
"VM%d MSIX add vector mapping vbdf%x:pbdf%x idx=%d",
@@ -453,7 +454,7 @@ remove_msix_remapping(struct vm *vm, uint16_t virt_bdf, int msix_entry_index)
453454
{
454455
struct ptdev_remapping_info *entry;
455456

456-
spinlock_obtain(&vm->ptdev_lock);
457+
spinlock_obtain(&ptdev_lock);
457458
entry = _get_remapping_entry(vm,
458459
entry_id_from_msix(virt_bdf, msix_entry_index));
459460
if (!entry)
@@ -471,7 +472,7 @@ remove_msix_remapping(struct vm *vm, uint16_t virt_bdf, int msix_entry_index)
471472
release_entry(entry);
472473

473474
END:
474-
spinlock_release(&vm->ptdev_lock);
475+
spinlock_release(&ptdev_lock);
475476

476477
}
477478

@@ -483,7 +484,7 @@ add_intx_remapping(struct vm *vm, uint8_t virt_pin, uint8_t phys_pin, bool pic_p
483484
enum ptdev_vpin_source vpin_src =
484485
pic_pin ? PTDEV_VPIN_PIC : PTDEV_VPIN_IOAPIC;
485486

486-
spinlock_obtain(&vm->ptdev_lock);
487+
spinlock_obtain(&ptdev_lock);
487488
entry = _get_remapping_entry(vm,
488489
entry_id_from_intx(virt_pin, vpin_src));
489490
if (!entry) {
@@ -494,7 +495,7 @@ add_intx_remapping(struct vm *vm, uint8_t virt_pin, uint8_t phys_pin, bool pic_p
494495
/* update existing */
495496
entry->intx.virt_pin = virt_pin;
496497
entry->intx.phys_pin = phys_pin;
497-
spinlock_release(&vm->ptdev_lock);
498+
spinlock_release(&ptdev_lock);
498499

499500
dev_dbg(ACRN_DBG_IRQ,
500501
"VM%d INTX add pin mapping vpin%d:ppin%d",
@@ -511,7 +512,7 @@ void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
511512
enum ptdev_vpin_source vpin_src =
512513
pic_pin ? PTDEV_VPIN_PIC : PTDEV_VPIN_IOAPIC;
513514

514-
spinlock_obtain(&vm->ptdev_lock);
515+
spinlock_obtain(&ptdev_lock);
515516
entry = _get_remapping_entry(vm,
516517
entry_id_from_intx(virt_pin, vpin_src));
517518
if (!entry)
@@ -537,7 +538,7 @@ void remove_intx_remapping(struct vm *vm, uint8_t virt_pin, bool pic_pin)
537538
release_entry(entry);
538539

539540
END:
540-
spinlock_release(&vm->ptdev_lock);
541+
spinlock_release(&ptdev_lock);
541542
}
542543

543544
static void ptdev_intr_handle_irq(struct vm *vm,
@@ -860,21 +861,17 @@ void ptdev_init(void)
860861
return;
861862

862863
INIT_LIST_HEAD(&ptdev_list);
864+
spinlock_init(&ptdev_lock);
863865
INIT_LIST_HEAD(&softirq_dev_entry_list);
864866
spinlock_init(&softirq_dev_lock);
865867
}
866868

867-
void ptdev_vm_init(struct vm *vm)
868-
{
869-
spinlock_init(&vm->ptdev_lock);
870-
}
871-
872869
void ptdev_vm_deinit(struct vm *vm)
873870
{
874871
/* VM already down */
875-
spinlock_obtain(&vm->ptdev_lock);
872+
spinlock_obtain(&ptdev_lock);
876873
release_all_entry(vm);
877-
spinlock_release(&vm->ptdev_lock);
874+
spinlock_release(&ptdev_lock);
878875
}
879876

880877
void ptdev_add_intx_remapping(struct vm *vm,
@@ -979,33 +976,29 @@ int get_ptdev_info(char *str, int str_max)
979976
uint64_t dest;
980977
bool lvl_tm;
981978
int pin, vpin, bdf, vbdf;
982-
struct list_head *pos, *vm_pos;
983-
struct vm *vm;
979+
struct list_head *pos;
984980

985981
len = snprintf(str, size,
986982
"\r\nVM\tTYPE\tIRQ\tVEC\tDEST\tTM\tPIN\tVPIN\tBDF\tVBDF");
987983
size -= len;
988984
str += len;
989985

990-
spinlock_obtain(&vm_list_lock);
991-
list_for_each(vm_pos, &vm_list) {
992-
vm = list_entry(vm_pos, struct vm, list);
993-
spinlock_obtain(&vm->ptdev_lock);
994-
list_for_each(pos, &ptdev_list) {
995-
entry = list_entry(pos, struct ptdev_remapping_info,
996-
entry_node);
997-
if (entry_is_active(entry)) {
998-
get_entry_info(entry, type, &irq, &vector,
986+
spinlock_obtain(&ptdev_lock);
987+
list_for_each(pos, &ptdev_list) {
988+
entry = list_entry(pos, struct ptdev_remapping_info,
989+
entry_node);
990+
if (entry_is_active(entry)) {
991+
get_entry_info(entry, type, &irq, &vector,
999992
&dest, &lvl_tm, &pin, &vpin,
1000993
&bdf, &vbdf);
1001-
len = snprintf(str, size,
994+
len = snprintf(str, size,
1002995
"\r\n%d\t%s\t%d\t0x%X\t0x%X",
1003996
entry->vm->attr.id, type,
1004997
irq, vector, dest);
1005-
size -= len;
1006-
str += len;
998+
size -= len;
999+
str += len;
10071000

1008-
len = snprintf(str, size,
1001+
len = snprintf(str, size,
10091002
"\t%s\t%d\t%d\t%x:%x.%x\t%x:%x.%x",
10101003
entry_is_active(entry) ?
10111004
(lvl_tm ? "level" : "edge") : "none",
@@ -1014,13 +1007,11 @@ int get_ptdev_info(char *str, int str_max)
10141007
(bdf & 0xf8) >> 3, bdf & 0x7,
10151008
(vbdf & 0xff00) >> 8,
10161009
(vbdf & 0xf8) >> 3, vbdf & 0x7);
1017-
size -= len;
1018-
str += len;
1019-
}
1010+
size -= len;
1011+
str += len;
10201012
}
1021-
spinlock_release(&vm->ptdev_lock);
10221013
}
1023-
spinlock_release(&vm_list_lock);
1014+
spinlock_release(&ptdev_lock);
10241015

10251016
snprintf(str, size, "\r\n");
10261017
return 0;

hypervisor/arch/x86/guest/vm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm)
167167

168168
/* Populate return VM handle */
169169
*rtn_vm = vm;
170-
ptdev_vm_init(vm);
171170
vm->sw.req_buf = 0;
172171

173172
status = set_vcpuid_entries(vm);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ struct vm {
174174
struct _vm_virtual_device_node *tail;
175175
} virtual_device_list;
176176

177-
spinlock_t ptdev_lock;
178-
179177
unsigned char GUID[16];
180178
struct secure_world_control sworld_control;
181179

0 commit comments

Comments
 (0)