From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D436843214; Fri, 27 Oct 2023 11:03:42 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BFDD54029A; Fri, 27 Oct 2023 11:03:42 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 6AFFD40272 for ; Fri, 27 Oct 2023 11:03:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698397421; 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=lEts2wpLZdPYy6A+WtqizhLKs5ys8zDKB8cYyaq1KuQ=; b=HkBNY0J6NwoaJD4ESGxyBYKrBtr5NNs7oSNs/Na9C2oqKvdkHIhLWgwZdWgFJsCdcJdUwY hoNH8sz1n2mfqx1mAY/s/e8G0gfIJHiWbDnZLthgZVGEhpOZauybR/9znYlfpa/dVHaL5B oZ2gui1Nww1cTLPrx5He08TGEAbtlaI= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-8-5fBp66NNKK1MrvO4npzA-1; Fri, 27 Oct 2023 05:03:39 -0400 X-MC-Unique: 8-5fBp66NNKK1MrvO4npzA-1 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-9b2cf504e3aso125937966b.2 for ; Fri, 27 Oct 2023 02:03:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698397418; x=1699002218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V9ulTm6ah5ZGGRgwvpdlmiIXOKGaPs66q1qSxykHA3E=; b=TFQL2iwv7OE2jOeaQ/5Um2tmiLMPT942XfDJpyXsBd67oHuZOHLCQG2g09cLEnnGbm 3Uu1Yw2krd1GS5MeFcHZnL8G/QvB7AAx7AcBDwefb6Pyj1okoxw3P+HJSQpSnMlT8ba0 1U/MvLjKuiUYSkGXUsI/peMYMuBAjS+/3AqeM+zmgmUnIstlLjna9JCDyVoMmormTVEr pVXOsnQgSiR1Sgc+N3J6LVF0+rHcdHBed0E4xWsFp3cGliSsNrsgSyMJQJZoIxsc1BHA irG4ZkJeWevxxqE9NpS9740Nuz0ELePvuC69KZgGUTxncfXjYer4oVMPb2syusXRZau5 iIIA== X-Gm-Message-State: AOJu0Yz+M+cm1eCzeSUqiJEz6aMgfsNip1j/HO1EFRgytKCDs3cJIqqh UQ66uFHUTnGUGfnA5MTbzJwjiJ59Elmj34e4s/LfhXV/0CvXsneO7EdggSTKm8Ns7cCi1pJOsD1 1cVI= X-Received: by 2002:a17:907:7d93:b0:9ae:53a2:4289 with SMTP id oz19-20020a1709077d9300b009ae53a24289mr1686002ejc.63.1698397418250; Fri, 27 Oct 2023 02:03:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEss9DWkulHzZHCD1o5Rret1jq0iD/7ilg90BRk6oxunEEoZnweLoVLuIaGeAXeqvVkdgyEVA== X-Received: by 2002:a17:907:7d93:b0:9ae:53a2:4289 with SMTP id oz19-20020a1709077d9300b009ae53a24289mr1685984ejc.63.1698397417867; Fri, 27 Oct 2023 02:03:37 -0700 (PDT) Received: from [172.16.2.75] (5920ab7b.static.cust.trined.nl. [89.32.171.123]) by smtp.gmail.com with ESMTPSA id oy29-20020a170907105d00b009b29553b648sm861123ejb.206.2023.10.27.02.03.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Oct 2023 02:03:36 -0700 (PDT) From: Eelco Chaudron To: David Marchand Cc: dev@dpdk.org, stable@dpdk.org, Maxime Coquelin , Chenbo Xia Subject: Re: [PATCH 2/3] vhost: fix virtqueue access lock in datapath Date: Fri, 27 Oct 2023 11:03:34 +0200 X-Mailer: MailMate (1.14r5964) Message-ID: <76029D4A-DA8B-4CE9-ACFC-0B7D5BFF8512@redhat.com> In-Reply-To: <20231023095520.2864868-2-david.marchand@redhat.com> References: <20231023095520.2864868-1-david.marchand@redhat.com> <20231023095520.2864868-2-david.marchand@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 23 Oct 2023, at 11:55, David Marchand wrote: > Now that a r/w lock is used, the access_ok field should only be updated > under a write lock. > > Since the datapath code only takes a read lock on the virtqueue to check > access_ok, this lock must be released and a write lock taken before > calling vring_translate(). > > Fixes: 03f77d66d966 ("vhost: change virtqueue access lock to a read/write= one") > Cc: stable@dpdk.org > > Signed-off-by: David Marchand Only one question, but whatever the outcome is the change looks good to me. Acked-by: Eelco Chaudron > --- > lib/vhost/virtio_net.c | 60 +++++++++++++++++++++++++++++++----------- > 1 file changed, 44 insertions(+), 16 deletions(-) > > diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c > index 759a78e3e3..4116f79d4f 100644 > --- a/lib/vhost/virtio_net.c > +++ b/lib/vhost/virtio_net.c > @@ -1694,6 +1694,17 @@ virtio_dev_rx_packed(struct virtio_net *dev, > =09return pkt_idx; > } > > +static void > +virtio_dev_vring_translate(struct virtio_net *dev, struct vhost_virtqueu= e *vq) > +{ Would it be an idea to annotate this function that it needs to be called wi= th the =E2=80=9Cread locks=E2=80=9D (and that it will free them) to avoid t= he duplicate: +=09=09vhost_user_iotlb_rd_unlock(vq); +=09=09rte_rwlock_read_unlock(&vq->access_lock); > +=09rte_rwlock_write_lock(&vq->access_lock); > +=09vhost_user_iotlb_rd_lock(vq); > +=09if (!vq->access_ok) > +=09=09vring_translate(dev, vq); > +=09vhost_user_iotlb_rd_unlock(vq); > +=09rte_rwlock_write_unlock(&vq->access_lock); > +} > + > static __rte_always_inline uint32_t > virtio_dev_rx(struct virtio_net *dev, struct vhost_virtqueue *vq, > =09struct rte_mbuf **pkts, uint32_t count) > @@ -1708,9 +1719,13 @@ virtio_dev_rx(struct virtio_net *dev, struct vhost= _virtqueue *vq, > > =09vhost_user_iotlb_rd_lock(vq); > > -=09if (unlikely(!vq->access_ok)) > -=09=09if (unlikely(vring_translate(dev, vq) < 0)) > -=09=09=09goto out; > +=09if (unlikely(!vq->access_ok)) { > +=09=09vhost_user_iotlb_rd_unlock(vq); > +=09=09rte_rwlock_read_unlock(&vq->access_lock); > + > +=09=09virtio_dev_vring_translate(dev, vq); > +=09=09goto out_no_unlock; > +=09} > > =09count =3D RTE_MIN((uint32_t)MAX_PKT_BURST, count); > =09if (count =3D=3D 0) > @@ -1729,6 +1744,7 @@ virtio_dev_rx(struct virtio_net *dev, struct vhost_= virtqueue *vq, > out_access_unlock: > =09rte_rwlock_read_unlock(&vq->access_lock); > > +out_no_unlock: > =09return nb_tx; > } > > @@ -2523,9 +2539,13 @@ virtio_dev_rx_async_submit(struct virtio_net *dev,= struct vhost_virtqueue *vq, > > =09vhost_user_iotlb_rd_lock(vq); > > -=09if (unlikely(!vq->access_ok)) > -=09=09if (unlikely(vring_translate(dev, vq) < 0)) > -=09=09=09goto out; > +=09if (unlikely(!vq->access_ok)) { > +=09=09vhost_user_iotlb_rd_unlock(vq); > +=09=09rte_rwlock_read_unlock(&vq->access_lock); > + > +=09=09virtio_dev_vring_translate(dev, vq); > +=09=09goto out_no_unlock; > +=09} > > =09count =3D RTE_MIN((uint32_t)MAX_PKT_BURST, count); > =09if (count =3D=3D 0) > @@ -2546,6 +2566,7 @@ virtio_dev_rx_async_submit(struct virtio_net *dev, = struct vhost_virtqueue *vq, > out_access_unlock: > =09rte_rwlock_write_unlock(&vq->access_lock); > > +out_no_unlock: > =09return nb_tx; > } > > @@ -3576,11 +3597,13 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_i= d, > > =09vhost_user_iotlb_rd_lock(vq); > > -=09if (unlikely(!vq->access_ok)) > -=09=09if (unlikely(vring_translate(dev, vq) < 0)) { > -=09=09=09count =3D 0; > -=09=09=09goto out; > -=09=09} > +=09if (unlikely(!vq->access_ok)) { > +=09=09vhost_user_iotlb_rd_unlock(vq); > +=09=09rte_rwlock_read_unlock(&vq->access_lock); > + > +=09=09virtio_dev_vring_translate(dev, vq); > +=09=09goto out_no_unlock; > +=09} > > =09/* > =09 * Construct a RARP broadcast packet, and inject it to the "pkts" > @@ -3641,6 +3664,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id, > =09if (unlikely(rarp_mbuf !=3D NULL)) > =09=09count +=3D 1; > > +out_no_unlock: > =09return count; > } > > @@ -4190,11 +4214,14 @@ rte_vhost_async_try_dequeue_burst(int vid, uint16= _t queue_id, > > =09vhost_user_iotlb_rd_lock(vq); > > -=09if (unlikely(vq->access_ok =3D=3D 0)) > -=09=09if (unlikely(vring_translate(dev, vq) < 0)) { > -=09=09=09count =3D 0; > -=09=09=09goto out; > -=09=09} > +=09if (unlikely(vq->access_ok =3D=3D 0)) { > +=09=09vhost_user_iotlb_rd_unlock(vq); > +=09=09rte_rwlock_read_unlock(&vq->access_lock); > + > +=09=09virtio_dev_vring_translate(dev, vq); > +=09=09count =3D 0; > +=09=09goto out_no_unlock; > +=09} > > =09/* > =09 * Construct a RARP broadcast packet, and inject it to the "pkts" > @@ -4260,5 +4287,6 @@ rte_vhost_async_try_dequeue_burst(int vid, uint16_t= queue_id, > =09if (unlikely(rarp_mbuf !=3D NULL)) > =09=09count +=3D 1; > > +out_no_unlock: > =09return count; > } > --=20 > 2.41.0