Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp93363ybp; Tue, 8 Oct 2019 14:39:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzOPuOoUobi2UHfDO2v3EQB0CVBHi7NQYgyMF0spijZlY9w8TpbfIYB7AQqPA5vr6S2sNo X-Received: by 2002:a17:906:6897:: with SMTP id n23mr2395057ejr.222.1570570751372; Tue, 08 Oct 2019 14:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570570751; cv=none; d=google.com; s=arc-20160816; b=qA2b1FL+B4YKHpOUaoU1AuX1oyQbGW+g/Ju7Vpw79PfV3LfNV5ACUv4HVC5giuiBLG hT5ev0uqDCAOSmGAPOFqq11uZE9eGvFTB7z67wKA1jKY4Cslv0phmZoJz2B4wsF+Yrma pX1EqynEkisOQfUSENFX0ggu4hOMrIqvw6kP1loNbZXVaEf8xaR94lvjG4Gh+zQIwh32 8IFv4fFCd28hVLjhUzXuNgTMtfQXLyXYf3Puu1rTMEa/gmfbJehNaYWxb0DJHWey83wb 9hu8OI2mZ2eYz41Z/d7ZQmdWXvew5iEiKWqzzLAnx3Xjd4UgJ7Vtz1423WFZ2DBOx9WG WU8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=o95FoGD+0cz1wcE4SAcUuzrEHd5i6a+CP2HHFyY1JAM=; b=UXxLYY4atDP1U3js0ItzxFe3yGyp+xGJahnqOGp5tDC1fN9lP+fowAVGiHPpUGWLUD hblu4KgoR4oV1aySLQJvlWTWN4/hE/xUS/F3BJMNjGGVzo5UXpYjHpmq6NG8vO9AAvnT Gcp9hxFBpabOXkLXe70trMYRG0+L8wwj4+HznJE34Dw0v137olf6Fra2TcOFPzj/5Xou 9uJfC15YGWvoLPOJaScpCSOujI6dUe4WjHKq88cWcmk+2t7MW4zmd5B2BXJWCeJmqadY i/sJoQBsileMrE/Q5vN0V3ttkzrYBRk8FNu0qfOi1e36GNOfAG03X2TOS8kwKYaUVKya C7Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vdS3XsDJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u12si85708ejt.21.2019.10.08.14.38.47; Tue, 08 Oct 2019 14:39:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=vdS3XsDJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730135AbfJHVik (ORCPT + 99 others); Tue, 8 Oct 2019 17:38:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:58156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727570AbfJHVik (ORCPT ); Tue, 8 Oct 2019 17:38:40 -0400 Received: from localhost (unknown [69.71.4.100]) (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 A2BB32070B; Tue, 8 Oct 2019 21:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570570719; bh=11TBIQmvDjjaIrom74PlC3QwYOcWo8Yzh1UnY6FDcXM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=vdS3XsDJMxwTYD7JXt7NUIntQHVBVRlNiQi5xBv/fgLTIFcGeDhw+C0HfNW4Wjwh7 e+5qQwwp5LH8xUShakUgnUp7sCPg45gIVCt6ehJz+iXM6t+iqJVkhY+7zczyZ6lYul hBlMiNvw4LndkopNyp9a7E1JajpgAU8UTqbUqXNQ= Date: Tue, 8 Oct 2019 16:38:35 -0500 From: Bjorn Helgaas To: CREGUT Pierre IMT/OLN Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Donald Dutile , Alexander Duyck , Jakub Kicinski Subject: Re: [PATCH] PCI/IOV: update num_VFs earlier Message-ID: <20191008213835.GA230403@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191003221007.GA209602@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 03, 2019 at 05:10:07PM -0500, Bjorn Helgaas wrote: > On Thu, Oct 03, 2019 at 11:04:45AM +0200, CREGUT Pierre IMT/OLN wrote: > > ... > > NIC drivers send netlink events when their state change, but it is > > the core that changes the value of num_vfs. So I would think it is > > the core responsibility to make sure the exposed value makes sense > > and it would be better to ignore the details of the driver > > implementation. > > Yes, I think you're right. And I like your previous suggestion of > just locking the device in the reader. I'm not enough of a sysfs > expert to know if there's a good reason to avoid a lock there. Does > the following look reasonable to you? I applied the patch below to pci/virtualization for v5.5, thanks for your great patience! > commit 0940fc95da45 > Author: Pierre Cr?gut > Date: Wed Sep 11 09:27:36 2019 +0200 > > PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes > > When sriov_numvfs is being updated, drivers may notify about new devices > before they are reflected in sriov->num_VFs, so concurrent sysfs reads > previously returned stale values. > > Serialize the sysfs read vs the write so the read returns the correct > num_VFs value. > > 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 > > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c > index b3f972e8cfed..e77562aabbae 100644 > --- a/drivers/pci/iov.c > +++ b/drivers/pci/iov.c > @@ -254,8 +254,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_lock(&pdev->dev); > > - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); > + return sprintf(buf, "%u\n", num_vfs); > } > > /*