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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DCFA2C433FE for ; Thu, 14 Apr 2022 06:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237051AbiDNG1Y (ORCPT ); Thu, 14 Apr 2022 02:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231788AbiDNG1Y (ORCPT ); Thu, 14 Apr 2022 02:27:24 -0400 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97631FA6F; Wed, 13 Apr 2022 23:24:56 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=33;SR=0;TI=SMTPD_---0VA0zc-G_1649917489; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0VA0zc-G_1649917489) by smtp.aliyun-inc.com(127.0.0.1); Thu, 14 Apr 2022 14:24:51 +0800 Message-ID: <1649917349.6242197-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH v9 22/32] virtio_pci: queue_reset: extract the logic of active vq for modern pci Date: Thu, 14 Apr 2022 14:22:29 +0800 From: Xuan Zhuo To: Jason Wang Cc: Jeff Dike , Richard Weinberger , Anton Ivanov , "Michael S. Tsirkin" , "David S. Miller" , Jakub Kicinski , Hans de Goede , Mark Gross , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , Cornelia Huck , Halil Pasic , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , Sven Schnelle , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Johannes Berg , Vincent Whitchurch , linux-um@lists.infradead.org, netdev@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org, virtualization@lists.linux-foundation.org References: <20220406034346.74409-1-xuanzhuo@linux.alibaba.com> <20220406034346.74409-23-xuanzhuo@linux.alibaba.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-s390@vger.kernel.org On Tue, 12 Apr 2022 14:58:19 +0800, Jason Wang wrote: > > =E5=9C=A8 2022/4/6 =E4=B8=8A=E5=8D=8811:43, Xuan Zhuo =E5=86=99=E9=81=93: > > Introduce vp_active_vq() to configure vring to backend after vq attach > > vring. And configure vq vector if necessary. > > > > Signed-off-by: Xuan Zhuo > > --- > > drivers/virtio/virtio_pci_modern.c | 46 ++++++++++++++++++------------ > > 1 file changed, 28 insertions(+), 18 deletions(-) > > > > diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio= _pci_modern.c > > index 86d301f272b8..49a4493732cf 100644 > > --- a/drivers/virtio/virtio_pci_modern.c > > +++ b/drivers/virtio/virtio_pci_modern.c > > @@ -176,6 +176,29 @@ static void vp_reset(struct virtio_device *vdev) > > vp_disable_cbs(vdev); > > } > > > > +static int vp_active_vq(struct virtqueue *vq, u16 msix_vec) > > +{ > > + struct virtio_pci_device *vp_dev =3D to_vp_device(vq->vdev); > > + struct virtio_pci_modern_device *mdev =3D &vp_dev->mdev; > > + unsigned long index; > > + > > + index =3D vq->index; > > + > > + /* activate the queue */ > > + vp_modern_set_queue_size(mdev, index, virtqueue_get_vring_size(vq)); > > + vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq), > > + virtqueue_get_avail_addr(vq), > > + virtqueue_get_used_addr(vq)); > > + > > + if (msix_vec !=3D VIRTIO_MSI_NO_VECTOR) { > > + msix_vec =3D vp_modern_queue_vector(mdev, index, msix_vec); > > + if (msix_vec =3D=3D VIRTIO_MSI_NO_VECTOR) > > + return -EBUSY; > > + } > > + > > + return 0; > > +} > > + > > static u16 vp_config_vector(struct virtio_pci_device *vp_dev, u16 vec= tor) > > { > > return vp_modern_config_vector(&vp_dev->mdev, vector); > > @@ -220,32 +243,19 @@ static struct virtqueue *setup_vq(struct virtio_p= ci_device *vp_dev, > > > > vq->num_max =3D num; > > > > - /* activate the queue */ > > - vp_modern_set_queue_size(mdev, index, virtqueue_get_vring_size(vq)); > > - vp_modern_queue_address(mdev, index, virtqueue_get_desc_addr(vq), > > - virtqueue_get_avail_addr(vq), > > - virtqueue_get_used_addr(vq)); > > + err =3D vp_active_vq(vq, msix_vec); > > + if (err) > > + goto err; > > > > vq->priv =3D (void __force *)vp_modern_map_vq_notify(mdev, index, NU= LL); > > if (!vq->priv) { > > err =3D -ENOMEM; > > - goto err_map_notify; > > - } > > - > > - if (msix_vec !=3D VIRTIO_MSI_NO_VECTOR) { > > - msix_vec =3D vp_modern_queue_vector(mdev, index, msix_vec); > > - if (msix_vec =3D=3D VIRTIO_MSI_NO_VECTOR) { > > - err =3D -EBUSY; > > - goto err_assign_vector; > > - } > > + goto err; > > } > > > > return vq; > > > > -err_assign_vector: > > - if (!mdev->notify_base) > > - pci_iounmap(mdev->pci_dev, (void __iomem __force *)vq->priv); > > > We need keep this or anything I missed? I think so, after modification, vp_modern_map_vq_notify is the last step be= fore returning vq. If it fails, then vq->priv is equal to NULL, so there is no n= eed to execute pci_iounmap. Did I miss something? Thanks. > > Thanks > > > > -err_map_notify: > > +err: > > vring_del_virtqueue(vq); > > return ERR_PTR(err); > > } >