From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FAKE_REPLY_C,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C4B2ECE58D for ; Wed, 9 Oct 2019 12:31:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7752321929 for ; Wed, 9 Oct 2019 12:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570624298; bh=qJNqWYgUP04FWWOyhZUVfn25DZyG752Qo/ZuAv9t3z4=; h=Date:From:To:Cc:Subject:In-Reply-To:List-ID:From; b=EezjtLXxyfWEPZd1rz0yN0RC+/Nx2R3Qjf2XCysujuL7x/2rwJyS8YzGuBIRT6QY+ QRnhslmyFxfV48dHBfx7uFJE0J41Wf8jltyTqyJnc6iICNw5fnS2xEOvpXptO+s8c9 1VXgvVxS2DEgvNm0nTzcNCnoabUDhEI5ZUXhYO6g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730110AbfJIMbh (ORCPT ); Wed, 9 Oct 2019 08:31:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:45098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728200AbfJIMbh (ORCPT ); Wed, 9 Oct 2019 08:31:37 -0400 Received: from localhost (173-25-83-245.client.mchsi.com [173.25.83.245]) (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 750C1206C0; Wed, 9 Oct 2019 12:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570624296; bh=qJNqWYgUP04FWWOyhZUVfn25DZyG752Qo/ZuAv9t3z4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=X/2o/lHUYyW9dA4IpOQVPKDMvH3l27/o6Z66nGTPND3rmtqUV1O78exJmzZ8Gjm/S HOfqHqGyaed1ol3CEOaFIHLSZSIsLVKL3C9u8WLQhgGJp5Rq8wpjnJO+rhBBNxxhNA QtYKzn1Jyc3QBA0hDNZGCtjFXoYU/0wXzCW9ufus= Date: Wed, 9 Oct 2019 07:31:35 -0500 From: Bjorn Helgaas To: Don Dutile Cc: CREGUT Pierre IMT/OLN , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck , Jakub Kicinski Subject: Re: [PATCH] PCI/IOV: update num_VFs earlier Message-ID: <20191009123135.GA62790@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4ac38c7a-b8d4-9a1c-10ab-ce8b4cf2991f@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Tue, Oct 08, 2019 at 06:06:46PM -0400, Don Dutile wrote: > On 10/08/2019 05:38 PM, Bjorn Helgaas wrote: > > 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 > I hope not... see below > > > 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); > ^^^^^ lock > > > + num_vfs = pdev->sriov->num_VFs; > > > + device_lock(&pdev->dev); > ^^^^ and lock again! Oops, sorry, my fault. Fixed. > > > - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); > > > + return sprintf(buf, "%u\n", num_vfs); > > > } > > > /* >