From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E569BA04F3 for ; Thu, 19 Dec 2019 15:38:08 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BF60A1BFBD; Thu, 19 Dec 2019 15:38:08 +0100 (CET) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by dpdk.org (Postfix) with ESMTP id 4EAA11BFB9 for ; Thu, 19 Dec 2019 15:38:07 +0100 (CET) Received: by mail-wm1-f68.google.com with SMTP id f4so7185079wmj.1 for ; Thu, 19 Dec 2019 06:38:07 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=w4unIH0h1s5MzjgI8Wt9HUUH3iqY/1w3Yaal5/Q3YbI=; b=PvXTYqMBYoElHsDDT083xwkciGMrYu2lAP//JGxdANJEGQgT4Ey7VIfmB9wFu8WuDi 0LfbTEcew8NjfBIrnwBHfyXVsOHRhnNJpgGzuygKkBtGgC2iL9qpcCdrP/6jYVsT75q5 ruaifIIx5FTrLtB8FVnyCWQbqkx4U1eddhD2y8OIJCmVx/Srbs+UCugGsqVZyzNtzBKk IkfIjTH7cAT1ie2KA0EiHw9SI5IXAMh28Xx3cDi6vJH14i/gsl910ovlW2fThGC21Vzw 5tztjtx6TBMnEZ+Ud+WqRAFENG78r9UzY7fGcq6ggjUBO3UbxjDUTXdcFqP0XZlEX9AC i+4w== 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:mime-version:content-transfer-encoding; bh=w4unIH0h1s5MzjgI8Wt9HUUH3iqY/1w3Yaal5/Q3YbI=; b=SRpnoA+Wq2gFqPZ/WjwtN6fgHzNi0/AtMtky5BhMdxHiz3jG76KW4WN7axPUZiWsF7 ++79J9xGvXsBe3MQrIPILje0Un8OECqnodiWzpkBtHGbyS5iJKnhj1sDmOc77mPuIbpG R/Z5JjetbItkS/cSWoODx6QpUFCy37N/nPYpIFp2js+19ip6tReHR11hUA0BmXySOnSS 3RTliPDJq7RirNONt/GE7dtTP4cUjZQ5mfNxIROaVAa9X+c/dpBQnUGpuJCC6vKm09sK Ws+MjVVHRjORFyufySeewteBgvl+br6VTwKC7HRgA/ap0b0l5Ymc75l8Ck1AWRNfIM5Z tKTw== X-Gm-Message-State: APjAAAVEU3uyzhaPfuAsHUOl+IQneMzBGNFd+UUl/ZFqMhyCjhXn1fOp iKjWllAgic8oY7VeU1abT3jCdIE246o= X-Google-Smtp-Source: APXvYqxmR84YcNbPParAbZ3pGxz7cZFa5n4K/yq4Gf2gZbqW0Q6xKU/eFNi+T38AjuOUOObslYc9ww== X-Received: by 2002:a1c:1b15:: with SMTP id b21mr9734631wmb.17.1576766287033; Thu, 19 Dec 2019 06:38:07 -0800 (PST) Received: from localhost ([88.98.246.218]) by smtp.gmail.com with ESMTPSA id f207sm7219279wme.9.2019.12.19.06.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2019 06:38:06 -0800 (PST) From: luca.boccassi@gmail.com To: Michal Krawczyk Cc: Anatoly Burakov , dpdk stable Date: Thu, 19 Dec 2019 14:33:47 +0000 Message-Id: <20191219143447.21506-80-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191219143447.21506-1-luca.boccassi@gmail.com> References: <20191219143447.21506-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'vfio: fix truncated BAR offset for 32-bit' has been queued to LTS release 17.11.10 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: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 17.11.10 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/21/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Luca Boccassi --- >From e19a6f68c34f091c9b7e814a722f25b8c4cb513b Mon Sep 17 00:00:00 2001 From: Michal Krawczyk Date: Thu, 24 Oct 2019 14:10:46 +0200 Subject: [PATCH] vfio: fix truncated BAR offset for 32-bit [ upstream commit 8108393d982b805ee4911c0d5cdfed53acec5d36 ] When 32-bit application is built on 64-bit system it is possible that the offset of the resource is outside of the 32-bit value. The problem with the unsigned long is, that it is 32-bit and not 64-bit when using armhf compiler. Although the system is returning u64 value, we are losing it's value if it's higher than 32-bit in the conversion process. It can further cause mmap to fail due to offset being 0 or to map not intended memory region. To make it more portable, the uint64_t value is now being used for storing offset instead of unsigned long. The size of being 32-bit seems to be fine as the 32-bit application won't be able to access bigger memory and it is further converted to size_t anyway. But for better readability and to be consistent, it's type was changed to size_t as well. Fixes: 0205f873557c ("vfio: fix overflow of BAR region offset and size") Signed-off-by: Michal Krawczyk Acked-by: Anatoly Burakov --- drivers/bus/pci/linux/pci_vfio.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 5093265e56..98f2ec9b8e 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -356,7 +356,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, int bar_index, int additional_flags) { struct memreg { - unsigned long offset, size; + uint64_t offset; + size_t size; } memreg[2] = {}; void *bar_addr; struct pci_msix_table *msix_table = &vfio_res->msix_table; @@ -392,7 +393,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, RTE_LOG(DEBUG, EAL, "Trying to map BAR%d that contains the MSI-X " "table. Trying offsets: " - "0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index, + "0x%04" PRIx64 ":0x%04zx, 0x%04" PRIx64 ":0x%04zx\n", + bar_index, memreg[0].offset, memreg[0].size, memreg[1].offset, memreg[1].size); } else { @@ -417,8 +419,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, if (map_addr != MAP_FAILED && memreg[1].offset && memreg[1].size) { void *second_addr = RTE_PTR_ADD(bar_addr, - memreg[1].offset - - (uintptr_t)bar->offset); + (uintptr_t)(memreg[1].offset - + bar->offset)); map_addr = pci_map_resource(second_addr, vfio_dev_fd, memreg[1].offset, -- 2.20.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-12-19 14:32:29.548858558 +0000 +++ 0080-vfio-fix-truncated-BAR-offset-for-32-bit.patch 2019-12-19 14:32:26.185299412 +0000 @@ -1,8 +1,10 @@ -From 8108393d982b805ee4911c0d5cdfed53acec5d36 Mon Sep 17 00:00:00 2001 +From e19a6f68c34f091c9b7e814a722f25b8c4cb513b Mon Sep 17 00:00:00 2001 From: Michal Krawczyk Date: Thu, 24 Oct 2019 14:10:46 +0200 Subject: [PATCH] vfio: fix truncated BAR offset for 32-bit +[ upstream commit 8108393d982b805ee4911c0d5cdfed53acec5d36 ] + When 32-bit application is built on 64-bit system it is possible that the offset of the resource is outside of the 32-bit value. @@ -20,7 +22,6 @@ well. Fixes: 0205f873557c ("vfio: fix overflow of BAR region offset and size") -Cc: stable@dpdk.org Signed-off-by: Michal Krawczyk Acked-by: Anatoly Burakov @@ -29,10 +30,10 @@ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c -index faf2990a73..b8faa23f82 100644 +index 5093265e56..98f2ec9b8e 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c -@@ -451,7 +451,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, +@@ -356,7 +356,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, int bar_index, int additional_flags) { struct memreg { @@ -42,7 +43,7 @@ } memreg[2] = {}; void *bar_addr; struct pci_msix_table *msix_table = &vfio_res->msix_table; -@@ -504,7 +505,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, +@@ -392,7 +393,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, RTE_LOG(DEBUG, EAL, "Trying to map BAR%d that contains the MSI-X " "table. Trying offsets: " @@ -52,7 +53,7 @@ memreg[0].offset, memreg[0].size, memreg[1].offset, memreg[1].size); } else { -@@ -529,8 +531,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, +@@ -417,8 +419,8 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, if (map_addr != MAP_FAILED && memreg[1].offset && memreg[1].size) { void *second_addr = RTE_PTR_ADD(bar_addr,