Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3744759pxk; Tue, 29 Sep 2020 05:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQKnKkEbqDyD92rGl/sDSB4s53pGb+cAv6Zetp2vNju9tVVm03853Rpa3A+p3ZugKH859n X-Received: by 2002:a05:6402:2c3:: with SMTP id b3mr2929004edx.213.1601382031783; Tue, 29 Sep 2020 05:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601382031; cv=none; d=google.com; s=arc-20160816; b=MxAnzLSXHQt5esa+8VfyBjAU0ytuWoD7CgqZ8EdssbgMhaumGWqMzBzOLBvd0/bukQ mcI8A4IAThuxQr8F3xg4Qbxma3bEyGhi7WHJFzvFSk9dfUAhH0bsSvVcjRsLqe6yFTaS 9xBQ/Gp7f+QPkA/2qwY4tQ6BvEG3NX6iTAoVi8L4EPwK8YmAVZXxpirQJzx3BBvnIO1T 4zrdW/EG6TdWWXHeIzmRznru5NEC5BC4+LDyh3//XqZRdJao3mHbMlBMg7DZMw6mPjG5 /mKXTx0UuK20DEYp8mDeIZKWYuCnTDCQyeL81/rux5L4VXX60MP6oabUYfSmirSFZI5x vSqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6ijsQdNWdPU5xbxmRl116BKxNtxdhX14isXg4qBVumo=; b=qmVC+opK7U7ZDwsHFHpz+si4wLoMDkZFBUkQXP25B+fh9qPUwJV1QkxsCHZ5KvCe5F nV9/2/dxYGVTrDGjRLtN9MKV8oba0KPgVTAvgFauHjvdw47JQSAz3zTtIpVmL4g0wBkX pyWlzGRJ24JgZFpLIIp8n4pKOqF+Cd1gB040G+Aq6tBonekTwrPYxaoYxvOePJvLfYj2 6bVycCRxY6nJrRKAoFtxGUu6KXVdvPmyG+rixa6wp7FuYRoAPLJVrIbEHw2hvdX9rbs8 KuNt3ONfEPaDJDrI3bXrQe8sdk3gH5HMExXciA605ZKfpANRy+/Nv8mGLSqKavuyVrsw 0N7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HjFzuu0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si2925813edq.546.2020.09.29.05.20.08; Tue, 29 Sep 2020 05:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HjFzuu0q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732164AbgI2MS1 (ORCPT + 99 others); Tue, 29 Sep 2020 08:18:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:55996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729974AbgI2LgV (ORCPT ); Tue, 29 Sep 2020 07:36:21 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C358023E24; Tue, 29 Sep 2020 11:31:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379095; bh=4dZeExV5m9YmaEEXt9XuEf/XrmsgGX7WgJ9Hprr9dkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HjFzuu0qyq1lhIp+xO3QvSh3At+G1X0Dt284cstdW0d/evbip7Hfw+B24jKcO+4FU DyQSMlipCQ9StPW7NvVNpQiDE6rvPhVhatdqd4Qu/VTKJteWDqc70SLls9EXATgIgv NHiXFcV7lyXFd7SKT3vovC3/unSFZns87Dhj1+8U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pierre=20Cr=C3=A9gut?= , Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.4 012/388] PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes Date: Tue, 29 Sep 2020 12:55:43 +0200 Message-Id: <20200929110011.081821667@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pierre Crégut [ Upstream commit 35ff867b76576e32f34c698ccd11343f7d616204 ] When sriov_numvfs is being updated, we call the driver->sriov_configure() function, which may enable VFs and call probe functions, which may make new devices visible. This all happens before before sriov_numvfs_store() updates sriov->num_VFs, so previously, concurrent sysfs reads of sriov_numvfs returned stale values. Serialize the sysfs read vs the write so the read returns the correct num_VFs value. [bhelgaas: hold device_lock instead of checking mutex_is_locked()] Link: https://bugzilla.kernel.org/show_bug.cgi?id=202991 Link: https://lore.kernel.org/r/20190911072736.32091-1-pierre.cregut@orange.com Signed-off-by: Pierre Crégut Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/iov.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index deec9f9e0b616..9c116cbaa95d8 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -253,8 +253,14 @@ static ssize_t sriov_numvfs_show(struct device *dev, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); + u16 num_vfs; + + /* Serialize vs sriov_numvfs_store() so readers see valid num_VFs */ + device_lock(&pdev->dev); + num_vfs = pdev->sriov->num_VFs; + device_unlock(&pdev->dev); - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); + return sprintf(buf, "%u\n", num_vfs); } /* -- 2.25.1