Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp733986ybg; Wed, 10 Jun 2020 12:13:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8drHgdD/Gjv6ulj3u9rCYNAADmk2SOeS1sT8EmAXvzwgzqCH5OCclY9p6kicCdlRPZ49G X-Received: by 2002:a17:906:7212:: with SMTP id m18mr4821917ejk.29.1591816419520; Wed, 10 Jun 2020 12:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591816419; cv=none; d=google.com; s=arc-20160816; b=Lrp7bv3rf4ORCKs9R4dwnu5LoeV/CUBffBexQacwccFVMeqroUCt8MCHFDnUlOjQ73 MsA8Xes18I+DVh00qNkcX0c30W0jczyptUcqxYQIFJrkn4Ua5K3/IAUJiJ/T8uAPb5Pd 7uwdp7oD+eCH5Mv5+LAPu0yflsomzPu6+QuxL6udbSQOPFwPIG1Wdskl79RIsrzFI1Ir O8KfvKRmosZWV1kiOlRIuyDtd5htjxEyX4xQIbpUx1lMfSlTyElp4qHrSf5DYoSbPBTm VGRMS4ndevpIM4X1bhBA38i4OLtofC00Vf35MlxV9ZBlgngubljE3tZTZeJDxeFY7YKa UjZw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=3AdYr/U77mMkba00VNjxwsRChFi8mZOf+xIMqa5UEd8=; b=uakLMsgvT7qn6AnltrsT+/aON2K5ZoRQpgklHl1FXCGQtraxYiz4s7M+QTE1Etf9Sc eadCYPIC6eh5kofPH8LwUAWCoJxR5l4zQbgx1WrrmHRqYrbR0SQ2PMf4WKdXYQiuExTJ mYyP2zdBlOjLSOKehna3+gS1W+SBO0FNaOSpZDiXFpYHZ8G6KfIkhMphVesdRcc7Mh9N 7oxxZNiFh/w/Dc7t68MGutKkWCbhOJgHMBOr0O8MaYYS8HqSsCLKhLjMSrGbddLDtaMm n7qdJJateZLm5pQGRXxOlks/XoRvriX7NiV1icNvGpQnQIpZq0NP3uISJkfARKL+zzLF yLUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VAf8WwMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u23si564832ejx.512.2020.06.10.12.13.15; Wed, 10 Jun 2020 12:13:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VAf8WwMd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730024AbgFJPNS (ORCPT + 99 others); Wed, 10 Jun 2020 11:13:18 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:43644 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728108AbgFJPNS (ORCPT ); Wed, 10 Jun 2020 11:13:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591801997; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3AdYr/U77mMkba00VNjxwsRChFi8mZOf+xIMqa5UEd8=; b=VAf8WwMdPYF0UqCwQtRRQ9OrKnIe8JW6E23tKoszhYcIIauVmY3lMSvRQA81v4cm4vNIGG DVDe/9ccqaosCpUkd7Ds8rL6QCiuZyKbzqGKEvmA87TCzMFpm6VHFd9Ra15J5aOv99W2VL qLO4as4etqhsq/7xjCU//WhXGP2w6Mk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-41-L1B-mkbxMNmPnfRBbTeduw-1; Wed, 10 Jun 2020 11:13:15 -0400 X-MC-Unique: L1B-mkbxMNmPnfRBbTeduw-1 Received: by mail-qk1-f199.google.com with SMTP id p138so2311810qke.7 for ; Wed, 10 Jun 2020 08:13:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=3AdYr/U77mMkba00VNjxwsRChFi8mZOf+xIMqa5UEd8=; b=I8NofVFiKSB0VRg4E0rCVT9y1J81RD4qMzQhbTZyJAhYD9x9OQnlqAicjebZ8gBylU g071bg0+KgwXIh20Lujnk9QdpVX3hAGR7SctWzUrswWYjYD0l9ooZGyNy72ND7NBlTFH H9lr5SxG6NYfYVWzTJngQH4rX363rAsUmWd09O6FZFQmmGFjmwg98h9E1W5zRdmr7ude aXmqlc5JeReX/cl2BZgZTjQ69v9XgztX1THQn0koKEjOoS4+FgXtzw0KO2b22JJQ5MqI 3fWOJyBeib0wa40BiK0daFLgZgXPZ6ON2mCNs0t7cjSSqFumGuNTgfPAALYvdSRhvwb5 xxlw== X-Gm-Message-State: AOAM53009MJQ2LoFICGmCIa/RFkHcTRaMvjQWjgfqSrdQ7skP9r1y8Ih g+zr8POY2nkQwCFByFMrRfFAIJRSx2Ki2vRH46Unfb2FiU7emPi+e77fvq14MD+A0YIM5/UqeCL oIvT1lF+TD9OQhgJLEp913daPz8N7tVM2RA2m05OB X-Received: by 2002:a37:64c6:: with SMTP id y189mr3551956qkb.353.1591801994701; Wed, 10 Jun 2020 08:13:14 -0700 (PDT) X-Received: by 2002:a37:64c6:: with SMTP id y189mr3551926qkb.353.1591801994393; Wed, 10 Jun 2020 08:13:14 -0700 (PDT) MIME-Version: 1.0 References: <20200610113515.1497099-1-mst@redhat.com> <20200610113515.1497099-4-mst@redhat.com> <035e82bcf4ade0017641c5b457d0c628c5915732.camel@redhat.com> <20200610105829-mutt-send-email-mst@kernel.org> In-Reply-To: <20200610105829-mutt-send-email-mst@kernel.org> From: Eugenio Perez Martin Date: Wed, 10 Jun 2020 17:12:38 +0200 Message-ID: Subject: Re: [PATCH RFC v7 03/14] vhost: use batched get_vq_desc version To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, kvm list , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, Jason Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 10, 2020 at 5:08 PM Michael S. Tsirkin wrote: > > On Wed, Jun 10, 2020 at 04:29:29PM +0200, Eugenio P=C3=83=C2=A9rez wrote: > > On Wed, 2020-06-10 at 07:36 -0400, Michael S. Tsirkin wrote: > > > As testing shows no performance change, switch to that now. > > > > > > Signed-off-by: Michael S. Tsirkin > > > Signed-off-by: Eugenio P=C3=83=C2=A9rez > > > Link: https://lore.kernel.org/r/20200401183118.8334-3-eperezma@redhat= .com > > > Signed-off-by: Michael S. Tsirkin > > > --- > > > drivers/vhost/test.c | 2 +- > > > drivers/vhost/vhost.c | 318 ++++++++--------------------------------= -- > > > drivers/vhost/vhost.h | 7 +- > > > 3 files changed, 65 insertions(+), 262 deletions(-) > > > > > > diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c > > > index 0466921f4772..7d69778aaa26 100644 > > > --- a/drivers/vhost/test.c > > > +++ b/drivers/vhost/test.c > > > @@ -119,7 +119,7 @@ static int vhost_test_open(struct inode *inode, s= truct file *f) > > > dev =3D &n->dev; > > > vqs[VHOST_TEST_VQ] =3D &n->vqs[VHOST_TEST_VQ]; > > > n->vqs[VHOST_TEST_VQ].handle_kick =3D handle_vq_kick; > > > - vhost_dev_init(dev, vqs, VHOST_TEST_VQ_MAX, UIO_MAXIOV, > > > + vhost_dev_init(dev, vqs, VHOST_TEST_VQ_MAX, UIO_MAXIOV + 64, > > > VHOST_TEST_PKT_WEIGHT, VHOST_TEST_WEIGHT, true, NU= LL); > > > > > > f->private_data =3D n; > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > > index 11433d709651..28f324fd77df 100644 > > > --- a/drivers/vhost/vhost.c > > > +++ b/drivers/vhost/vhost.c > > > @@ -304,6 +304,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, > > > { > > > vq->num =3D 1; > > > vq->ndescs =3D 0; > > > + vq->first_desc =3D 0; > > > vq->desc =3D NULL; > > > vq->avail =3D NULL; > > > vq->used =3D NULL; > > > @@ -372,6 +373,11 @@ static int vhost_worker(void *data) > > > return 0; > > > } > > > > > > +static int vhost_vq_num_batch_descs(struct vhost_virtqueue *vq) > > > +{ > > > + return vq->max_descs - UIO_MAXIOV; > > > +} > > > + > > > static void vhost_vq_free_iovecs(struct vhost_virtqueue *vq) > > > { > > > kfree(vq->descs); > > > @@ -394,6 +400,9 @@ static long vhost_dev_alloc_iovecs(struct vhost_d= ev *dev) > > > for (i =3D 0; i < dev->nvqs; ++i) { > > > vq =3D dev->vqs[i]; > > > vq->max_descs =3D dev->iov_limit; > > > + if (vhost_vq_num_batch_descs(vq) < 0) { > > > + return -EINVAL; > > > + } > > > vq->descs =3D kmalloc_array(vq->max_descs, > > > sizeof(*vq->descs), > > > GFP_KERNEL); > > > @@ -1610,6 +1619,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, uns= igned int ioctl, void __user *arg > > > vq->last_avail_idx =3D s.num; > > > /* Forget the cached index value. */ > > > vq->avail_idx =3D vq->last_avail_idx; > > > + vq->ndescs =3D vq->first_desc =3D 0; > > > > This is not needed if it is done in vhost_vq_set_backend, as far as I c= an tell. > > > > Actually, maybe it is even better to move `vq->avail_idx =3D vq->last_a= vail_idx;` line to vhost_vq_set_backend, it is part > > of the backend "set up" procedure, isn't it? > > > > I tested with virtio_test + batch tests sent in > > https://lkml.kernel.org/lkml/20200418102217.32327-1-eperezma@redhat.com= /T/. > > Ow did I forget to merge them for rc1? Should I have? Maybe Linus won't > yell to hard at me if I merge them after rc1. > > > > I append here what I'm proposing in case it is clearer this way. > > > > Thanks! > > > > diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c > > index 4d198994e7be..809ad2cd2879 100644 > > --- a/drivers/vhost/vhost.c > > +++ b/drivers/vhost/vhost.c > > @@ -1617,9 +1617,6 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsig= ned int ioctl, void __user *arg > > break; > > } > > vq->last_avail_idx =3D s.num; > > - /* Forget the cached index value. */ > > - vq->avail_idx =3D vq->last_avail_idx; > > - vq->ndescs =3D vq->first_desc =3D 0; > > break; > > case VHOST_GET_VRING_BASE: > > s.index =3D idx; > > diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h > > index fed36af5c444..f4902dc808e4 100644 > > --- a/drivers/vhost/vhost.h > > +++ b/drivers/vhost/vhost.h > > @@ -258,6 +258,7 @@ static inline void vhost_vq_set_backend(struct vhos= t_virtqueue *vq, > > void *private_data) > > { > > vq->private_data =3D private_data; > > + vq->avail_idx =3D vq->last_avail_idx; > > vq->ndescs =3D 0; > > vq->first_desc =3D 0; > > } > > > > Seems like a nice cleanup, though it's harmless right? > Fields ndescs and first_descs are supposed to be updated outside, that was the intention but maybe I forgot to delete it here, not sure. Regarding avail_idx, the whole change has been tested with vhost_test and for vhost needs to have a backend to modify it already so it seems safe to me.