From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 737962B92; Fri, 24 Nov 2017 19:08:53 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9846C049D4E; Fri, 24 Nov 2017 18:08:52 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3523F648C1; Fri, 24 Nov 2017 18:08:44 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, yliu@fridaylinux.org, tiwei.bie@intel.com, jianfeng.tan@intel.com, vkaplans@redhat.com Cc: stable@dpdk.org, jfreiman@redhat.com, Maxime Coquelin Date: Fri, 24 Nov 2017 19:08:26 +0100 Message-Id: <20171124180826.18439-4-maxime.coquelin@redhat.com> In-Reply-To: <20171124180826.18439-1-maxime.coquelin@redhat.com> References: <20171124180826.18439-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 Nov 2017 18:08:52 +0000 (UTC) Subject: [dpdk-dev] [PATCH v2 3/3] vhost: don't invalidate vrings if new addresses are identical X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Nov 2017 18:08:53 -0000 In VHOST_USER_SET_VRING_ADDR handling, don't invalidate the vring if it has already been mapped and new addresses are identical. When initiating live-migration, VHOST_USER_SET_VRING_ADDR is sent again by QEMU, but the queues are enabled, so invalidating them can result in NULL pointer de-referencing. In this case, it is not needed to perform the invalidation, as the new addresses provided by QEMU are indentical to the initial ones. Fixes: eefac9536a90 ("vhost: postpone device creation until rings are mapped") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 4b03dbbca..29a431687 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -436,6 +436,14 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) return dev; } +static int +is_same_vring_addrs(struct vhost_vring_addr *a1, struct vhost_vring_addr *a2) +{ + return ((a1->desc_user_addr == a2->desc_user_addr) && + (a1->used_user_addr == a2->used_user_addr) && + (a1->avail_user_addr == a2->avail_user_addr)); +} + /* * The virtio device sends us the desc, used and avail ring addresses. * This function then converts these to our address space. @@ -453,6 +461,13 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[msg->payload.addr.index]; + /* + * If it is trying to set the same rings addresses, don't invalidate as + * PMD threads might be using them. + */ + if (is_same_vring_addrs(addr, &vq->ring_addrs)) + return 0; + /* * Rings addresses should not be interpreted as long as the ring is not * started and enabled -- 2.14.3