From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id A887D1B1B0 for ; Wed, 24 Jan 2018 16:38:49 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5C85F2269A; Wed, 24 Jan 2018 10:38:49 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Wed, 24 Jan 2018 10:38:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fridaylinux.org; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=YrzZldu9gfgd8p/EI ibv6gy+qelTINFZpH+LupBwXo0=; b=gFwAD147ty+553NyPZNpruyUd5MdbUIZL w98LNc8emND/Q/pvcIH2nYG5OMbDEKAeHHc/+Rb9MDvZK7PD2Cm4zY7hTxWsCaEU rcgV7B7JzqZ0fUhgFwOuFatxaWv/30qibaOkssXyC2u/24UxOx6VVmVM1CtV0+Jt h1H7UNf6mwVrQnVHfaElaNp+yWatcaokcal1xHggn5GW0e98QsOMPLbFKmzu+4Wc fnde6oD8Wsgy0yfOu7tUJ4ZPSAyJgr2Ffp2nQaLZP26AKXzQ+1A6aV1WGRCOyvD0 Ks0RIv4N4yfgtg17BKTTF7K+dSfnv2NuZluifwcntc1D5ejPKh8rw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=YrzZldu9gfgd8p/EIibv6gy+qelTINFZpH+LupBwXo0=; b=SglVQtNM BdrMbizXuRHMT4ZKGFwNPIXyAMCofOWMj8gn0COq/1oj1o1nwt2yuLHc9ozCjlfI YMN2VhCZjCkUuCymPUKLDR3Y+zvlcX0CH6WU809dIvJy/fxvi/edZCePIFv34HlC +qjZau5/prQZUTx/ofWP6anu8saA99qShg914WKlvTnR3Ql+Yy3MoNjOEf3NwrHd O57B990H9i2pbXlbaSV3QPjBwDrGzFgthyduyp6203JWfSoI+nlgko+pDmBjY44M 3PnXuVI3Kj5WxQBK5Y7vNH6O/Xy9UbKtJdQeTLuoQ7+p1/F7uPzEoHdkryiyhIS4 xt2lHp2lD+JjxQ== X-ME-Sender: Received: from localhost.localdomain (unknown [115.150.27.206]) by mail.messagingengine.com (Postfix) with ESMTPA id B9B907E448; Wed, 24 Jan 2018 10:38:45 -0500 (EST) From: Yuanhan Liu To: Jianfeng Tan Cc: Yang Zhang , Xin Long , Yi Yang , Maxime Coquelin , Yuanhan Liu , dpdk stable Date: Wed, 24 Jan 2018 23:32:14 +0800 Message-Id: <1516808026-25523-66-git-send-email-yliu@fridaylinux.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516808026-25523-1-git-send-email-yliu@fridaylinux.org> References: <1516808026-25523-1-git-send-email-yliu@fridaylinux.org> Subject: [dpdk-stable] patch 'vhost: fix crash' has been queued to LTS release 17.11.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jan 2018 15:38:49 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 01/26/18. So please shout if anyone has objections. Thanks. --yliu --- >>From e1fd3c6f9e695da2e74a939bba129b92a0d09d95 Mon Sep 17 00:00:00 2001 From: Jianfeng Tan Date: Wed, 15 Nov 2017 11:41:08 +0000 Subject: [PATCH] vhost: fix crash [ upstream commit cab278dee9290ee48062576b09d21e6c1eb0214b ] In a running VM, operations (like device attach/detach) will trigger the QEMU to resend set_mem_table to vhost-user backend. DPDK vhost-user handles this message rudely by unmap all existing regions and map new ones. This might lead to segfault if there is pmd thread just trying to touch those unmapped memory regions. But for most cases, except VM memory hotplug, QEMU still sends the set_mem_table message even the memory regions are not changed as QEMU vhost-user filters out those not backed by file (fd > 0). To fix this case, we add a check in the handler to see if the memory regions are really changed; if not, we just keep old memory regions. Fixes: 8f972312b8f4 ("vhost: support vhost-user") Reported-by: Yang Zhang Reported-by: Xin Long Signed-off-by: Yi Yang Signed-off-by: Jianfeng Tan Reviewed-by: Maxime Coquelin Acked-by: Yuanhan Liu --- lib/librte_vhost/vhost_user.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index f4c7ce4..6f3869c 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -573,6 +573,30 @@ dump_guest_pages(struct virtio_net *dev) #define dump_guest_pages(dev) #endif +static bool +vhost_memory_changed(struct VhostUserMemory *new, + struct rte_vhost_memory *old) +{ + uint32_t i; + + if (new->nregions != old->nregions) + return true; + + for (i = 0; i < new->nregions; ++i) { + VhostUserMemoryRegion *new_r = &new->regions[i]; + struct rte_vhost_mem_region *old_r = &old->regions[i]; + + if (new_r->guest_phys_addr != old_r->guest_phys_addr) + return true; + if (new_r->memory_size != old_r->size) + return true; + if (new_r->userspace_addr != old_r->guest_user_addr) + return true; + } + + return false; +} + static int vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) { @@ -585,6 +609,16 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) uint32_t i; int fd; + if (dev->mem && !vhost_memory_changed(&memory, dev->mem)) { + RTE_LOG(INFO, VHOST_CONFIG, + "(%d) memory regions not changed\n", dev->vid); + + for (i = 0; i < memory.nregions; i++) + close(pmsg->fds[i]); + + return 0; + } + if (dev->mem) { free_mem_region(dev); rte_free(dev->mem); -- 2.7.4