[PATCH 3/3] kvm: emulate command register for SRIOV virtual function

Sheng Yang
2009-03-04T07:54:45Z

MMIO enable byte would be checked when enabling virtual function, but in fact,
the whole virtual function's command register is hard-wired to zero... So when
guest read from command register it would only get 0, specially for MMIO enable
bit.

Then we relay on QEmu to provide a reasonable command register content to guest.

Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
qemu/hw/device-assignment.c | 13 ++++++++++++-
qemu/hw/device-assignment.h | 1 +
2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index 867229d..c88214c 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -26,7 +26,10 @@
* Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com)
*/
#include <stdio.h>
+#include <unistd.h>
#include <sys/io.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "qemu-kvm.h"
#include "hw.h"
#include "pc.h"
@@ -317,7 +320,7 @@ static uint32_t assigned_dev_pci_read_config(PCIDevice *d, uint32_t address,
ssize_t ret;
AssignedDevice *pci_dev = container_of(d, AssignedDevice, dev);

- if (address < 0x4 ||
+ if (address < 0x4 || (pci_dev->need_emulate_cmd && address == 0x4) ||
(address >= 0x10 && address <= 0x24) || address == 0x34 ||
address == 0x3c || address == 0x3d ||
pci_access_cap_config(d, address, len)) {
@@ -431,6 +434,7 @@ static int get_real_device(AssignedDevice *pci_dev, uint8_t r_bus,
FILE *f;
unsigned long long start, end, size, flags;
unsigned long id;
+ struct stat statbuf;
PCIRegion *rp;
PCIDevRegions *dev = &pci_dev->real_device;

@@ -519,6 +523,13 @@ again:
}
fclose(f);

+ /* dealing with virtual function device */
+ snprintf(name, sizeof(name), "%sphysfn/", dir);
+ if (!stat(name, &statbuf))
+ pci_dev->need_emulate_cmd = 1;
+ else
+ pci_dev->need_emulate_cmd = 0;
+
dev->region_number = r;
return 0;
}
diff --git a/qemu/hw/device-assignment.h b/qemu/hw/device-assignment.h
index fc1af8f..cdebaa5 100644
--- a/qemu/hw/device-assignment.h
+++ b/qemu/hw/device-assignment.h
@@ -94,6 +94,7 @@ typedef struct {
void *msix_table_page;
target_phys_addr_t msix_table_addr;
int mmio_index;
+ int need_emulate_cmd;
} AssignedDevice;

typedef struct AssignedDevInfo AssignedDevInfo;
--
1.5.4.5