{"id":1658309,"url":"http://patchwork.ozlabs.org/api/patches/1658309/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-um/patch/20220720030436.79520-31-xuanzhuo@linux.alibaba.com/","project":{"id":60,"url":"http://patchwork.ozlabs.org/api/projects/60/?format=json","name":"User-mode Linux Development","link_name":"linux-um","list_id":"linux-um.lists.infradead.org","list_email":"linux-um@lists.infradead.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20220720030436.79520-31-xuanzhuo@linux.alibaba.com>","list_archive_url":null,"date":"2022-07-20T03:04:26","name":"[v12,30/40] virtio_pci: support VIRTIO_F_RING_RESET","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"2fea6de2b94c35f41126f9e7962744b941041410","submitter":{"id":80519,"url":"http://patchwork.ozlabs.org/api/people/80519/?format=json","name":"Xuan Zhuo","email":"xuanzhuo@linux.alibaba.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-um/patch/20220720030436.79520-31-xuanzhuo@linux.alibaba.com/mbox/","series":[{"id":310331,"url":"http://patchwork.ozlabs.org/api/series/310331/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-um/list/?series=310331","date":"2022-07-20T03:03:59","name":"virtio pci support VIRTIO_F_RING_RESET","version":12,"mbox":"http://patchwork.ozlabs.org/series/310331/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/1658309/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/1658309/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["bilbo.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ekmhT5du;\n\tdkim-atps=neutral","ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=lists.infradead.org\n (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;\n envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=<UNKNOWN>)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby bilbo.ozlabs.org (Postfix) with ESMTPS id 4LngZQ66Xkz9s2R\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 20 Jul 2022 13:06:06 +1000 (AEST)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux))\n\tid 1oE029-00HFIc-SB; Wed, 20 Jul 2022 03:05:57 +0000","from out30-130.freemail.mail.aliyun.com ([115.124.30.130])\n\tby bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux))\n\tid 1oE025-00HFCt-Rm\n\tfor linux-um@lists.infradead.org; Wed, 20 Jul 2022 03:05:55 +0000","from localhost(mailfrom:xuanzhuo@linux.alibaba.com\n fp:SMTPD_---0VJux9EQ_1658286348)\n          by smtp.aliyun-inc.com;\n          Wed, 20 Jul 2022 11:05:49 +0800"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:\n\tMessage-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tList-Owner; bh=eHKYsMS8okLDYGwIj5RB4gsC2VhYoqpS4PZOk2s2PAk=; b=ekmhT5duMnMlhg\n\thVtpHD2KcgGuLJbJ8QFCX5SL1NIQACzubJL3ZJSn28KefEHVRrDsx5WBAuLCDM91WmSzs19Mgqb2F\n\ttbyURwqi2eHfObFx1mYJLQ9rdBQ9WY4h3KhQ1nDBY43cwphONdBiqF3I3FMiISd9MaTM4do82DDoe\n\tI2OjjMERcICFy6x3LbUeGSAHC7TzhQJEMEmShlN4H/FGvOiAF6m0UB0bxS3aeFW41U3P+ZuenHZQQ\n\tok/rKqv1reAUKYhUA0+sdTGCm7yODzwEFCBPn2rRYiNpc2uWTuldS7/6EXcv0l8hrw//TqADzANSi\n\ts4FYMeMzveU2nwNU4lkw==;","X-Alimail-AntiSpam":"\n AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=37;SR=0;TI=SMTPD_---0VJux9EQ_1658286348;","From":"Xuan Zhuo <xuanzhuo@linux.alibaba.com>","To":"virtualization@lists.linux-foundation.org","Cc":"Richard Weinberger <richard@nod.at>,\n\tAnton Ivanov <anton.ivanov@cambridgegreys.com>,\n\tJohannes Berg <johannes@sipsolutions.net>,\n\t\"Michael S. Tsirkin\" <mst@redhat.com>,\n\tJason Wang <jasowang@redhat.com>,\n\t\"David S. Miller\" <davem@davemloft.net>,\n\tEric Dumazet <edumazet@google.com>,\n\tJakub Kicinski <kuba@kernel.org>,\n\tPaolo Abeni <pabeni@redhat.com>,\n\tHans de Goede <hdegoede@redhat.com>,\n\tMark Gross <markgross@kernel.org>,\n\tVadim Pasternak <vadimp@nvidia.com>,\n\tBjorn Andersson <bjorn.andersson@linaro.org>,\n\tMathieu Poirier <mathieu.poirier@linaro.org>,\n\tCornelia Huck <cohuck@redhat.com>,\n\tHalil Pasic <pasic@linux.ibm.com>,\n\tEric Farman <farman@linux.ibm.com>,\n\tHeiko Carstens <hca@linux.ibm.com>,\n\tVasily Gorbik <gor@linux.ibm.com>,\n\tAlexander Gordeev <agordeev@linux.ibm.com>,\n\tChristian Borntraeger <borntraeger@linux.ibm.com>,\n\tSven Schnelle <svens@linux.ibm.com>,\n\tAlexei Starovoitov <ast@kernel.org>,\n\tDaniel Borkmann <daniel@iogearbox.net>,\n\tJesper Dangaard Brouer <hawk@kernel.org>,\n\tJohn Fastabend <john.fastabend@gmail.com>,\n\tXuan Zhuo <xuanzhuo@linux.alibaba.com>,\n\tVincent Whitchurch <vincent.whitchurch@axis.com>,\n\tlinux-um@lists.infradead.org,\n\tnetdev@vger.kernel.org,\n\tplatform-driver-x86@vger.kernel.org,\n\tlinux-remoteproc@vger.kernel.org,\n\tlinux-s390@vger.kernel.org,\n\tkvm@vger.kernel.org,\n\tbpf@vger.kernel.org,\n\tkangjie.xu@linux.alibaba.com","Subject":"[PATCH v12 30/40] virtio_pci: support VIRTIO_F_RING_RESET","Date":"Wed, 20 Jul 2022 11:04:26 +0800","Message-Id":"<20220720030436.79520-31-xuanzhuo@linux.alibaba.com>","X-Mailer":"git-send-email 2.31.0","In-Reply-To":"<20220720030436.79520-1-xuanzhuo@linux.alibaba.com>","References":"<20220720030436.79520-1-xuanzhuo@linux.alibaba.com>","MIME-Version":"1.0","X-Git-Hash":"366032b2ffac","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20220719_200554_099570_C541A46E ","X-CRM114-Status":"GOOD (  19.19  )","X-Spam-Score":"-8.0 (--------)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  This patch implements virtio pci support for QUEUE RESET.\n   Performing reset on a queue is divided into these steps: 1. notify the\n device\n    to reset the queue 2. recycle the buffer submitted 3. reset the vring (may\n    re-alloc) 4. mmap vring to device, and enable the queue\n Content analysis details:   (-8.0 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,\n                              no trust\n                             [115.124.30.130 listed in list.dnswl.org]\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -7.5 USER_IN_DEF_SPF_WL     From: address is in the default SPF\n                             white-list\n -0.5 ENV_AND_HDR_SPF_MATCH  Env and Hdr From used in default SPF WL\n                             Match\n  0.0 UNPARSEABLE_RELAY      Informational: message has unparseable relay\n                             lines","X-BeenThere":"linux-um@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"<linux-um.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-um>,\n <mailto:linux-um-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-um/>","List-Post":"<mailto:linux-um@lists.infradead.org>","List-Help":"<mailto:linux-um-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-um>,\n <mailto:linux-um-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-um\" <linux-um-bounces@lists.infradead.org>","Errors-To":"linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"This patch implements virtio pci support for QUEUE RESET.\n\nPerforming reset on a queue is divided into these steps:\n\n 1. notify the device to reset the queue\n 2. recycle the buffer submitted\n 3. reset the vring (may re-alloc)\n 4. mmap vring to device, and enable the queue\n\nThis patch implements virtio_reset_vq(), virtio_enable_resetq() in the\npci scenario.\n\nSigned-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>\n---\n drivers/virtio/virtio_pci_common.c | 12 +++-\n drivers/virtio/virtio_pci_modern.c | 96 ++++++++++++++++++++++++++++++\n 2 files changed, 105 insertions(+), 3 deletions(-)","diff":"diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c\nindex ca51fcc9daab..ad258a9d3b9f 100644\n--- a/drivers/virtio/virtio_pci_common.c\n+++ b/drivers/virtio/virtio_pci_common.c\n@@ -214,9 +214,15 @@ static void vp_del_vq(struct virtqueue *vq)\n \tstruct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];\n \tunsigned long flags;\n \n-\tspin_lock_irqsave(&vp_dev->lock, flags);\n-\tlist_del(&info->node);\n-\tspin_unlock_irqrestore(&vp_dev->lock, flags);\n+\t/*\n+\t * If it fails during re-enable reset vq. This way we won't rejoin\n+\t * info->node to the queue. Prevent unexpected irqs.\n+\t */\n+\tif (!vq->reset) {\n+\t\tspin_lock_irqsave(&vp_dev->lock, flags);\n+\t\tlist_del(&info->node);\n+\t\tspin_unlock_irqrestore(&vp_dev->lock, flags);\n+\t}\n \n \tvp_dev->del_vq(info);\n \tkfree(info);\ndiff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c\nindex 9041d9a41b7d..4d28b6918c80 100644\n--- a/drivers/virtio/virtio_pci_modern.c\n+++ b/drivers/virtio/virtio_pci_modern.c\n@@ -34,6 +34,9 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)\n \tif ((features & BIT_ULL(VIRTIO_F_SR_IOV)) &&\n \t\t\tpci_find_ext_capability(pci_dev, PCI_EXT_CAP_ID_SRIOV))\n \t\t__virtio_set_bit(vdev, VIRTIO_F_SR_IOV);\n+\n+\tif (features & BIT_ULL(VIRTIO_F_RING_RESET))\n+\t\t__virtio_set_bit(vdev, VIRTIO_F_RING_RESET);\n }\n \n /* virtio config->finalize_features() implementation */\n@@ -199,6 +202,95 @@ static int vp_active_vq(struct virtqueue *vq, u16 msix_vec)\n \treturn 0;\n }\n \n+static int vp_modern_reset_vq(struct virtqueue *vq)\n+{\n+\tstruct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);\n+\tstruct virtio_pci_modern_device *mdev = &vp_dev->mdev;\n+\tstruct virtio_pci_vq_info *info;\n+\tunsigned long flags;\n+\n+\tif (!virtio_has_feature(vq->vdev, VIRTIO_F_RING_RESET))\n+\t\treturn -ENOENT;\n+\n+\tvp_modern_set_queue_reset(mdev, vq->index);\n+\n+\tinfo = vp_dev->vqs[vq->index];\n+\n+\t/* delete vq from irq handler */\n+\tspin_lock_irqsave(&vp_dev->lock, flags);\n+\tlist_del(&info->node);\n+\tspin_unlock_irqrestore(&vp_dev->lock, flags);\n+\n+\tINIT_LIST_HEAD(&info->node);\n+\n+\t/* For the case where vq has an exclusive irq, to prevent the irq from\n+\t * being received again and the pending irq, call synchronize_irq(), and\n+\t * break it.\n+\t *\n+\t * We can't use disable_irq() since it conflicts with the affinity\n+\t * managed IRQ that is used by some drivers. So this is done on top of\n+\t * IRQ hardening.\n+\t *\n+\t * In the scenario based on shared interrupts, vq will be searched from\n+\t * the queue virtqueues. Since the previous list_del() has been deleted\n+\t * from the queue, it is impossible for vq to be called in this case.\n+\t * There is no need to close the corresponding interrupt.\n+\t */\n+\tif (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR) {\n+#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION\n+\t\t__virtqueue_break(vq);\n+#endif\n+\t\tsynchronize_irq(pci_irq_vector(vp_dev->pci_dev, info->msix_vector));\n+\t}\n+\n+\tvq->reset = true;\n+\n+\treturn 0;\n+}\n+\n+static int vp_modern_enable_reset_vq(struct virtqueue *vq)\n+{\n+\tstruct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);\n+\tstruct virtio_pci_modern_device *mdev = &vp_dev->mdev;\n+\tstruct virtio_pci_vq_info *info;\n+\tunsigned long flags, index;\n+\tint err;\n+\n+\tif (!vq->reset)\n+\t\treturn -EBUSY;\n+\n+\tindex = vq->index;\n+\tinfo = vp_dev->vqs[index];\n+\n+\tif (vp_modern_get_queue_reset(mdev, index))\n+\t\treturn -EBUSY;\n+\n+\tif (vp_modern_get_queue_enable(mdev, index))\n+\t\treturn -EBUSY;\n+\n+\terr = vp_active_vq(vq, info->msix_vector);\n+\tif (err)\n+\t\treturn err;\n+\n+\tif (vq->callback) {\n+\t\tspin_lock_irqsave(&vp_dev->lock, flags);\n+\t\tlist_add(&info->node, &vp_dev->virtqueues);\n+\t\tspin_unlock_irqrestore(&vp_dev->lock, flags);\n+\t} else {\n+\t\tINIT_LIST_HEAD(&info->node);\n+\t}\n+\n+#ifdef CONFIG_VIRTIO_HARDEN_NOTIFICATION\n+\tif (vp_dev->per_vq_vectors && info->msix_vector != VIRTIO_MSI_NO_VECTOR)\n+\t\t__virtqueue_unbreak(vq);\n+#endif\n+\n+\tvp_modern_set_queue_enable(&vp_dev->mdev, index, true);\n+\tvq->reset = false;\n+\n+\treturn 0;\n+}\n+\n static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vector)\n {\n \treturn vp_modern_config_vector(&vp_dev->mdev, vector);\n@@ -413,6 +505,8 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = {\n \t.set_vq_affinity = vp_set_vq_affinity,\n \t.get_vq_affinity = vp_get_vq_affinity,\n \t.get_shm_region  = vp_get_shm_region,\n+\t.disable_vq_and_reset = vp_modern_reset_vq,\n+\t.enable_vq_after_reset = vp_modern_enable_reset_vq,\n };\n \n static const struct virtio_config_ops virtio_pci_config_ops = {\n@@ -431,6 +525,8 @@ static const struct virtio_config_ops virtio_pci_config_ops = {\n \t.set_vq_affinity = vp_set_vq_affinity,\n \t.get_vq_affinity = vp_get_vq_affinity,\n \t.get_shm_region  = vp_get_shm_region,\n+\t.disable_vq_and_reset = vp_modern_reset_vq,\n+\t.enable_vq_after_reset = vp_modern_enable_reset_vq,\n };\n \n /* the PCI probing function */\n","prefixes":["v12","30/40"]}