From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmRvu-0005D1-LT for qemu-devel@nongnu.org; Tue, 20 Sep 2016 16:46:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmRvt-0007Xh-Q0 for qemu-devel@nongnu.org; Tue, 20 Sep 2016 16:46:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmRvt-0007XM-KY for qemu-devel@nongnu.org; Tue, 20 Sep 2016 16:46:25 -0400 From: Eric Auger Date: Tue, 20 Sep 2016 20:45:52 +0000 Message-Id: <1474404352-28958-13-git-send-email-eric.auger@redhat.com> In-Reply-To: <1474404352-28958-1-git-send-email-eric.auger@redhat.com> References: <1474404352-28958-1-git-send-email-eric.auger@redhat.com> Subject: [Qemu-devel] [PATCH v2 12/12] vfio/pci: Handle host oversight List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: eric.auger@redhat.com, eric.auger.pro@gmail.com, qemu-devel@nongnu.org, alex.williamson@redhat.com, armbru@redhat.com In case the end-user calls qemu with -vfio-pci option without passing either sysfsdev or host property value, the device is interpreted as 0000:00:00.0. Let's create a specific error message to guide the end-user. Signed-off-by: Eric Auger --- hw/vfio/pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index f5ff14b..6a961bf 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2518,6 +2518,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) int i, ret; if (!vdev->vbasedev.sysfsdev) { + if (!(~vdev->host.domain || ~vdev->host.bus || + ~vdev->host.slot || ~vdev->host.function)) { + error_setg(errp, "No provided host device"); + error_append_hint(errp, "Use -vfio-pci,host=DDDD:BB:DD.F " + "or -vfio-pci,sysfsdev=PATH_TO_DEVICE\n"); + return; + } vdev->vbasedev.sysfsdev = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%01x", vdev->host.domain, vdev->host.bus, @@ -2829,6 +2836,10 @@ static void vfio_instance_init(Object *obj) device_add_bootindex_property(obj, &vdev->bootindex, "bootindex", NULL, &pci_dev->qdev, NULL); + vdev->host.domain = ~0U; + vdev->host.bus = ~0U; + vdev->host.slot = ~0U; + vdev->host.function = ~0U; } static Property vfio_pci_dev_properties[] = { -- 1.9.1