Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp885416pxk; Thu, 17 Sep 2020 20:18:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQOhqX9wic6gmGEJbP/7ZFDT4MPZwkZ+QsDMI6by4wPKvXltiyKEqrGwuVWGSmdsbLZguL X-Received: by 2002:a17:906:2681:: with SMTP id t1mr16863723ejc.474.1600399120643; Thu, 17 Sep 2020 20:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600399120; cv=none; d=google.com; s=arc-20160816; b=PddV/TgXGh4ZGe3VshEex3QMaW5CxA/fScI5Esmrd4rpLfVGKl4A3JnFAAFCI3alh/ MIum9MkoTYLSsTg/jVau1oL2kkVdC3AphZEDvodPmQSlpx7Zj7Wi7pCkbASVBld5NORq 7QeoFiiHgNCPwWEciPJXqOqc558euII8UIil+XqcSMv6v5fSsQzBlMS3YaXwBUZ+ZdxR McF0IuV7vzYIDTK/sWgMv4UtSptEbrivi5DpRy6hCRmSfJXxVzfDh56rZIMruaA0HbQq eG0vQZdK49VooWujdDZELIFlj4gHlDGiu0XfZRschCujpz3K0RLRyhdcGsZ7TbNIN2Pu gaiw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6ijsQdNWdPU5xbxmRl116BKxNtxdhX14isXg4qBVumo=; b=soNbXN52vfKSpJF3Z95EouCAI4Y5TJ9+Up+lv/D2qAjcfuQ/CzviXBIjUgenWx7J/Y 7oQk7DCSXkXYoTyFG/mcE69RGbGTBe2HgDAgCU3+tbAzLctvGcvIgzdWPbmWHcu11pm4 wHjLZKJqvhygxKxf0wHT69ZjOxZ1p1XJpCCeXsnjfsgjzqofyYGK0xsRXELYTsSbvhPy fBWrjODzYcWcRzbeGPtvpJrz4MqzTyAxYIEXKMahLuinEwjSTJXiKbmCl65NnX6IGopc GlNE9sxVoya+rvFj/zW1++hdFpJCtI5pyxsJc9OR6sdtmeFfAzfQaPwWplYjTzcifANC OGYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tsQt0YHo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ha18si1339553ejb.543.2020.09.17.20.18.17; Thu, 17 Sep 2020 20:18:40 -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=tsQt0YHo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730602AbgIRDP3 (ORCPT + 99 others); Thu, 17 Sep 2020 23:15:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:45806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726375AbgIRCB3 (ORCPT ); Thu, 17 Sep 2020 22:01:29 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7A682311D; Fri, 18 Sep 2020 02:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394487; bh=4dZeExV5m9YmaEEXt9XuEf/XrmsgGX7WgJ9Hprr9dkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsQt0YHosRtojE/1ptfYBfXYjAfV4hIzCFduwBUzTFfC5DY05yXPSFe4YTNkKmc23 uFscyjlllHsZqcKNaSuc2LFvIoeoY7OUFAB5oUd7GIx+qx16aJ0xBDc7TaCBQloIEF Mp2RqcPd/CwKb7ogqp67gMzVA4zqmYAeLTsql478= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Pierre=20Cr=C3=A9gut?= , Bjorn Helgaas , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 013/330] PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes Date: Thu, 17 Sep 2020 21:55:53 -0400 Message-Id: <20200918020110.2063155-13-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore 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