From patchwork Mon Jun 6 21:30:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 853972 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p56LWLNU025164 for ; Mon, 6 Jun 2011 21:32:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752801Ab1FFVcS (ORCPT ); Mon, 6 Jun 2011 17:32:18 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:56134 "EHLO fmmailgate03.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752500Ab1FFVcS (ORCPT ); Mon, 6 Jun 2011 17:32:18 -0400 Received: from smtp01.web.de ( [172.20.0.243]) by fmmailgate03.web.de (Postfix) with ESMTP id 6D68219192EEF; Mon, 6 Jun 2011 23:30:56 +0200 (CEST) Received: from [88.64.11.205] (helo=mchn199C.mchp.siemens.de) by smtp01.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1QThNw-0003Gz-00; Mon, 06 Jun 2011 23:30:56 +0200 Message-ID: <4DED470F.4020203@web.de> Date: Mon, 06 Jun 2011 23:30:55 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity , Marcelo Tosatti CC: kvm , Alex Williamson Subject: [PATCH] pci-assign: Do not reset the device unless the kernel supports it X-Enigmail-Version: 1.1.2 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX197rQnJmdSk5uW97RSwrwsYls8TryQRcL4DUbCH 3P+RlLFqYE7DpESbTSc1AywIDMLeaI9tW6F/HBsVK20gHTqxvO YbAsloBC4= 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 (demeter2.kernel.org [140.211.167.43]); Mon, 06 Jun 2011 21:32:21 +0000 (UTC) From: Jan Kiszka At least kernels 2.6.38 and 2.6.39 do not properly support issuing a reset on an assigned device and corrupt its config space. Prevent this by checking for a host kernel with the required support, tagged by the to-be-introduced KVM_CAP_DEVICE_RESET. Signed-off-by: Jan Kiszka --- PS: What's the state of those KVM patches? Will they make it into 3.0? hw/device-assignment.c | 33 +++++++++++++++++++-------------- 1 files changed, 19 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 57d8dc0..97a1450 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -1689,26 +1689,31 @@ static const VMStateDescription vmstate_assigned_device = { static void reset_assigned_device(DeviceState *dev) { PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev); +#ifdef KVM_CAP_DEVICE_RESET 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/%04x:%02x:%02x.%01x/reset", - adev->host.seg, 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); + if (kvm_check_extension(kvm_state, KVM_CAP_DEVICE_RESET) { + snprintf(reset_file, sizeof(reset_file), + "/sys/bus/pci/devices/%04x:%02x:%02x.%01x/reset", + adev->host.seg, 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); + } } +#endif /* KVM_CAP_DEVICE_RESET */ /* * When a 0 is written to the command register, the device is logically