From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 1384225D9 for ; Sun, 22 Apr 2018 17:10:44 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 7BCCC212DE; Sun, 22 Apr 2018 11:10:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 22 Apr 2018 11:10:43 -0400 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=fm2; bh=lCnBIY+VbcRyA9eIl 0lRFY3qz+48XYBZ7OlO8UU43Yg=; b=akz8VkgpicstLf4YD4w0/gf4hLZqgRxkH gGK/B56Zt7ABb+Ld2cuS0AAF0AiVA3mQfJXlvh8aRdZkj1VSuoHyizUSFFv1yT1P 2pFKgF6jICz6bJw4roXUjWh1g/N17birSsrYPPBeh0dHuJDy62Qcauko7Rs3fHp2 FNy/fuQoNtnVMweLMW8qEKtXGOe5C67k5KTiKNjZuW1D9C4YmCMjH+crQDQSIF8W rffPYPs4NuiZA/RPKM2fKTx3OacwsSATcXS7x+fPwKrKnxSl2zzFGQo5DHTLeHFj H0Ga6HDIKBknpsPk6N3nHCtpNEyTJ4kjRpmER9ABpGkZzOVZdoREw== 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= fm2; bh=lCnBIY+VbcRyA9eIl0lRFY3qz+48XYBZ7OlO8UU43Yg=; b=ER/3lbL7 c/QxI9zVlHfxAFjDSLmchu13X7XFxcFksYxckrZrEQ8ThQjIwH+mWvDeaAJ8yncj Q4uSX7L+fcH3g4guNC3yMqwn8YurfZlflAZcI9fk5it39DVmvPnH+Rm5muY6u67p zIugvAVtrHdpXwCuFeuAX8uB02NMTLmOefmPOowvBtxMiJauqh68+lQLR+xEMS+u lVlkMuoyxqkeZNXZ9DMF1DwBo5oqQ/sN7p/2M3LzEzr4/waHY2hPkiZPR1c7a3R3 /YyOkieMebW25Thqhhc9aM8IOKbN2oR2N1bxQ2oK/l8XlN0e5ERwUkaGi66/CyMv eN2Rz8hIOzeTsQ== X-ME-Sender: Received: from yuanhanliu-NB0.tencent.com (unknown [223.74.148.66]) by mail.messagingengine.com (Postfix) with ESMTPA id E2DCB10253; Sun, 22 Apr 2018 11:10:40 -0400 (EDT) From: Yuanhan Liu To: Tomasz Kulasek Cc: Ziye Yang , Jianfeng Tan , Maxime Coquelin , dpdk stable Date: Sun, 22 Apr 2018 23:09:02 +0800 Message-Id: <20180422150949.17523-12-yliu@fridaylinux.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180422150949.17523-1-yliu@fridaylinux.org> References: <20180422150949.17523-1-yliu@fridaylinux.org> Subject: [dpdk-stable] patch 'vhost: fix realloc failure' has been queued to LTS release 17.11.2 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: Sun, 22 Apr 2018 15:10:44 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 04/29/18. So please shout if anyone has objections. Thanks. --yliu --- >>From fc53c4750ed619bdf238e7616720cc2f1954eb15 Mon Sep 17 00:00:00 2001 From: Tomasz Kulasek Date: Fri, 9 Feb 2018 18:19:00 +0100 Subject: [PATCH] vhost: fix realloc failure [ upstream commit 7afa2e4538c1740391e40e018fb3ecafd53603cc ] When reallocation of guest pages fails, vhost_user_set_mem_table() also should fail. Fixes: e246896178e6 ("vhost: get guest/host physical address mappings") Signed-off-by: Ziye Yang Signed-off-by: Tomasz Kulasek Reviewed-by: Jianfeng Tan Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 02f219dc7..63f7d50ef 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -488,7 +488,7 @@ vhost_user_set_vring_base(struct virtio_net *dev, return 0; } -static void +static int add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, uint64_t host_phys_addr, uint64_t size) { @@ -498,6 +498,10 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, dev->max_guest_pages *= 2; dev->guest_pages = realloc(dev->guest_pages, dev->max_guest_pages * sizeof(*page)); + if (!dev->guest_pages) { + RTE_LOG(ERR, VHOST_CONFIG, "cannot realloc guest_pages\n"); + return -1; + } } if (dev->nr_guest_pages > 0) { @@ -506,7 +510,7 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, if (host_phys_addr == last_page->host_phys_addr + last_page->size) { last_page->size += size; - return; + return 0; } } @@ -514,9 +518,11 @@ add_one_guest_page(struct virtio_net *dev, uint64_t guest_phys_addr, page->guest_phys_addr = guest_phys_addr; page->host_phys_addr = host_phys_addr; page->size = size; + + return 0; } -static void +static int add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg, uint64_t page_size) { @@ -530,7 +536,9 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg, size = page_size - (guest_phys_addr & (page_size - 1)); size = RTE_MIN(size, reg_size); - add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size); + if (add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size) < 0) + return -1; + host_user_addr += size; guest_phys_addr += size; reg_size -= size; @@ -539,12 +547,16 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg, size = RTE_MIN(reg_size, page_size); host_phys_addr = rte_mem_virt2iova((void *)(uintptr_t) host_user_addr); - add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size); + if (add_one_guest_page(dev, guest_phys_addr, host_phys_addr, + size) < 0) + return -1; host_user_addr += size; guest_phys_addr += size; reg_size -= size; } + + return 0; } #ifdef RTE_LIBRTE_VHOST_DEBUG @@ -692,7 +704,12 @@ vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg) mmap_offset; if (dev->dequeue_zero_copy) - add_guest_pages(dev, reg, alignment); + if (add_guest_pages(dev, reg, alignment) < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "adding guest pages to region %u failed.\n", + i); + goto err_mmap; + } RTE_LOG(INFO, VHOST_CONFIG, "guest memory region %u, size: 0x%" PRIx64 "\n" -- 2.11.0