Received: by 10.223.185.116 with SMTP id b49csp5087314wrg; Tue, 27 Feb 2018 07:36:23 -0800 (PST) X-Google-Smtp-Source: AH8x2247K7NdCgAzurAezapmvGMycDZvxo23XyTGjtWhmzv08vgr7av5WseFmqahItpFLNBF+kEr X-Received: by 10.99.103.133 with SMTP id b127mr11487336pgc.155.1519745783096; Tue, 27 Feb 2018 07:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519745783; cv=none; d=google.com; s=arc-20160816; b=0SWpfaGdeF+MAx230gYw7EsSa2/78seruNgaKrHyvzz1Mz1joNBdnWE9wWNCGJMZdz m7wZvkGMMSkHhkL/fbhZL3dyNH8vADuvyE1f5ndChfrwNQmKy8f6lmOdAXpnjpAvKzU0 zqLGenoNwN0ehCFcf1bl/6rGhvt2IquLm3f6pjpTFlPD60zF5Io/L6XK0YlpImbne9aL iXdv/YzkOmC9soZlF6Ey4/ugICfcMgrG/y9B0D9HxjLSqRyzd7+csolFtuTDfR43rEKp ZX26M1k5Tbwsd3Za+cEvpesDOpTlY11OvRlnwXrOyxDObgAnq8fkPEd8V5Uwae1gKe6B oz7g== 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:mime-version :references:in-reply-to:from:subject:cc:to:message-id:date :arc-authentication-results; bh=TneppwY+/H4ae8K6Cc0FVSFAxptWWNV4JX4y+iLZxK8=; b=TLntTSj24a6cWK+YimJGIgJQbBXy3UOVWrqK5ARbTwbTOKffw3GGcL1opDCpLY4DcK Pd4DFITar7K9AsjoezlWmx1rV2noRsyXmHLnDlhPxDq9Jhz1lRHEsXK0IHgbFsG1em7u Ix2i47p8QyWoXX0ETSwjDUZIOtPbbakQYucZF2bK/AJlPFO0fJaxUDJWUUEenl8FjDCz iRdUEbGdMwjsub10uuCbgl5WsY8vQYwV7W5yPJIywZkyTejCFWP3JJxm/ni4/e2J7ZI6 aEDDxnx4P5B7nReKQBM4+tm4OwdJGBzONZYM2xwLRI0czAFE6jbJ9fVvviyQ1t6zIlUA l1eQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i67si5236062pfk.28.2018.02.27.07.36.08; Tue, 27 Feb 2018 07:36:23 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753656AbeB0PfJ (ORCPT + 99 others); Tue, 27 Feb 2018 10:35:09 -0500 Received: from shards.monkeyblade.net ([184.105.139.130]:56568 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752798AbeB0PfI (ORCPT ); Tue, 27 Feb 2018 10:35:08 -0500 Received: from localhost (67.110.78.66.ptr.us.xo.net [67.110.78.66]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 8E286142677E1; Tue, 27 Feb 2018 07:35:06 -0800 (PST) Date: Tue, 27 Feb 2018 10:35:02 -0500 (EST) Message-Id: <20180227.103502.2160088807348773566.davem@davemloft.net> To: mark.d.rustad@intel.com Cc: virtio-dev@lists.oasis-open.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, dan.daly@intel.com, alex.williamson@redhat.com, MRustad@gmail.com, alexander.duyck@gmail.com, mst@redhat.com Subject: Re: [RFC PATCH V3] virtio_pci: Add SR-IOV support From: David Miller In-Reply-To: <20180226031911.18980.80488.stgit@mdrustad-mac04.local> References: <20180226031911.18980.80488.stgit@mdrustad-mac04.local> X-Mailer: Mew version 6.7 on Emacs 25.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 27 Feb 2018 07:35:07 -0800 (PST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rustad Date: Sun, 25 Feb 2018 19:19:11 -0800 > diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c > index 677924ae0350..ddd44a9d93ec 100644 > --- a/drivers/pci/iov.c > +++ b/drivers/pci/iov.c > @@ -367,6 +367,54 @@ static void sriov_disable(struct pci_dev *dev) > pci_iov_set_numvfs(dev, 0); > } > > +/** > + * pci_sriov_disable - standard helper to disable SR-IOV > + * @dev:the PCI PF device whose VFs are to be disabled > + */ > +int pci_sriov_disable(struct pci_dev *dev) > +{ > + /* > + * If vfs are assigned we cannot shut down SR-IOV without causing > + * issues, so just leave the hardware available. > + */ > + if (pci_vfs_assigned(dev)) { > + pci_warn(&dev->dev, > + "Cannot disable SR-IOV while VFs are assigned - VFs will not be deallocated\n"); > + return -EPERM; > + } > + pci_disable_sriov(dev); > + return 0; > +} > + > +static int pci_sriov_enable(struct pci_dev *dev, int num_vfs) > +{ > + int rc; > + > + if (pci_num_vf(dev)) > + return -EINVAL; > + > + rc = pci_enable_sriov(dev, num_vfs); > + if (rc) { > + pci_warn(dev, "Failed to enable PCI sriov: %d\n", rc); > + return rc; > + } > + dev_info(dev, "SR-IOV enabled with %d VFs\n", num_vfs); > + return num_vfs; > +} I don't like these helpers on many different levels. The pci_num_vf() test in pci_sriov_enable() is redundant, the pci_enable_sriov() code path does that check and returns the same exact error code from sriov_enable(). Just call pci_enable_sriov() directly. The log message adds no value justifying an entirely new (and confusingly named) helper. If the log message is useful, add it to pci_enable_sriov(). Speaking of naming, is this stuff confusing or what? As a programmer what am I supposed to think when I consider what may be the difference between two interfaces, the only difference in naming is that two words are transposed? pci_enable_sriov() pci_sriov_enable() pci_disable_sriov() pci_sriov_disable() ?!?!?!?! As per pci_sriov_disable() explicitly, all it does different is check for vf assignment and return failure. If you want a little help that does that, name it appropriately. pci_disable_sriov_if_unassigned() So kill off pci_sriov_enable() helper completely, it is unnecessary, and rename the disable helper so that it says something meaningful to the reader. Thanks.