From patchwork Tue Mar 5 09:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 137984 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 378B443C51; Tue, 5 Mar 2024 10:13:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B9775402A8; Tue, 5 Mar 2024 10:13:44 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 9E04E4026B for ; Tue, 5 Mar 2024 10:13:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709630022; 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; bh=LtQDAA4ogcykHfzp4PzuKE4qvmA91/1ovlGa+rXB2Gw=; b=JrRolA7OCaDsgHPuLkkEqYnew4WaZRot9k6yGZjkRCxv1px0Sz0VGY/TPwDmQsQ1QhrxjR MvMc8V9aBD8QZV/ZYD/PqTYZYZI+3owGk23Mq8VB5RjbUXsKtPhFlSAOyfoSwlBu8H+41j FkFTPMoaMvJvTuEYOlMt4HeLfUq+3XI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-tCbmZtKsOkG_C2pCtUWOFQ-1; Tue, 05 Mar 2024 04:13:37 -0500 X-MC-Unique: tCbmZtKsOkG_C2pCtUWOFQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 604131C41A03; Tue, 5 Mar 2024 09:13:37 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F72F175AD; Tue, 5 Mar 2024 09:13:35 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: ssimma@nvidia.com, Maxime Coquelin , Chenbo Xia , Eelco Chaudron Subject: [PATCH] vhost: fix vring addr update with vDPA Date: Tue, 5 Mar 2024 10:13:25 +0100 Message-ID: <20240305091326.2697724-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 For vDPA devices, vq are not locked once the device has been configured at runtime. On the other hand, we need to hold the vq lock to evaluate vq->access_ok, invalidate vring addresses and translate them. Move vring address update earlier and, when vDPA is configured, skip parts which expect lock to be taken. Bugzilla ID: 1394 Fixes: 741dc052eaf9 ("vhost: annotate virtqueue access checks") Signed-off-by: David Marchand --- lib/vhost/vhost_user.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 3aba32c95a..7fe1687f08 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -986,17 +986,20 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[ctx->msg.payload.addr.index]; - /* vhost_user_lock_all_queue_pairs locked all qps */ - VHOST_USER_ASSERT_LOCK(dev, vq, VHOST_USER_SET_VRING_ADDR); - - access_ok = vq->access_ok; - /* * Rings addresses should not be interpreted as long as the ring is not * started and enabled */ memcpy(&vq->ring_addrs, addr, sizeof(*addr)); + if (dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) + goto out; + + /* vhost_user_lock_all_queue_pairs locked all qps */ + VHOST_USER_ASSERT_LOCK(dev, vq, VHOST_USER_SET_VRING_ADDR); + + access_ok = vq->access_ok; + vring_invalidate(dev, vq); if ((vq->enabled && (dev->features & @@ -1006,6 +1009,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, *pdev = dev; } +out: return RTE_VHOST_MSG_RESULT_OK; }