From patchwork Thu Mar 17 19:29:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 642051 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2HJTuqP030736 for ; Thu, 17 Mar 2011 19:29:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753726Ab1CQT3x (ORCPT ); Thu, 17 Mar 2011 15:29:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2819 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751572Ab1CQT3x (ORCPT ); Thu, 17 Mar 2011 15:29:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2HJTn1I011931 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Mar 2011 15:29:49 -0400 Received: from s20.home (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2HJTn5v019760; Thu, 17 Mar 2011 15:29:49 -0400 From: Alex Williamson Subject: [PATCH] device-assignment: Reset device on system reset To: kvm@vger.kernel.org Cc: alex.williamson@redhat.com, ddutile@redhat.com, chrisw@redhat.com, bernhard.kohl@nsn.com Date: Thu, 17 Mar 2011 13:29:48 -0600 Message-ID: <20110317192923.24889.79288.stgit@s20.home> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 17 Mar 2011 19:30:05 +0000 (UTC) diff --git a/hw/device-assignment.c b/hw/device-assignment.c index db82e73..f1c2a3c 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1693,13 +1693,33 @@ static const VMStateDescription vmstate_assigned_device = { static void reset_assigned_device(DeviceState *dev) { - PCIDevice *d = DO_UPCAST(PCIDevice, qdev, dev); + PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev); + AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev); + char reset_file[64]; + const char reset[] = "1"; + int fd, ret; + + snprintf(reset_file, sizeof(reset_file), + "/sys/bus/pci/devices/0000:%02x:%02x.%01x/reset", + adev->host.bus, adev->host.dev, adev->host.func); + + /* + * Issue a device reset via pci-sysfs. Note that we use write(2) here + * and ignore the return value because some kernels have a bug that + * returns 0 rather than bytes written on success, sending us into an + * infinite retry loop using other write mechanisms. + */ + fd = open(reset_file, O_WRONLY); + if (fd != -1) { + ret = write(fd, reset, strlen(reset)); + close(fd); + } /* * When a 0 is written to the command register, the device is logically * disconnected from the PCI bus. This avoids further DMA transfers. */ - assigned_dev_pci_write_config(d, PCI_COMMAND, 0, 2); + assigned_dev_pci_write_config(pci_dev, PCI_COMMAND, 0, 2); } static int assigned_initfn(struct PCIDevice *pci_dev)