From patchwork Sat Mar 25 16:18:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 95986 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp532169qgd; Sat, 25 Mar 2017 09:19:23 -0700 (PDT) X-Received: by 10.99.103.133 with SMTP id b127mr15441737pgc.29.1490458763780; Sat, 25 Mar 2017 09:19:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3si6723034pli.62.2017.03.25.09.19.23; Sat, 25 Mar 2017 09:19:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751344AbdCYQTX (ORCPT + 5 others); Sat, 25 Mar 2017 12:19:23 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:35251 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751309AbdCYQTX (ORCPT ); Sat, 25 Mar 2017 12:19:23 -0400 Received: by mail-pf0-f170.google.com with SMTP id 20so7967199pfk.2 for ; Sat, 25 Mar 2017 09:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tCJgzT8thrFblqINa63Jp71LYcx4lHGWafqBVNird9U=; b=gtqzr93hza+YuoRSVgbrUZl8kyncl70KGaB2Hw11wDQ6HysYt3it/HqTuZ6D3V64yx McwKLzQM7OzZHxibaSmUr4uTpPy2ZmnFC0cLSKm0I8JUygK/Xw+Idw4yGSb/JuxXpXU4 LPKbbtlFcz7xo7UkYYqGx5KlzmbcF98xDSUvM= 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:in-reply-to :references; bh=tCJgzT8thrFblqINa63Jp71LYcx4lHGWafqBVNird9U=; b=Ryv5b/gq6++axyF8cmWdNNbpFUKR9VfuAZ785Ric04rvvpM6zdHmitEs73XzF0Wshk oIxQvb9GkbU6DkZZ/IKTs6lJkzzTpNYexT5z1OFsqAgqAapJ86LUxTqWo+OQCeiF8Tze F3Jbiq0daX0ePKOV7x3r2TVoNj6wzmqJ/7u1++pZU4yxzmdLt74+5FTo7ogbwiOHiRt0 tbr+yjruzwudxyAb/kko072qDuBeiL37780XibD/pWJBomWQo3VbwtneGyD3lFIlMSV+ PcYOsxNU269wT7L0UCoHtD78LBa51l6X2DcTuo3N2JBDqwdp4OfrCbPU0BHJ69y/l+Tw ESBg== X-Gm-Message-State: AFeK/H1pMAKlKhvjDOi7GI9kN9IeCmS9Lu308br06hH6XLoQC7qDtPLtfXFqjbF59k4DmQQW X-Received: by 10.84.173.4 with SMTP id o4mr18493469plb.106.1490458761859; Sat, 25 Mar 2017 09:19:21 -0700 (PDT) Received: from phantom.lan ([106.51.225.38]) by smtp.gmail.com with ESMTPSA id q194sm11469541pfq.43.2017.03.25.09.19.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Mar 2017 09:19:20 -0700 (PDT) From: Sumit Semwal To: stable@vger.kernel.org Cc: Bjorn Helgaas , Sasha Levin , Greg Kroah-Hartman , Sumit Semwal Subject: [PATCH for-4.4 09/19] PCI: Don't update VF BARs while VF memory space is enabled Date: Sat, 25 Mar 2017 21:48:09 +0530 Message-Id: <1490458699-24484-10-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> References: <1490458699-24484-1-git-send-email-sumit.semwal@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bjorn Helgaas [ Upstream commit 546ba9f8f22f71b0202b6ba8967be5cc6dae4e21 ] If we update a VF BAR while it's enabled, there are two potential problems: 1) Any driver that's using the VF has a cached BAR value that is stale after the update, and 2) We can't update 64-bit BARs atomically, so the intermediate state (new lower dword with old upper dword) may conflict with another device, and an access by a driver unrelated to the VF may cause a bus error. Warn about attempts to update VF BARs while they are enabled. This is a programming error, so use dev_WARN() to get a backtrace. Signed-off-by: Bjorn Helgaas Reviewed-by: Gavin Shan Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sumit Semwal --- drivers/pci/iov.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 2f8ea6f..47c46d0 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -567,6 +567,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno) struct resource *res = dev->resource + resno; int vf_bar = resno - PCI_IOV_RESOURCES; struct pci_bus_region region; + u16 cmd; u32 new; int reg; @@ -578,6 +579,13 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno) if (!iov) return; + pci_read_config_word(dev, iov->pos + PCI_SRIOV_CTRL, &cmd); + if ((cmd & PCI_SRIOV_CTRL_VFE) && (cmd & PCI_SRIOV_CTRL_MSE)) { + dev_WARN(&dev->dev, "can't update enabled VF BAR%d %pR\n", + vf_bar, res); + return; + } + /* * Ignore unimplemented BARs, unused resource slots for 64-bit * BARs, and non-movable resources, e.g., those described via