From patchwork Wed Jan 4 00:48:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Tantilov X-Patchwork-Id: 9495971 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C4214606DD for ; Wed, 4 Jan 2017 00:57:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2C032787C for ; Wed, 4 Jan 2017 00:57:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7C63277D9; Wed, 4 Jan 2017 00:57:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58F192787C for ; Wed, 4 Jan 2017 00:57:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967086AbdADA5P (ORCPT ); Tue, 3 Jan 2017 19:57:15 -0500 Received: from mga05.intel.com ([192.55.52.43]:2843 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967097AbdADA5G (ORCPT ); Tue, 3 Jan 2017 19:57:06 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP; 03 Jan 2017 16:57:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,457,1477983600"; d="scan'208";a="49782489" Received: from estantil-desk3.jf.intel.com (HELO localhost6.localdomain6) ([134.134.3.64]) by fmsmga006.fm.intel.com with ESMTP; 03 Jan 2017 16:57:05 -0800 Subject: [PATCH 2/2] PCI: lock each enable/disable num_vfs operation in sysfs From: Emil Tantilov To: linux-pci@vger.kernel.org, intel-wired-lan@lists.osuosl.org Cc: alexander.h.duyck@intel.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 03 Jan 2017 16:48:31 -0800 Message-ID: <20170104004831.17866.11537.stgit@localhost6.localdomain6> In-Reply-To: <20170104004826.17866.77074.stgit@localhost6.localdomain6> References: <20170104004826.17866.77074.stgit@localhost6.localdomain6> User-Agent: StGit/0.17.1-17-ge4e0 MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enabling/disabling SRIOV via sysfs by echo-ing multiple values simultaneously: echo 63 > /sys/class/net/ethX/device/sriov_numvfs& echo 63 > /sys/class/net/ethX/device/sriov_numvfs sleep 5 echo 0 > /sys/class/net/ethX/device/sriov_numvfs& echo 0 > /sys/class/net/ethX/device/sriov_numvfs Results in the following bug: kernel BUG at drivers/pci/iov.c:495! invalid opcode: 0000 [#1] SMP CPU: 1 PID: 8050 Comm: bash Tainted: G W 4.9.0-rc7-net-next #2092 RIP: 0010:[] [] pci_iov_release+0x57/0x60 Call Trace: [] pci_release_dev+0x26/0x70 [] device_release+0x3e/0xb0 [] kobject_cleanup+0x67/0x180 [] kobject_put+0x2d/0x60 [] put_device+0x17/0x20 [] pci_dev_put+0x1a/0x20 [] pci_get_dev_by_id+0x5b/0x90 [] pci_get_subsys+0x35/0x40 [] pci_get_device+0x18/0x20 [] pci_get_domain_bus_and_slot+0x2b/0x60 [] pci_iov_remove_virtfn+0x57/0x180 [] pci_disable_sriov+0x65/0x140 [] ixgbe_disable_sriov+0xc7/0x1d0 [ixgbe] [] ixgbe_pci_sriov_configure+0x3d/0x170 [ixgbe] [] sriov_numvfs_store+0xdc/0x130 ... RIP [] pci_iov_release+0x57/0x60 Use the existing mutex lock to protect each enable/disable operation. CC: Alexander Duyck Signed-off-by: Emil Tantilov --- drivers/pci/pci-sysfs.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" 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/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 0666287..5b54cf5 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -472,7 +472,9 @@ static ssize_t sriov_numvfs_store(struct device *dev, const char *buf, size_t count) { struct pci_dev *pdev = to_pci_dev(dev); + struct pci_sriov *iov = pdev->sriov; int ret; + u16 num_vfs; ret = kstrtou16(buf, 0, &num_vfs); @@ -482,38 +484,46 @@ static ssize_t sriov_numvfs_store(struct device *dev, if (num_vfs > pci_sriov_get_totalvfs(pdev)) return -ERANGE; + mutex_lock(&iov->dev->sriov->lock); + if (num_vfs == pdev->sriov->num_VFs) - return count; /* no change */ + goto exit; /* is PF driver loaded w/callback */ if (!pdev->driver || !pdev->driver->sriov_configure) { dev_info(&pdev->dev, "Driver doesn't support SRIOV configuration via sysfs\n"); - return -ENOSYS; + ret = -EINVAL; + goto exit; } if (num_vfs == 0) { /* disable VFs */ ret = pdev->driver->sriov_configure(pdev, 0); - if (ret < 0) - return ret; - return count; + goto exit; } /* enable VFs */ if (pdev->sriov->num_VFs) { dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n", pdev->sriov->num_VFs, num_vfs); - return -EBUSY; + ret = -EBUSY; + goto exit; } ret = pdev->driver->sriov_configure(pdev, num_vfs); if (ret < 0) - return ret; + goto exit; if (ret != num_vfs) dev_warn(&pdev->dev, "%d VFs requested; only %d enabled\n", num_vfs, ret); +exit: + mutex_unlock(&iov->dev->sriov->lock); + + if (ret < 0) + return ret; + return count; }