From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 996A72BA3 for ; Tue, 1 May 2018 12:46:44 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id 94-v6so9160930wrf.5 for ; Tue, 01 May 2018 03:46:44 -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=ZhXlSxr0VvAmktsJy6JG7BJhw+yxvIr0L1pi39s/tJs=; b=Hb3hY2wM5XwedZqh/TxEifUi1ODhbOtQ3wQlRxOzq9z+LLfZVPexJAu8CZlOeQZx3V 3uLdIAMQ1hpBbruElhM6sviCzk5UYZYPFW5ZbOtX0GJDE0gLOWtu7SXY67NFEedDESmz QfFlCHyPlBA9JHY4rxh5JWI423DMhYu2e/C0YkfV4hWAv4dQ6xPH6LVZuG5Q1TfDZXkE c5XmchBlRynyF/B9osZd9GaoE8IbNP7Ulc2yLm1hosZKLffn5OxU/99RJgc4/NMxQqoz BGDfLfvKTZh8gEu/5pXbl4X9MYNqLZ3tIVxoUHpiJAR9HaFjtQrmDnmknTvXo7aDQgb8 7N/g== 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=ZhXlSxr0VvAmktsJy6JG7BJhw+yxvIr0L1pi39s/tJs=; b=AID9IVTywZisu5Obx/8p5UwafqSx/TMM2OBMTrWhiM3ETiUPBmfKB+41D1ZCsT0Ig1 +Zxwq70PYw2MMMmtyx5xuHVDD2gGMpSelyNtqq8kjIk3iwg7cb7ixNTF0FlXPKyeASi3 wNDTczmcKw0dkaj0VpxO5+p481rUKHM7wlLzYuzdY7GckELfyfxwkM3Y5jfdh4MyaRXv MW+34Sf9IuKwEDyRzpN4H2gE8ILao3YRzN+oYkjmJU01bwcrXE4e6zU/IiLXmo4AwicC mEYsdo6ZwG55hVqcgqCI3dv1uCyHNX5njOdqx0C4WP1tXjssiMAbHmAJ2e9+sHHNVQwD NtOA== X-Gm-Message-State: ALQs6tDjFpVdNXoKZHBt83UFDrst3ROGOuPZ3BIT+aQo8abOWg1XcLaA bhwpefOqwhmZIcb5TOEIDIc= X-Google-Smtp-Source: AB8JxZogPGMOESlc7KUG16hbWRRAJ1sX2fgCMdnS9cbPeXTRvSlMECw8cOaErgjmKMxOXCHYeAgOow== X-Received: by 2002:adf:a925:: with SMTP id u34-v6mr12569807wrc.248.1525171604286; Tue, 01 May 2018 03:46:44 -0700 (PDT) Received: from localhost (slip139-92-244-193.lon.uk.prserv.net. [139.92.244.193]) by smtp.gmail.com with ESMTPSA id f6-v6sm2833319wrj.66.2018.05.01.03.46.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 May 2018 03:46:43 -0700 (PDT) From: luca.boccassi@gmail.com To: Tomasz Kulasek Cc: Ziye Yang , Jianfeng Tan , Maxime Coquelin , dpdk stable Date: Tue, 1 May 2018 11:44:31 +0100 Message-Id: <20180501104509.17238-8-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180501104509.17238-1-luca.boccassi@gmail.com> References: <20180501104509.17238-1-luca.boccassi@gmail.com> Subject: [dpdk-stable] patch 'vhost: fix realloc failure' has been queued to LTS release 16.11.7 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: Tue, 01 May 2018 10:46:44 -0000 Hi, FYI, your patch has been queued to LTS release 16.11.7 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/03/18. So please shout if anyone has objections. Thanks. Luca Boccassi --- >>From 3654b73cef9cf96ab0ea6716ae324e684f61ce10 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 0d30f11ef..aa5ed096d 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -421,7 +421,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) { @@ -431,6 +431,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) { @@ -439,7 +443,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; } } @@ -447,9 +451,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 virtio_memory_region *reg, uint64_t page_size) { @@ -463,7 +469,9 @@ add_guest_pages(struct virtio_net *dev, struct virtio_memory_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; @@ -472,12 +480,16 @@ add_guest_pages(struct virtio_net *dev, struct virtio_memory_region *reg, size = RTE_MIN(reg_size, page_size); host_phys_addr = rte_mem_virt2phy((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 @@ -624,7 +636,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