Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2502imm; Thu, 20 Sep 2018 13:03:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbuBWVlJYpFwEYC43Dnnx21tm9o3GK0WxLFT46nxWOKTjeOHgE50x1yZ64wgfYLX++RvSfL X-Received: by 2002:a62:c4da:: with SMTP id h87-v6mr43012436pfk.39.1537473831030; Thu, 20 Sep 2018 13:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537473831; cv=none; d=google.com; s=arc-20160816; b=kKIziLnaS3+cGqThD9IKYer6n0n1Gx72EZWboD1iwJ8OOCnpfBGKHqorhlx4m2sLVY 89kJSrrJYIzyjh0spfdIm3+xDi1U7qC4GUwPWINPRpiQI377eDXgDbQtuhYYvzkCjHP5 GI4o3VBhkFSYNqyFy1ubkq9sY+1mGehGPmwQrctyw2Vk1bHNL1Ic55iSh3zw95+EINbp gc0Q2Rm2v7p1yAp6RcfLjvK157ASz6lCVF5hxcohqmZ0AtKZTasESRBqIZ/OqHN+MY3p 3qGPXEGIflvvDUeow8yb0XX4VakYJyauIIXCprIlu9p0P/Q1cZ70AeER8vnda+UNuB84 nhwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject; bh=NZIg0MzwfCWXQMzHvf7ZGd6Okg4xWeWT+v+zbVuJeMQ=; b=XhgG4JT0RFdNca0ZeDaMpe15BdhcPCCQ0Lis3p2YCOISoJHaFw1430CBcV/XfQjS40 Aky2ITulezZkr2q8mHyIrAk3CFweRoBaG42XI/7lDc9svYsDZ2q3riZ4ajWJQcgTzgM6 9ZoQ0hJzpkRgmZspZ3gJwtxFsvh8cCy6r25K2fRe1S+FyGoaRWLmXn8mvVSXoAhA3z+7 uk43FUdoLLb4GrKM2jb1se9o+w6nmmZMQv5/1VJIjSR7l7nYT3MbVayN3KAscj9Gx95t Nk2YAg8pJ5+pUTOtvYkeS97RYTu8MdE9virIBQ+bzYJWMS0ULIttVhJ1m43eLi+UFVKi Pl+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y67-v6si25454949pfa.47.2018.09.20.13.03.35; Thu, 20 Sep 2018 13:03:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388462AbeIUBsT (ORCPT + 99 others); Thu, 20 Sep 2018 21:48:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59582 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388196AbeIUBsS (ORCPT ); Thu, 20 Sep 2018 21:48:18 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55F9E88312; Thu, 20 Sep 2018 20:03:10 +0000 (UTC) Received: from gimli.home (ovpn-116-77.phx2.redhat.com [10.3.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47FEF106A785; Thu, 20 Sep 2018 20:03:07 +0000 (UTC) Subject: [PATCH v2] vfio/pci: Mask buggy SR-IOV VF INTx support From: Alex Williamson To: kvm@vger.kernel.org, ashok.raj@intel.com, gage.eads@intel.com Cc: gnomes@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org Date: Thu, 20 Sep 2018 14:03:06 -0600 Message-ID: <153747346143.7344.14634545723456004489.stgit@gimli.home> User-Agent: StGit/0.18-136-gffd7-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Sep 2018 20:03:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SR-IOV spec requires that VFs must report zero for the INTx pin register as VFs are precluded from INTx support. It's much easier for the host kernel to understand whether a device is a VF and therefore whether a non-zero pin register value is bogus than it is to do the same in userspace. Override the INTx count for such devices and virtualize the pin register to provide a consistent view of the device to the user. As this is clearly a spec violation, warn about it to support hardware validation, but also provide a known whitelist as it doesn't do much good to continue complaining if the hardware vendor doesn't plan to fix it. Known devices with this issue: 8086:270c Signed-off-by: Alex Williamson --- v2: Moved the warning to vfio_config_init(), so it triggers on device open and no longer depends on the user looking at the number of INTx IRQs available. Also changed from dev_warn_once() to pci_warn() as this new location seems sufficiently low frequency to nag repeatedly. Please test. Thanks, Alex drivers/vfio/pci/vfio_pci.c | 8 ++++++-- drivers/vfio/pci/vfio_pci_config.c | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index cddb453a1ba5..50cdedfca9fe 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -434,10 +434,14 @@ static int vfio_pci_get_irq_count(struct vfio_pci_device *vdev, int irq_type) { if (irq_type == VFIO_PCI_INTX_IRQ_INDEX) { u8 pin; + + if (!IS_ENABLED(CONFIG_VFIO_PCI_INTX) || + vdev->nointx || vdev->pdev->is_virtfn) + return 0; + pci_read_config_byte(vdev->pdev, PCI_INTERRUPT_PIN, &pin); - if (IS_ENABLED(CONFIG_VFIO_PCI_INTX) && !vdev->nointx && pin) - return 1; + return pin ? 1 : 0; } else if (irq_type == VFIO_PCI_MSI_IRQ_INDEX) { u8 pos; u16 flags; diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 62023b4a373b..423ea1f98441 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -1611,6 +1611,15 @@ static int vfio_ecap_init(struct vfio_pci_device *vdev) return 0; } +/* + * Nag about hardware bugs, hopefully to have vendors fix them, but at least + * to collect a list of dependencies for the VF INTx pin quirk below. + */ +static const struct pci_device_id known_bogus_vf_intx_pin[] = { + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x270c) }, + {} +}; + /* * For each device we allocate a pci_config_map that indicates the * capability occupying each dword and thus the struct perm_bits we @@ -1676,6 +1685,24 @@ int vfio_config_init(struct vfio_pci_device *vdev) if (pdev->is_virtfn) { *(__le16 *)&vconfig[PCI_VENDOR_ID] = cpu_to_le16(pdev->vendor); *(__le16 *)&vconfig[PCI_DEVICE_ID] = cpu_to_le16(pdev->device); + + /* + * Per SR-IOV spec rev 1.1, 3.4.1.18 the interrupt pin register + * does not apply to VFs and VFs must implement this register + * as read-only with value zero. Userspace is not readily able + * to identify whether a device is a VF and thus that the pin + * definition on the device is bogus should it violate this + * requirement. We already virtualize the pin register for + * other purposes, so we simply need to replace the bogus value + * and consider VFs when we determine INTx IRQ count. + */ + if (vconfig[PCI_INTERRUPT_PIN] && + !pci_match_id(known_bogus_vf_intx_pin, pdev)) + pci_warn(pdev, + "Hardware bug: VF reports bogus INTx pin %d\n", + vconfig[PCI_INTERRUPT_PIN]); + + vconfig[PCI_INTERRUPT_PIN] = 0; /* Gratuitous for good VFs */ } if (!IS_ENABLED(CONFIG_VFIO_PCI_INTX) || vdev->nointx)