Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3814699ybb; Tue, 31 Mar 2020 12:31:14 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsY0SYWyzNNM4vJKRs5zFjsjBnQLgJQmdsP/kLzUo2Gp6nidtYsc+QIPnW6b8gF8sxjl8Z+ X-Received: by 2002:a05:6830:6:: with SMTP id c6mr4298012otp.84.1585683074455; Tue, 31 Mar 2020 12:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585683074; cv=none; d=google.com; s=arc-20160816; b=NRwzCbw0a4Ff6AIB9qv0hdXOimpcbg388T4cTS6neSFN3ZGoZT9oVYqi7zQRAfSsuG ZlHedZDAmxlixr2uFJOptN66KbWG0jp5dSoPaUBRwjSsntNuFWhfCIQv2rLv/yOPiZH3 VX37YtqJ4awuaBVYbfdvmzm7jj7krYNV/NdmV2LO6hL+BH9MI0FsmLGy6eDkgRsDUMdO 5lRLaZYJYEpZx7iOyousolkDLWS3yKbuNzhGTyP2die2utJKKdRamCObdl2JG3cmY143 kfobnIexqI65kD2/G6QvRbfFxsn16xKLBe5gPcjt3jE20odZloakyh+yAN56D7SAwq7E TbAg== 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=0om1tDTYIRQhTCKQFE/dlR8vuduWySdQ5AoKosLSrZY=; b=nlZqKxWoQztIpPBBMnCxrZTaAZ21WWF+OcguxUqddr0kc4lIGLQPaD+4trqwXYhBFn 8IPdzPX+RvN5XVYqebxzzyIYt7/ZyrtiMTOYuzZVDKjCuEQ0okVi8jezrDEUDC/DljUH i/HZq37cwLync9CRJlDRGTucsCFBOjAWmZGVAWWBMo0UdjMKM8f8PxnT/7Nv62FNFbuF S6Ocq5RA0sEDXuCfA8oGj9UytCAvnkF2KFaAcV/uHRLCazWPBITTnrts4/beLblxOP2q e49dRbX+bR31y4hQOj7UhDzcawgNahfdoJ/BYvp6SOdVi4C7pJMBrzXvaq6iBju9Pm/6 bMLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PHKfWWHd; 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=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f41si2987961otf.280.2020.03.31.12.31.00; Tue, 31 Mar 2020 12:31:14 -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=@redhat.com header.s=mimecast20190719 header.b=PHKfWWHd; 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=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731412AbgCaT3G (ORCPT + 99 others); Tue, 31 Mar 2020 15:29:06 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:53847 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730677AbgCaT3G (ORCPT ); Tue, 31 Mar 2020 15:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585682944; 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=0om1tDTYIRQhTCKQFE/dlR8vuduWySdQ5AoKosLSrZY=; b=PHKfWWHdBUXMRI9Kjzy0tLqUBrtx7hhOVb1BIcMxnkH1MXXa723Ws0pGgvyRPJ+TewZN3I uNk4IOe/uFo62ANNT9+CnTS0CqcVLlmS3czMsnuPFfZKwxryUxUCo1IxxPrfcScAyXy54q //fh5FPrM3hdoLiXmJBfVes62FchPmo= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-geNfWTJeMLmvF2hb0nFf8A-1; Tue, 31 Mar 2020 15:29:02 -0400 X-MC-Unique: geNfWTJeMLmvF2hb0nFf8A-1 Received: by mail-lf1-f70.google.com with SMTP id u13so1715887lfo.10 for ; Tue, 31 Mar 2020 12:29:02 -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=0om1tDTYIRQhTCKQFE/dlR8vuduWySdQ5AoKosLSrZY=; b=EQVrRqlSAvC4Zvax4OGCfy6NRZ/WvSbseeeaF4tAvMPwBGBjzf7IM0MWhV8C8RYckS OOuCIV2o6ROG/UBTJvs0RQ9C26pakHEJ4umrFH4wuEpOyZAx0sg0GiSe5krXiChYHqgE eXMptqTi3cBvdg1h9M99BHXPjGInqZ66Jeu4K6CMJYuggRSPnxGNfL0QWojN6YghxSRD 0r1P8yuVTq1+EMuE/d31LbWHhUOCmnz+bBSZeoh3HLbuBeX0EC/zYHlrBa51odtLuSa8 +6GkseBpRWPUtdG9X0Hnad46m1RRDR7jtn1Fz+hkVbZ3uwXvuhG57pNEbq3iJbhDzkkt JlTQ== X-Gm-Message-State: AGi0PubIjNFyenFUOp2Oy5mK6VkCJd4djmHufzh4VTMlONMN9SgKrDQi V3lAvwvjNRslVMs12DVCOA8tyv3r5F2WWfUYjuWO5EENOn9Gpc31xB5uebC2FAA3mrnRQN44S/X 3udRXKwcBZqk9P8QR6PxMRwtUU36SNflgGkTWOTz0 X-Received: by 2002:ac2:5999:: with SMTP id w25mr12114696lfn.46.1585682940854; Tue, 31 Mar 2020 12:29:00 -0700 (PDT) X-Received: by 2002:ac2:5999:: with SMTP id w25mr12114683lfn.46.1585682940546; Tue, 31 Mar 2020 12:29:00 -0700 (PDT) MIME-Version: 1.0 References: <20200331180006.25829-1-eperezma@redhat.com> <20200331180006.25829-2-eperezma@redhat.com> <20200331142426-mutt-send-email-mst@kernel.org> In-Reply-To: <20200331142426-mutt-send-email-mst@kernel.org> From: Eugenio Perez Martin Date: Tue, 31 Mar 2020 21:28:24 +0200 Message-ID: Subject: Re: [PATCH v2 1/8] vhost: Create accessors for virtqueues private_data To: "Michael S. Tsirkin" Cc: "linux-kernel@vger.kernel.org" , kvm list , Halil Pasic , "virtualization@lists.linux-foundation.org" , Linux Next Mailing List , Cornelia Huck , Stephen Rothwell , Christian Borntraeger 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 Tue, Mar 31, 2020 at 8:29 PM Michael S. Tsirkin wrote: > > On Tue, Mar 31, 2020 at 07:59:59PM +0200, Eugenio P=C3=A9rez wrote: > > Signed-off-by: Eugenio P=C3=A9rez > > --- > > drivers/vhost/net.c | 28 +++++++++++++++------------- > > drivers/vhost/vhost.h | 28 ++++++++++++++++++++++++++++ > > drivers/vhost/vsock.c | 14 +++++++------- > > > Seems to be missing scsi and test. Good point, changing them too! > > > > 3 files changed, 50 insertions(+), 20 deletions(-) > > > > diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c > > index e158159671fa..6c5e7a6f712c 100644 > > --- a/drivers/vhost/net.c > > +++ b/drivers/vhost/net.c > > @@ -424,7 +424,7 @@ static void vhost_net_disable_vq(struct vhost_net *= n, > > struct vhost_net_virtqueue *nvq =3D > > container_of(vq, struct vhost_net_virtqueue, vq); > > struct vhost_poll *poll =3D n->poll + (nvq - n->vqs); > > - if (!vq->private_data) > > + if (!vhost_vq_get_backend_opaque(vq)) > > return; > > vhost_poll_stop(poll); > > } > > @@ -437,7 +437,7 @@ static int vhost_net_enable_vq(struct vhost_net *n, > > struct vhost_poll *poll =3D n->poll + (nvq - n->vqs); > > struct socket *sock; > > > > - sock =3D vq->private_data; > > + sock =3D vhost_vq_get_backend_opaque(vq); > > if (!sock) > > return 0; > > > > @@ -524,7 +524,7 @@ static void vhost_net_busy_poll(struct vhost_net *n= et, > > return; > > > > vhost_disable_notify(&net->dev, vq); > > - sock =3D rvq->private_data; > > + sock =3D vhost_vq_get_backend_opaque(rvq); > > > > busyloop_timeout =3D poll_rx ? rvq->busyloop_timeout: > > tvq->busyloop_timeout; > > @@ -570,8 +570,10 @@ static int vhost_net_tx_get_vq_desc(struct vhost_n= et *net, > > > > if (r =3D=3D tvq->num && tvq->busyloop_timeout) { > > /* Flush batched packets first */ > > - if (!vhost_sock_zcopy(tvq->private_data)) > > - vhost_tx_batch(net, tnvq, tvq->private_data, msgh= dr); > > + if (!vhost_sock_zcopy(vhost_vq_get_backend_opaque(tvq))) > > + vhost_tx_batch(net, tnvq, > > + vhost_vq_get_backend_opaque(tvq), > > + msghdr); > > > > vhost_net_busy_poll(net, rvq, tvq, busyloop_intr, false); > > > > @@ -685,7 +687,7 @@ static int vhost_net_build_xdp(struct vhost_net_vir= tqueue *nvq, > > struct vhost_virtqueue *vq =3D &nvq->vq; > > struct vhost_net *net =3D container_of(vq->dev, struct vhost_net, > > dev); > > - struct socket *sock =3D vq->private_data; > > + struct socket *sock =3D vhost_vq_get_backend_opaque(vq); > > struct page_frag *alloc_frag =3D &net->page_frag; > > struct virtio_net_hdr *gso; > > struct xdp_buff *xdp =3D &nvq->xdp[nvq->batched_xdp]; > > @@ -952,7 +954,7 @@ static void handle_tx(struct vhost_net *net) > > struct socket *sock; > > > > mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_TX); > > - sock =3D vq->private_data; > > + sock =3D vhost_vq_get_backend_opaque(vq); > > if (!sock) > > goto out; > > > > @@ -1121,7 +1123,7 @@ static void handle_rx(struct vhost_net *net) > > int recv_pkts =3D 0; > > > > mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_RX); > > - sock =3D vq->private_data; > > + sock =3D vhost_vq_get_backend_opaque(vq); > > if (!sock) > > goto out; > > > > @@ -1344,9 +1346,9 @@ static struct socket *vhost_net_stop_vq(struct vh= ost_net *n, > > container_of(vq, struct vhost_net_virtqueue, vq); > > > > mutex_lock(&vq->mutex); > > - sock =3D vq->private_data; > > + sock =3D vhost_vq_get_backend_opaque(vq); > > vhost_net_disable_vq(n, vq); > > - vq->private_data =3D NULL; > > + vhost_vq_set_backend_opaque(vq, NULL); > > vhost_net_buf_unproduce(nvq); > > nvq->rx_ring =3D NULL; > > mutex_unlock(&vq->mutex); > > @@ -1528,7 +1530,7 @@ static long vhost_net_set_backend(struct vhost_ne= t *n, unsigned index, int fd) > > } > > > > /* start polling new socket */ > > - oldsock =3D vq->private_data; > > + oldsock =3D vhost_vq_get_backend_opaque(vq); > > if (sock !=3D oldsock) { > > ubufs =3D vhost_net_ubuf_alloc(vq, > > sock && vhost_sock_zcopy(soc= k)); > > @@ -1538,7 +1540,7 @@ static long vhost_net_set_backend(struct vhost_ne= t *n, unsigned index, int fd) > > } > > > > vhost_net_disable_vq(n, vq); > > - vq->private_data =3D sock; > > + vhost_vq_set_backend_opaque(vq, sock); > > vhost_net_buf_unproduce(nvq); > > r =3D vhost_vq_init_access(vq); > > if (r) > > @@ -1575,7 +1577,7 @@ static long vhost_net_set_backend(struct vhost_ne= t *n, unsigned index, int fd) > > return 0; > > > > err_used: > > - vq->private_data =3D oldsock; > > + vhost_vq_set_backend_opaque(vq, oldsock); > > vhost_net_enable_vq(n, vq); > > if (ubufs) > > vhost_net_ubuf_put_wait_and_free(ubufs); > > diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h > > index a123fd70847e..0808188f7e8f 100644 > > --- a/drivers/vhost/vhost.h > > +++ b/drivers/vhost/vhost.h > > @@ -244,6 +244,34 @@ enum { > > (1ULL << VIRTIO_F_VERSION_1) > > }; > > > > +/** > > + * vhost_vq_set_backend_opaque - Set backend opaque. > > + * > > + * @vq Virtqueue. > > + * @private_data The private data. > > + * > > + * Context: Need to call with vq->mutex acquired. > > + */ > > +static inline void vhost_vq_set_backend_opaque(struct vhost_virtqueue = *vq, > > + void *private_data) > > +{ > > + vq->private_data =3D private_data; > > +} > > + > > +/** > > + * vhost_vq_get_backend_opaque - Get backend opaque. > > + * > > + * @vq Virtqueue. > > + * @private_data The private data. > > + * > > + * Context: Need to call with vq->mutex acquired. > > + * Return: Opaque previously set with vhost_vq_set_backend_opaque. > > > I prefer opaque -> private data in comments. > Changing. v3 sent. Thanks! > > + */ > > > > > > +static inline void *vhost_vq_get_backend_opaque(struct vhost_virtqueue= *vq) > > +{ > > + return vq->private_data; > > +} > > + > > static inline bool vhost_has_feature(struct vhost_virtqueue *vq, int b= it) > > { > > return vq->acked_features & (1ULL << bit); > > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c > > index c2d7d57e98cf..6e20dbe14acd 100644 > > --- a/drivers/vhost/vsock.c > > +++ b/drivers/vhost/vsock.c > > @@ -91,7 +91,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock= , > > > > mutex_lock(&vq->mutex); > > > > - if (!vq->private_data) > > + if (!vhost_vq_get_backend_opaque(vq)) > > goto out; > > > > /* Avoid further vmexits, we're already processing the virtqueue = */ > > @@ -440,7 +440,7 @@ static void vhost_vsock_handle_tx_kick(struct vhost= _work *work) > > > > mutex_lock(&vq->mutex); > > > > - if (!vq->private_data) > > + if (!vhost_vq_get_backend_opaque(vq)) > > goto out; > > > > vhost_disable_notify(&vsock->dev, vq); > > @@ -533,8 +533,8 @@ static int vhost_vsock_start(struct vhost_vsock *vs= ock) > > goto err_vq; > > } > > > > - if (!vq->private_data) { > > - vq->private_data =3D vsock; > > + if (!vhost_vq_get_backend_opaque(vq)) { > > + vhost_vq_set_backend_opaque(vq, vsock); > > ret =3D vhost_vq_init_access(vq); > > if (ret) > > goto err_vq; > > @@ -547,14 +547,14 @@ static int vhost_vsock_start(struct vhost_vsock *= vsock) > > return 0; > > > > err_vq: > > - vq->private_data =3D NULL; > > + vhost_vq_set_backend_opaque(vq, NULL); > > mutex_unlock(&vq->mutex); > > > > for (i =3D 0; i < ARRAY_SIZE(vsock->vqs); i++) { > > vq =3D &vsock->vqs[i]; > > > > mutex_lock(&vq->mutex); > > - vq->private_data =3D NULL; > > + vhost_vq_set_backend_opaque(vq, NULL); > > mutex_unlock(&vq->mutex); > > } > > err: > > @@ -577,7 +577,7 @@ static int vhost_vsock_stop(struct vhost_vsock *vso= ck) > > struct vhost_virtqueue *vq =3D &vsock->vqs[i]; > > > > mutex_lock(&vq->mutex); > > - vq->private_data =3D NULL; > > + vhost_vq_set_backend_opaque(vq, NULL); > > mutex_unlock(&vq->mutex); > > } > > > > -- > > 2.18.1 >