Skip to content

Commit e8479f8

Browse files
lifeixwenlingz
authored andcommitted
hv: vPCI: remove passthrough PCI device unuse code
Now we split passthrough PCI device from DM to HV, we could remove all the passthrough PCI device unused code. Tracked-On: #4371 Signed-off-by: Li Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 9fa6eff commit e8479f8

File tree

9 files changed

+43
-284
lines changed

9 files changed

+43
-284
lines changed

doc/developer-guides/hld/hv-dev-passthrough.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,6 @@ for UOS.
251251
.. doxygenfunction:: ptirq_remove_intx_remapping
252252
:project: Project ACRN
253253

254-
.. doxygenfunction:: ptirq_add_msix_remapping
255-
:project: Project ACRN
256-
257254
.. doxygenfunction:: ptirq_remove_msix_remapping
258255
:project: Project ACRN
259256

hypervisor/arch/x86/guest/assign.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,7 @@ int32_t ptirq_prepare_msix_remap(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t
610610
union pci_bdf vbdf;
611611

612612
/*
613-
* Device Model should pre-hold the mapping entries by calling
614-
* ptirq_add_msix_remapping for UOS.
615-
*
616-
* For SOS(sos_vm), it adds the mapping entries at runtime, if the
613+
* adds the mapping entries at runtime, if the
617614
* entry already be held by others, return error.
618615
*/
619616
spinlock_obtain(&ptdev_lock);
@@ -842,32 +839,3 @@ void ptirq_remove_msix_remapping(const struct acrn_vm *vm, uint16_t virt_bdf,
842839
spinlock_release(&ptdev_lock);
843840
}
844841
}
845-
846-
/* except sos_vm, Device Model should call this function to pre-hold ptdev msi
847-
* entries:
848-
* - the entry is identified by phys_bdf:msi_idx:
849-
* one entry vs. one phys_bdf:msi_idx
850-
*/
851-
int32_t ptirq_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf,
852-
uint16_t phys_bdf, uint32_t vector_count)
853-
{
854-
struct ptirq_remapping_info *entry;
855-
uint32_t i;
856-
uint32_t vector_added = 0U;
857-
858-
for (i = 0U; i < vector_count; i++) {
859-
spinlock_obtain(&ptdev_lock);
860-
entry = add_msix_remapping(vm, virt_bdf, phys_bdf, i);
861-
spinlock_release(&ptdev_lock);
862-
if (entry == NULL) {
863-
break;
864-
}
865-
vector_added++;
866-
}
867-
868-
if (vector_added != vector_count) {
869-
ptirq_remove_msix_remapping(vm, virt_bdf, vector_added);
870-
}
871-
872-
return (vector_added == vector_count) ? 0 : -ENODEV;
873-
}

hypervisor/arch/x86/guest/vmcall.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,6 @@ static int32_t dispatch_sos_hypercall(const struct acrn_vcpu *vcpu)
167167
}
168168
break;
169169

