Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp992221ybp; Wed, 9 Oct 2019 07:21:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWzKaYOL5bNaxKbpn1+1Xfz0lj9z9h7oCJjhO2gqf9zE0sQWDTbsMurVOIhrK96VMzvE5L X-Received: by 2002:a17:906:684:: with SMTP id u4mr2960671ejb.155.1570630901991; Wed, 09 Oct 2019 07:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570630901; cv=none; d=google.com; s=arc-20160816; b=x9+3+bM49aI0gQhyZFXv8e+ADozb10q05ZzoBbN1xi0T7ZUOJJMfirI+GnRx/vz7xu AI86PUMzJSD8Ulcq+24lyXs33rV0xBq1nP1ZYE6gKsn1RIk3DjjjWThwyDzQBcb1r/Dc rENDSZs1ekoKQG0D3JWoNZVbL7RzLcMQj/lks6RKYoNasv1W9rab62Lii29UGRe0ukgO DVSfbZ+vNeqLQPvY9tBtxtGEMIukNmFQidJPqBGOG6Da5wKb61nXBPL2ztU2XGTQfhsA xYblb/7oWtvAOerap54rmwxXJN78aTN2lWFmX2LIuUh2R9ZBwmZ81vS+WIs6xlTv52r8 ci8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=RMNbDesB++eMdv7OnMzI5GK5ooQR+y5R0iejWdD+cbQ=; b=fC3M3hBtlLGxsCDa64KfmYDD5G6AUfShiY1m1xT3eVWYLiPzIKR7L8i4ODy13f616z iorkZ1LxSH45BYiJ4dlhLHt4yvVGyKjM+XB2tFoveT9AnaF5KUkno2pFSh1w0jD7FOcG qMpV2evwmp9krSHejnzCuPAN6UQPb0YOm5+Qt0GnXl6ufbpldVidCZMJdv3RL0I52MYE wziLVxvi88CrlkeQ7TkJET8VtAF3xX6T8U24HWYCPj7xONN67DAGq6dCJdJRL8FSEQcQ xzTGBtrnEmR3JTLF9uo8vtRDCQt54MgHdYrgAqfXwXp0SbarlD8sA6lgKxyKOcjSxd2o wjBQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g24si1158515ejo.355.2019.10.09.07.21.17; Wed, 09 Oct 2019 07:21:41 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731345AbfJIOUf (ORCPT + 99 others); Wed, 9 Oct 2019 10:20:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4776 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbfJIOUf (ORCPT ); Wed, 9 Oct 2019 10:20:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3406C307DA31; Wed, 9 Oct 2019 14:20:35 +0000 (UTC) Received: from [10.3.117.216] (ovpn-117-216.phx2.redhat.com [10.3.117.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 577DE601AC; Wed, 9 Oct 2019 14:20:34 +0000 (UTC) Subject: Re: [PATCH] PCI/IOV: update num_VFs earlier To: Bjorn Helgaas Cc: CREGUT Pierre IMT/OLN , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Duyck , Jakub Kicinski References: <20191009123135.GA62790@google.com> From: Don Dutile Message-ID: <4b08c218-790b-2f26-a5a0-b66a4d4e67e9@redhat.com> Date: Wed, 9 Oct 2019 10:20:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20191009123135.GA62790@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 09 Oct 2019 14:20:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/09/2019 08:31 AM, Bjorn Helgaas wrote: > 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. > Thanks. --dd >>>> - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); >>>> + return sprintf(buf, "%u\n", num_vfs); >>>> } >>>> /* >>