Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4643329imm; Wed, 30 May 2018 09:13:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKAajtTH/Tep22heoUzoCWjWjkQoaAs/SBPJvcvfcJc+vO6ifYo9V0B+leyckVrQNy/R3X6 X-Received: by 2002:a62:6c3:: with SMTP id 186-v6mr3317804pfg.151.1527696781789; Wed, 30 May 2018 09:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527696781; cv=none; d=google.com; s=arc-20160816; b=ZLe1fHdQLGExNg/XlLgqjF52B+x8QQeUzos7v0rTlDg0cHeIb2czwkerHCf6ZjdI+d /0I0qtwU2L9tedQAt+iLanc/IE1kjbGEJpyRyYXx91ovyZh0WOS2Ph3V6sWB8iiKHgSM kyP81lh41xFyH4gnn4Fw2VzwSivnLRpZTNBFwa3z5KCIpz5T47vUr8WgMDr2R3tXu/bk 3L5LOfkYOzmBc1/KTkmFpIKQCf8aMMU6WCvWwf0Y3eFNhTkCnEM587glEANu1vGmkZt3 w1mznFU3VEpyWxvUiqCI7pTFjLM7LfWEyU9YeBeLxmPO9ppX/i8AWtEQwPK8PS8vhdq+ L85A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=QGNb2vOJ0pNtfyqJvXC9vVGE9fLuLfee4hMk2TPX+yA=; b=tEmkUk7NBO3L6Al6dT5P21u6x1R6G5h3c7q5u6ijZRJf3t9kug7+x9B5P5h9rBA7Lk uFVYvWsc1xe7l0bVLvTzEX6fW5Vbnl8rkN4kw6UI0GdlReoqe+IOFduK40w08QDdztPa riIdp9OSTGfmRzLArI/U6Vw9oiWxwdsOxshusEi+HihTyWikXqDwKiOdv2jbWmEUu/OV R/wmhB3azB41B/G1T7mV7PCL+xVJA8P76ybcSXPLnHAALmO89qSXPDRP+zKqQoTsfNBD aKGQFV90yHB5i6EbgCtuaYWUWaFu03VaRtrnbG4FvkZsVTiAWu9s7mkT4B86fcbTQlM6 ZXWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hcK4S4eg; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a187-v6si28543724pgc.238.2018.05.30.09.12.47; Wed, 30 May 2018 09:13:01 -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=@gmail.com header.s=20161025 header.b=hcK4S4eg; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932089AbeE3QLB (ORCPT + 99 others); Wed, 30 May 2018 12:11:01 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:42263 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753137AbeE3QK7 (ORCPT ); Wed, 30 May 2018 12:10:59 -0400 Received: by mail-oi0-f68.google.com with SMTP id t27-v6so16830232oij.9; Wed, 30 May 2018 09:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=QGNb2vOJ0pNtfyqJvXC9vVGE9fLuLfee4hMk2TPX+yA=; b=hcK4S4egk8ILOsW4HhWhybBC/5XDJqqnBYF3s5iCH8ksOKScjh+JkcWrfnLAXxUgst h7f01pTI7TLrRhi/3acaQ9jIukwSjNebE9oxbwEl8KbYpSBD28XQndzo7RmxaTop9PWk mALSiu7EgudJHRNilPcFCUa0ITOr/u3yD7wbk47pr7PB8uP5dvR7myez+4J7MmZ2FO1+ mk9mV+2MUmp/4pdFJ4f9r348p+V9NZ9x6kHkeuywRTgwQihy/JFfIC/WLqWIByP6LSuB WO8pM8jMH9qzxN8Bp/m9p0VuR1syPs2cElxaWIa2Gd/VRKM6g9eIZk37oFtdSdyjHLAa Lc9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=QGNb2vOJ0pNtfyqJvXC9vVGE9fLuLfee4hMk2TPX+yA=; b=b/9B1kltMSvuUvOh8A9PISqnJCJus4Ify3Qh+aKbNp+qAta8xuCv+YdmKV5ytmGxIQ 51GvmFkWm+WAzUuYxmXYp6qk9D98kHt0k6GlGZBdArJ6b3ZKE5fwKt3il5VbMpUekhB9 WqOf8ntZiGGqxH4dniaT9BCe4wcM09gIU+jmuheqCbOx+piJnUOj+XgaSi+F1W4HkQie jJ4+ZQCmj7aIh9WEVOpZ26nW7ISn+ADddWEfGu850Yj8lDb3iHIX0mtUU9FIv8+xCY+V HbgvXAF7CPuoKeJCyIhB/Cj8u6bFxoYPozPP6Nd+EYjUzMO6PY/5DwKxslfOipSSxMoY Yatg== X-Gm-Message-State: ALKqPwev+hQBOSw4grr/n2HUcsZIJ0NObIxysjNbyYSv/3aTYASv8bc2 VA9+mDPBbysGHV9UE9QcDaUSHvGzhS7KHocqWJI= X-Received: by 2002:aca:df54:: with SMTP id w81-v6mr1756732oig.129.1527696658320; Wed, 30 May 2018 09:10:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:ad1:0:0:0:0:0 with HTTP; Wed, 30 May 2018 09:10:57 -0700 (PDT) In-Reply-To: <20180530085521.26583-1-tiwei.bie@intel.com> References: <20180530085521.26583-1-tiwei.bie@intel.com> From: Alexander Duyck Date: Wed, 30 May 2018 09:10:57 -0700 Message-ID: Subject: Re: [virtio-dev] [PATCH] virtio_pci: support enabling VFs To: Tiwei Bie Cc: "Michael S. Tsirkin" , Bjorn Helgaas , virtualization@lists.linux-foundation.org, LKML , virtio-dev@lists.oasis-open.org, linux-pci@vger.kernel.org, "Daly, Dan" , "Rustad, Mark D" , "Duyck, Alexander H" , cunming.liang@intel.com, zhihong.wang@intel.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 30, 2018 at 1:55 AM, Tiwei Bie wrote: > There is a new feature bit allocated in virtio spec to > support SR-IOV (Single Root I/O Virtualization): > > https://github.com/oasis-tcs/virtio-spec/issues/11 > > This patch enables the support for this feature bit in > virtio driver. > > Signed-off-by: Tiwei Bie So from a quick glance it looks like we are leaving SR-IOV enabled if the driver is removed. Do we want to have that behavior or should we be adding the code to disable SR-IOV and free the VFs on driver removal? > --- > This patch depends on below proposal: > https://lists.oasis-open.org/archives/virtio-dev/201805/msg00154.html > > This patch depends on below patch: > https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git/commit/?h=pci/virtualization&id=8effc395c2097e258fcedfc02ed4a66d45fb4238 > > drivers/virtio/virtio_pci_common.c | 20 ++++++++++++++++++++ > drivers/virtio/virtio_pci_modern.c | 14 ++++++++++++++ > include/uapi/linux/virtio_config.h | 7 ++++++- > 3 files changed, 40 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c > index 48d4d1cf1cb6..023da80a7a3e 100644 > --- a/drivers/virtio/virtio_pci_common.c > +++ b/drivers/virtio/virtio_pci_common.c > @@ -588,6 +588,25 @@ static void virtio_pci_remove(struct pci_dev *pci_dev) > put_device(dev); > } > > +static int virtio_pci_sriov_configure(struct pci_dev *pci_dev, int num_vfs) > +{ > + struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); > + struct virtio_device *vdev = &vp_dev->vdev; > + int (*sriov_configure)(struct pci_dev *pci_dev, int num_vfs); > + > + if (!(vdev->config->get_status(vdev) & VIRTIO_CONFIG_S_DRIVER_OK)) > + return -EBUSY; > + > + if (!__virtio_test_bit(vdev, VIRTIO_F_SR_IOV)) > + return -EINVAL; > + > + sriov_configure = pci_sriov_configure_simple; > + if (sriov_configure == NULL) > + return -ENOENT; > + > + return sriov_configure(pci_dev, num_vfs); > +} > + > static struct pci_driver virtio_pci_driver = { > .name = "virtio-pci", > .id_table = virtio_pci_id_table, > @@ -596,6 +615,7 @@ static struct pci_driver virtio_pci_driver = { > #ifdef CONFIG_PM_SLEEP > .driver.pm = &virtio_pci_pm_ops, > #endif > + .sriov_configure = virtio_pci_sriov_configure, > }; > > module_pci_driver(virtio_pci_driver); > diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c > index 2555d80f6eec..07571daccfec 100644 > --- a/drivers/virtio/virtio_pci_modern.c > +++ b/drivers/virtio/virtio_pci_modern.c > @@ -153,14 +153,28 @@ static u64 vp_get_features(struct virtio_device *vdev) > return features; > } > > +static void vp_transport_features(struct virtio_device *vdev, u64 features) > +{ > + struct virtio_pci_device *vp_dev = to_vp_device(vdev); > + struct pci_dev *pci_dev = vp_dev->pci_dev; > + > + if ((features & BIT_ULL(VIRTIO_F_SR_IOV)) && > + pci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV)) > + __virtio_set_bit(vdev, VIRTIO_F_SR_IOV); > +} > + > /* virtio config->finalize_features() implementation */ > static int vp_finalize_features(struct virtio_device *vdev) > { > struct virtio_pci_device *vp_dev = to_vp_device(vdev); > + u64 features = vdev->features; > > /* Give virtio_ring a chance to accept features. */ > vring_transport_features(vdev); > > + /* Give virtio_pci a chance to accept features. */ > + vp_transport_features(vdev, features); > + > if (!__virtio_test_bit(vdev, VIRTIO_F_VERSION_1)) { > dev_err(&vdev->dev, "virtio: device uses modern interface " > "but does not have VIRTIO_F_VERSION_1\n"); > diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h > index 308e2096291f..b7c1f4e7d59e 100644 > --- a/include/uapi/linux/virtio_config.h > +++ b/include/uapi/linux/virtio_config.h > @@ -49,7 +49,7 @@ > * transport being used (eg. virtio_ring), the rest are per-device feature > * bits. */ > #define VIRTIO_TRANSPORT_F_START 28 > -#define VIRTIO_TRANSPORT_F_END 34 > +#define VIRTIO_TRANSPORT_F_END 38 > > #ifndef VIRTIO_CONFIG_NO_LEGACY > /* Do we get callbacks when the ring is completely used, even if we've > @@ -71,4 +71,9 @@ > * this is for compatibility with legacy systems. > */ > #define VIRTIO_F_IOMMU_PLATFORM 33 > + > +/* > + * Does the device support Single Root I/O Virtualization? > + */ > +#define VIRTIO_F_SR_IOV 37 > #endif /* _UAPI_LINUX_VIRTIO_CONFIG_H */ > -- > 2.17.0 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org >