170-
case HC_ASSIGN_PTDEV:
171-
/* param1: relative vmid to sos, vm_id: absolute vmid */
172-
if (vmid_is_valid) {
173-
ret = hcall_assign_ptdev(sos_vm, vm_id, param2);
174-
}
175-
break;
176-
177-
case HC_DEASSIGN_PTDEV:
178-
/* param1: relative vmid to sos, vm_id: absolute vmid */
179-
if (vmid_is_valid) {
180-
ret = hcall_deassign_ptdev(sos_vm, vm_id, param2);
181-
}
182-
break;
183-
184170
case HC_ASSIGN_PCIDEV:
185171
/* param1: relative vmid to sos, vm_id: absolute vmid */
186172
if (vmid_is_valid) {

hypervisor/common/hypercall.c

Lines changed: 27 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -814,74 +814,6 @@ int32_t hcall_gpa_to_hpa(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
814814
return ret;
815815
}
816816

817-
/**
818-
* @brief Assign one passthrough dev to VM.
819-
*
820-
* @param vm Pointer to VM data structure
821-
* @param vmid ID of the VM
822-
* @param param the physical BDF of the assigning ptdev
823-
*
824-
* @pre Pointer vm shall point to SOS_VM
825-
* @return 0 on success, non-zero on error.
826-
*/
827-
int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
828-
{
829-
int32_t ret = 0;
830-
union pci_bdf bdf;
831-
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
832-
struct pci_vdev *vdev;
833-
834-
if (!is_poweroff_vm(target_vm) && is_postlaunched_vm(target_vm)) {
835-
bdf.value = (uint16_t)param;
836-
837-
spinlock_obtain(&vm->vpci.lock);
838-
vdev = pci_find_vdev(&vm->vpci, bdf);
839-
if ((vdev == NULL) || (vdev->pdev == NULL)) {
840-
pr_fatal("%s %x:%x.%x not found\n", __func__, bdf.bits.b, bdf.bits.d, bdf.bits.f);
841-
ret = -EPERM;
842-
} else {
843-
/* ToDo: Each PT device must support one type reset */
844-
if (!vdev->pdev->has_pm_reset && !vdev->pdev->has_flr && !vdev->pdev->has_af_flr) {
845-
pr_fatal("%s %x:%x.%x not support FLR or not support PM reset\n",
846-
__func__, bdf.bits.b, bdf.bits.d, bdf.bits.f);
847-
}
848-
}
849-
spinlock_release(&vm->vpci.lock);
850-
if (ret == 0) {
851-
ret = move_pt_device(vm->iommu, target_vm->iommu, bdf.fields.bus, bdf.fields.devfun);
852-
}
853-
} else {
854-
pr_err("%s, target vm is invalid\n", __func__);
855-
ret = -EINVAL;
856-
}
857-
858-
return ret;
859-
}
860-
861-
/**
862-
* @brief Deassign one passthrough dev from VM.
863-
*
864-
* @param vm Pointer to VM data structure
865-
* @param vmid ID of the VM
866-
* @param param the physical BDF of the deassigning ptdev
867-
*
868-
* @pre Pointer vm shall point to SOS_VM
869-
* @return 0 on success, non-zero on error.
870-
*/
871-
int32_t hcall_deassign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
872-
{
873-
int32_t ret = -1;
874-
union pci_bdf bdf;
875-
struct acrn_vm *target_vm = get_vm_from_vmid(vmid);
876-
877-
if (!is_poweroff_vm(target_vm) && is_postlaunched_vm(target_vm)) {
878-
bdf.value = (uint16_t)param;
879-
ret = move_pt_device(target_vm->iommu, vm->iommu, bdf.fields.bus, bdf.fields.devfun);
880-
}
881-
882-
return ret;
883-
}
884-
885817
/**
886818
* @brief Assign one PCI dev to a VM.
887819
*
@@ -964,20 +896,20 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa
964896
if (copy_from_gpa(vm, &irq, param, sizeof(irq)) != 0) {
965897
pr_err("%s: Unable copy param to vm\n", __func__);
966898
} else {
967-
/* Inform vPCI about the interupt info changes */
968-
vpci_set_ptdev_intr_info(target_vm, irq.virt_bdf, irq.phys_bdf);
969-
970899
if (irq.type == IRQ_INTX) {
971-
ret = ptirq_add_intx_remapping(target_vm, irq.is.intx.virt_pin,
972-
irq.is.intx.phys_pin, irq.is.intx.pic_pin);
973-
} else if (((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) &&
974-
(irq.is.msix.vector_cnt <= CONFIG_MAX_MSIX_TABLE_NUM)) {
975-
ret = ptirq_add_msix_remapping(target_vm,
976-
irq.virt_bdf, irq.phys_bdf,
977-
irq.is.msix.vector_cnt);
900+
struct pci_vdev *vdev;
901+
union pci_bdf bdf = {.value = irq.virt_bdf};
902+
struct acrn_vpci *vpci = &target_vm->vpci;
903+
904+
spinlock_obtain(&vpci->lock);
905+
vdev = pci_find_vdev(vpci, bdf);
906+
spinlock_release(&vpci->lock);
907+
if ((vdev != NULL) && (vdev->pdev->bdf.value == irq.phys_bdf)) {
908+
ret = ptirq_add_intx_remapping(target_vm, irq.intx.virt_pin,
909+
irq.intx.phys_pin, irq.intx.pic_pin);
910+
}
978911
} else {
979-
pr_err("%s: Invalid irq type: %u or MSIX vector count: %u\n",
980-
__func__, irq.type, irq.is.msix.vector_cnt);
912+
pr_err("%s: Invalid irq type: %u\n", __func__, irq.type);
981913
}
982914
}
983915
}
@@ -1006,28 +938,22 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
1006938

