From patchwork Mon May 22 22:50:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 9741517 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 B109E60388 for ; Mon, 22 May 2017 22:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A275628765 for ; Mon, 22 May 2017 22:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96DBA28772; Mon, 22 May 2017 22:50:37 +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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham 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 B3FC228765 for ; Mon, 22 May 2017 22:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760436AbdEVWuf (ORCPT ); Mon, 22 May 2017 18:50:35 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:35903 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758556AbdEVWue (ORCPT ); Mon, 22 May 2017 18:50:34 -0400 Received: by mail-pf0-f177.google.com with SMTP id m17so95318148pfg.3 for ; Mon, 22 May 2017 15:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=rY4fYcoKFkN/HMT+i7jfg3c3mWNYcd/kOQOcbR9rPuA=; b=IiIClnrch+ihUVAfpPm8bskjp12RX8AUKa24E0bkPkhlcfFga+2sGHRM/F3XgFTskB 6TmDxcaGIU+1+cbxq4wCXBhsx36ItZYMqmvPLFkGTBQEIWOpO9qNnh31L7RB3t/NGT14 X8gvwJ0iegmrqX2kwK/GYpVdEnZY0l5L3x1FDmXd51YaJJhdg/6aENnTNP6zrnFHVgcf 4F+H0DBfn1ZGhK2XFKAXd7IQOAjtvEt8HITG37Lj2VizdPDxXFJm/ROd7kuCGa/YEh9W Sa4zcq2Meeg0UINVVpPDD1z5vZc/HPORqffdLw0F+rwkNJr+3d/N8L5jxI3aRG09lh3x fM7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rY4fYcoKFkN/HMT+i7jfg3c3mWNYcd/kOQOcbR9rPuA=; b=WYvC/YAaaVbrvbY+T61jVl1Yg4Fq0EY1JruVk9a2TV07KdPLo0EEF0T03yMkbENbHK bEvlp1MpVg8JSx9szxjsw45NSUqncZ7y/wn3Qjm907AY+ZpCNQSPVC3MbGGFUKVJioq/ YofMbOZWtigG1wyPJixEadTKyhZ3tlo0AAzCivqFvzmkNnw0zR2c0EDplpKvzBxyy/nt G2jLgROhWyb1GT8pQb8z4NKzUlkHh36A+Aayghltn3xCubZ4JDm3tjr8++ICB1ijZoiS 5dLULGEUals2sjWfjEzhv/6e5qCZSfSLzgNkRE27pcjvhsQYdZE4kbETJWPToL7y0FF+ QCpg== X-Gm-Message-State: AODbwcAQTn6OVwM4rlMwERtXxHxEgMyAldvsyvaObcOLHF1Adtd3F7ws Q8qyghMhJ4JU0Sx1 X-Received: by 10.98.100.207 with SMTP id y198mr28194815pfb.139.1495493433882; Mon, 22 May 2017 15:50:33 -0700 (PDT) Received: from jkicinski-Precision-T1700.netronome.com ([75.53.12.129]) by smtp.gmail.com with ESMTPSA id k86sm34299001pfk.125.2017.05.22.15.50.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 May 2017 15:50:33 -0700 (PDT) From: Jakub Kicinski To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Emil Tantilov , Alexander Duyck , oss-drivers@netronome.com, Jakub Kicinski Subject: [PATCH] pci: iov: use device lock to protect IOV sysfs accesses Date: Mon, 22 May 2017 15:50:23 -0700 Message-Id: <20170522225023.14010-1-jakub.kicinski@netronome.com> X-Mailer: git-send-email 2.11.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 PCI core sets the driver pointer before calling ->probe() and only clears it after ->remove(). This means driver's ->sriov_configure() callback will happily race with probe() and remove(), most likely leading to BUGs, since drivers don't expect this. We could reorder pointer assignments, or try detecting races in all drivers, but it seems simpler and cleaner to just hold the device lock instead of special SR-IOV lock, since that lock is already supposed to synchronize the driver callbacks. Remove the iov lock completely, since we remove the last user. Signed-off-by: Jakub Kicinski Reviewed-by: Christoph Hellwig --- drivers/pci/iov.c | 4 ---- drivers/pci/pci-sysfs.c | 5 ++--- drivers/pci/pci.h | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index d9dc7363ac77..120485d6f352 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -461,8 +461,6 @@ static int sriov_init(struct pci_dev *dev, int pos) else iov->dev = dev; - mutex_init(&iov->lock); - dev->sriov = iov; dev->is_physfn = 1; rc = compute_max_vf_buses(dev); @@ -491,8 +489,6 @@ static void sriov_release(struct pci_dev *dev) if (dev != dev->sriov->dev) pci_dev_put(dev->sriov->dev); - mutex_destroy(&dev->sriov->lock); - kfree(dev->sriov); dev->sriov = NULL; } diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 31e99613a12e..7755559558df 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -472,7 +472,6 @@ 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; @@ -483,7 +482,7 @@ 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); + device_lock(&pdev->dev); if (num_vfs == pdev->sriov->num_VFs) goto exit; @@ -518,7 +517,7 @@ static ssize_t sriov_numvfs_store(struct device *dev, num_vfs, ret); exit: - mutex_unlock(&iov->dev->sriov->lock); + device_unlock(&pdev->dev); if (ret < 0) return ret; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index f8113e5b9812..93f4044b8f4b 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -272,7 +272,6 @@ struct pci_sriov { u16 driver_max_VFs; /* max num VFs driver supports */ struct pci_dev *dev; /* lowest numbered PF */ struct pci_dev *self; /* this PF */ - struct mutex lock; /* lock for setting sriov_numvfs in sysfs */ resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ bool drivers_autoprobe; /* auto probing of VFs by driver */ };