Re: [PATCH 2/2] hv: vSRIOV: add VF BARs mapping for PF


Eddie Dong
 

-----Original Message-----
From: Li, Fei1 <fei1.li@...>
Sent: Friday, April 22, 2022 3:47 AM
To: acrn-dev@...
Cc: Dong, Eddie <eddie.dong@...>; Chen, Jason CJ
<jason.cj.chen@...>
Subject: [PATCH 2/2] hv: vSRIOV: add VF BARs mapping for PF

When enabling SRIOV capability for a PF in Service VM, ACRN Hypervisor
should add VF BARs mapping for PF since PF's firmware would access these
BARs to do initialization for VFs when it's first created.

Signed-off-by: Fei Li <fei1.li@...>
---
hypervisor/dm/vpci/pci_pt.c | 2 +-
hypervisor/dm/vpci/vsriov.c | 12 ++++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/hypervisor/dm/vpci/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index
4a9568bbc..ec2372b0a 100644
--- a/hypervisor/dm/vpci/pci_pt.c
+++ b/hypervisor/dm/vpci/pci_pt.c
@@ -582,7 +582,7 @@ void init_vdev_pt(struct pci_vdev *vdev, bool
is_pf_vdev)
pci_vdev_write_vcfg(vdev, PCIR_VENDOR, 2U, vid);
pci_vdev_write_vcfg(vdev, PCIR_DEVICE, 2U, did);
} else {
- /* VF is unassinged */
+ /* VF is unassinged: when VF was first created, the
VF's BARs hasn't
+been assigned */
uint32_t bar_idx;

for (bar_idx = 0U; bar_idx < vdev->nr_bars;
bar_idx++) { diff --git a/hypervisor/dm/vpci/vsriov.c
b/hypervisor/dm/vpci/vsriov.c index 9e93f6d9d..940862dde 100644
--- a/hypervisor/dm/vpci/vsriov.c
+++ b/hypervisor/dm/vpci/vsriov.c
@@ -27,6 +27,7 @@
*/

#include <asm/guest/vm.h>
+#include <asm/guest/ept.h>
#include <ptdev.h>
#include <vpci.h>
#include <asm/pci_dev.h>
@@ -134,6 +135,17 @@ static void create_vf(struct pci_vdev *pf_vdev,
union pci_bdf vf_bdf, uint16_t v
pci_vdev_write_vcfg(vf_vdev,
pci_bar_offset(bar_idx), 4U, 0U);
}

+ /* Map VF's BARs when it's first created. */
+ for (bar_idx = 0U; bar_idx < PCI_BAR_COUNT; bar_idx++) {
Can we reuse the loop in above?

+ vf_vbar = &vf_vdev->vbars[bar_idx];
+
+ if (vf_vbar->base_gpa != 0UL) {
+ struct acrn_vm *vm = vpci2vm(vf_vdev-
vpci);
+ ept_add_mr(vm, (uint64_t *)(vm-
arch_vm.nworld_eptp), vf_vbar->base_hpa,
+ vf_vbar->base_gpa, vf_vbar->size,
EPT_WR | EPT_RD | EPT_UNCACHED);
+ }
+ }
+
if (has_msix_cap(vf_vdev)) {
vdev_pt_map_msix(vf_vdev, false);
}
--
2.25.1

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.