1007939
if (copy_from_gpa(vm, &irq, param, sizeof(irq)) != 0) {
1008940
pr_err("%s: Unable copy param to vm\n", __func__);
1009-
} else if (irq.type == IRQ_INTX) {
1010-
vpci_reset_ptdev_intr_info(target_vm, irq.virt_bdf, irq.phys_bdf);
1011-
ptirq_remove_intx_remapping(target_vm,
1012-
irq.is.intx.virt_pin,
1013-
irq.is.intx.pic_pin);
1014-
ret = 0;
1015-
} else if (((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) &&
1016-
(irq.is.msix.vector_cnt <= CONFIG_MAX_MSIX_TABLE_NUM)) {
1017-
1018-
/*
1019-
* Inform vPCI about the interupt info changes
1020-
* TODO: Need to add bdf info for IRQ_INTX type in devicemodel
1021-
*/
1022-
vpci_reset_ptdev_intr_info(target_vm, irq.virt_bdf, irq.phys_bdf);
1023-
1024-
ptirq_remove_msix_remapping(target_vm,
1025-
irq.virt_bdf,
1026-
irq.is.msix.vector_cnt);
1027-
ret = 0;
1028941
} else {
1029-
pr_err("%s: Invalid irq type: %u or MSIX vector count: %u\n",
1030-
__func__, irq.type, irq.is.msix.vector_cnt);
942+
if (irq.type == IRQ_INTX) {
943+
struct pci_vdev *vdev;
944+
union pci_bdf bdf = {.value = irq.virt_bdf};
945+
struct acrn_vpci *vpci = &target_vm->vpci;
946+
947+
spinlock_obtain(&vpci->lock);
948+
vdev = pci_find_vdev(vpci, bdf);
949+
spinlock_release(&vpci->lock);
950+
if ((vdev != NULL) && (vdev->pdev->bdf.value == irq.phys_bdf)) {
951+
ptirq_remove_intx_remapping(target_vm, irq.intx.virt_pin, irq.intx.pic_pin);
952+
ret = 0;
953+
}
954+
} else {
955+
pr_err("%s: Invalid irq type: %u\n", __func__, irq.type);
956+
}
1031957
}
1032958
}
1033959

hypervisor/dm/vpci/vpci.c

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -585,70 +585,6 @@ static void deinit_postlaunched_vm_vpci(struct acrn_vm *vm)
585585
spinlock_release(&sos_vm->vpci.lock);
586586
}
587587

588-
/**
589-
* @pre target_vm != NULL && Pointer target_vm shall point to SOS_VM
590-
*/
591-
void vpci_set_ptdev_intr_info(struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf)
592-
{
593-
struct pci_vdev *vdev, *target_vdev;
594-
struct acrn_vpci *target_vpci;
595-
union pci_bdf bdf;
596-
struct acrn_vm *sos_vm;
597-
598-
bdf.value = pbdf;
599-
sos_vm = get_sos_vm();
600-
spinlock_obtain(&sos_vm->vpci.lock);
601-
vdev = pci_find_vdev(&sos_vm->vpci, bdf);
602-
if ((vdev == NULL) || (vdev->pdev == NULL)) {
603-
pr_err("%s, can't find PCI device for vm%d, vbdf (0x%x) pbdf (0x%x)", __func__,
604-
target_vm->vm_id, vbdf, pbdf);
605-
} else {
606-
if (vdev->vpci->vm == sos_vm) {
607-
spinlock_obtain(&target_vm->vpci.lock);
608-
target_vpci = &(target_vm->vpci);
609-
vdev->vpci = target_vpci;
610-
611-
target_vdev = &target_vpci->pci_vdevs[target_vpci->pci_vdev_cnt];
612-
target_vpci->pci_vdev_cnt++;
613-
(void)memcpy_s((void *)target_vdev, sizeof(struct pci_vdev),
614-
(void *)vdev, sizeof(struct pci_vdev));
615-
target_vdev->bdf.value = vbdf;
616-
617-
vdev->new_owner = target_vdev;
618-
spinlock_release(&target_vm->vpci.lock);
619-
}
620-
}
621-
spinlock_release(&sos_vm->vpci.lock);
622-
}
623-
624-
/**
625-
* @pre target_vm != NULL && Pointer target_vm shall point to SOS_VM
626-
*/
627-
void vpci_reset_ptdev_intr_info(struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf)
628-
{
629-
struct pci_vdev *vdev;
630-
union pci_bdf bdf;
631-
struct acrn_vm *sos_vm;
632-
633-
bdf.value = pbdf;
634-
sos_vm = get_sos_vm();
635-
spinlock_obtain(&sos_vm->vpci.lock);
636-
vdev = pci_find_vdev(&sos_vm->vpci, bdf);
637-
if (vdev == NULL) {
638-
pr_err("%s, can't find PCI device for vm%d, vbdf (0x%x) pbdf (0x%x)", __func__,
639-
target_vm->vm_id, vbdf, pbdf);
640-
} else {
641-
/* Return this PCI device to SOS */
642-
if (vdev->vpci->vm == target_vm) {
643-
spinlock_obtain(&target_vm->vpci.lock);
644-
vdev->vpci = &sos_vm->vpci;
645-
vdev->new_owner = NULL;
646-
spinlock_release(&target_vm->vpci.lock);
647-
}
648-
}
649-
spinlock_release(&sos_vm->vpci.lock);
650-
}
651-
652588
/**
653589
* @brief assign a PCI device from SOS to target post-launched VM.
654590
*

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,6 @@ int32_t ptirq_add_intx_remapping(struct acrn_vm *vm, uint32_t virt_pin, uint32_t
124124
*/
125125
void ptirq_remove_intx_remapping(struct acrn_vm *vm, uint32_t virt_pin, bool pic_pin);
126126

