From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id 42B46187 for ; Mon, 30 Apr 2018 16:07:27 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id c14-v6so8170624wrd.4 for ; Mon, 30 Apr 2018 07:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YEqwVbPK8fvk8YxxeJxuLKDaL7xDFkfKaqQjyjvJ2Ck=; b=uX8Wx47UolVzxEV8faFXHxkjdi/m+By6gvgIF3MlK8+VAzpf25Sn4jNe/slSKjDjsv TPM8+Xe+LL71W1EOEJ4sylOKPGxQ030lRAAlYbzWeLW5xRRVI32hzdADniZmX0mzxLYJ dF9F/HVNZwiK7iHJZFxhBzroSk2qHaOfkJP33iOISUrEXGIzlYBTbMNdv+Zt7rIx9eiq mH2B654v5JJfJ18Y055UOjD3NqnlKiTFTWrSwcf/YIJDLqfunjpaJh3j0mIu3osdsMws r23oFA45upwYFMPS0/nBrDHYfyziuGBnDd7DnbbEm5a2ERW9PoXKtHIm+MQLx9yes9bm TLew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YEqwVbPK8fvk8YxxeJxuLKDaL7xDFkfKaqQjyjvJ2Ck=; b=YXK+O25KNMPh4xsW2ieOGbEWOX+6WHRxw82HsrpejBubOSwH7xtZRg21FN1+8L6nvv EEApOOFqePZxtEFMj+GLhxTFv/rZQ3UQwATRTS5IYyCBEFckOM3sZbIw3nKc/JF0W0mK 1WlmqeHwVYd3afU0obUBQEIYzbGMxD2rML2oAlCLPeTBl2FD+XStkEvqIgalgBIxO2/A B8VSJwUKHKNeKrb+K7p11QQGZccc70eEcOhEst5C/QRPrxQzXziQuxrsjdU2hI1XQdbQ zqk2mzMbgVG7+s4J7idNh4MzH2KwimtWV+u1G/u8EnZjq82/gYjVk2W1gzRvBOMSPbU1 dvMQ== X-Gm-Message-State: ALQs6tDHTBKYDOr2Xe1reQTfWT6rmbUiPtYgHJuTduWxMkSWj3fhf1Bp T/i9EcLbOULFdYxLPiLfXXU= X-Google-Smtp-Source: AB8JxZpNRJHqz2sk8XHugd6Wo1igsT8VZSbSjcsjoRz9gkWFsddwNIs1krh0rrI4iotRwl1AQQD4pA== X-Received: by 2002:adf:a673:: with SMTP id k106-v6mr9615421wrc.231.1525097246959; Mon, 30 Apr 2018 07:07:26 -0700 (PDT) Received: from localhost ([2a00:23c5:be9a:5200:ce4c:82c0:d567:ecbb]) by smtp.gmail.com with ESMTPSA id m18sm5790549wma.23.2018.04.30.07.07.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Apr 2018 07:07:26 -0700 (PDT) From: luca.boccassi@gmail.com To: Tomasz Kulasek Cc: Ziye Yang , Jianfeng Tan , Maxime Coquelin , dpdk stable Date: Mon, 30 Apr 2018 15:03:17 +0100 Message-Id: <20180430140606.4615-39-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180430140606.4615-1-luca.boccassi@gmail.com> References: <20180430140606.4615-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'vhost: fix realloc failure' has been queued to stable release 18.02.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: Mon, 30 Apr 2018 14:07:27 -0000 Hi, FYI, your patch has been queued to stable release 18.02.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 05/02/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From 0cd76d1a5aaf92c491dfa844a5f64ca17fde800d 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 995cf4203..d2ca7b4e7 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -538,7 +538,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) { @@ -548,6 +548,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) { @@ -556,7 +560,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; } } @@ -564,9 +568,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) { @@ -580,7 +586,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; @@ -589,12 +597,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 @@ -742,7 +754,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.14.2