From mboxrd@z Thu Jan 1 00:00:00 1970 From: Maxime Coquelin Subject: [PATCH v2 3/3] vhost: don't invalidate vrings if new addresses are identical Date: Fri, 24 Nov 2017 19:08:26 +0100 Message-ID: <20171124180826.18439-4-maxime.coquelin@redhat.com> References: <20171124180826.18439-1-maxime.coquelin@redhat.com> Cc: stable@dpdk.org, jfreiman@redhat.com, Maxime Coquelin To: dev@dpdk.org, yliu@fridaylinux.org, tiwei.bie@intel.com, jianfeng.tan@intel.com, vkaplans@redhat.com Return-path: In-Reply-To: <20171124180826.18439-1-maxime.coquelin@redhat.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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