127-
/**
128-
* @brief Add interrupt remapping entry/entries for MSI/MSI-x as pre-hold mapping.
129-
*
130-
* Add pre-hold mapping of the given number of vectors between the given physical and virtual BDF for the given vm.
131-
* Except sos_vm, Device Model should call this function to pre-hold ptdev MSI/MSI-x.
132-
* The entry is identified by phys_bdf:msi_idx, one entry vs. one phys_bdf:msi_idx.
133-
*
134-
* @param[in] vm pointer to acrn_vm
135-
* @param[in] virt_bdf virtual bdf associated with the passthrough device
136-
* @param[in] phys_bdf physical bdf associated with the passthrough device
137-
* @param[in] vector_count number of vectors
138-
*
139-
* @return
140-
* - 0: on success
141-
* - \p -ENODEV: failed to add the remapping entry
142-
*
143-
* @pre vm != NULL
144-
*
145-
*/
146-
int32_t ptirq_add_msix_remapping(struct acrn_vm *vm, uint16_t virt_bdf, uint16_t phys_bdf, uint32_t vector_count);
147-
148127
/**
149128
* @brief Remove interrupt remapping entry/entries for MSI/MSI-x.
150129
*

hypervisor/include/common/hypercall.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -248,30 +248,6 @@ int32_t hcall_write_protect_page(struct acrn_vm *vm, uint16_t vmid, uint64_t wp_
248248
*/
249249
int32_t hcall_gpa_to_hpa(struct acrn_vm *vm, uint16_t vmid, uint64_t param);
250250

251-
/**
252-
* @brief Assign one passthrough dev to VM.
253-
*
254-
* @param vm Pointer to VM data structure
255-
* @param vmid ID of the VM
256-
* @param param the physical BDF of the assigning ptdev
257-
*
258-
* @pre Pointer vm shall point to SOS_VM
259-
* @return 0 on success, non-zero on error.
260-
*/
261-
int32_t hcall_assign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param);
262-
263-
/**
264-
* @brief Deassign one passthrough dev from VM.
265-
*
266-
* @param vm Pointer to VM data structure
267-
* @param vmid ID of the VM
268-
* @param param the physical BDF of the deassigning ptdev
269-
*
270-
* @pre Pointer vm shall point to SOS_VM
271-
* @return 0 on success, non-zero on error.
272-
*/
273-
int32_t hcall_deassign_ptdev(struct acrn_vm *vm, uint16_t vmid, uint64_t param);
274-
275251
/**
276252
* @brief Assign one PCI dev to VM.
277253
*

hypervisor/include/dm/vpci.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ extern const struct pci_vdev_ops vhostbridge_ops;
132132
void vpci_init(struct acrn_vm *vm);
133133
void vpci_cleanup(struct acrn_vm *vm);
134134
struct pci_vdev *pci_find_vdev(struct acrn_vpci *vpci, union pci_bdf vbdf);
135-
void vpci_set_ptdev_intr_info(struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf);
136-
void vpci_reset_ptdev_intr_info(struct acrn_vm *target_vm, uint16_t vbdf, uint16_t pbdf);
137135
struct acrn_assign_pcidev;
138136
int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);
139137
int32_t vpci_deassign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pcidev);

0 commit comments

Comments
 (0)