From patchwork Wed Mar 11 17:25:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 3976 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id E9FD59A91; Wed, 11 Mar 2015 18:25:30 +0100 (CET) Received: from mail-we0-f169.google.com (mail-we0-f169.google.com [74.125.82.169]) by dpdk.org (Postfix) with ESMTP id 2120E6A87 for ; Wed, 11 Mar 2015 18:25:29 +0100 (CET) Received: by wevk48 with SMTP id k48so10806896wev.7 for ; Wed, 11 Mar 2015 10:25:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=CWNtLdHvbUmP2+qWO9UPMrpK8d+BIp55mPH+16WWoeo=; b=FQ3c7/sCcU6d5Nlr2sdeEm8EKwcJZ7YGV0EWlOzTFIOz6/cNpi+/L00+zQwC7anfiu iu9sJqYCY++fnnkikYJQPeMoiyE8Ob11yN99oBBwmJD5OUlC2Mo09Wb3yXktywXpIErQ N4BNwRGjRm9iStbYoOQZzNUlDebyW710Uo99mgnZxsIetqpb0dChzoo7ifiT/S3da7On m2WJzN0NFOGIO+bbNCMbiVJXdgtu41NC1aRufNHhqmwuj3LPmNlzDRExccYtMGsk3nVQ /Zp4HBdFTOkt78F2MW6MZb1xs1+vOsxHWxoURC+GdEnCtrQMePs4iDSzwt59fND1JuXq WfTA== X-Gm-Message-State: ALoCoQlRc+VCT2wm26kzHFAojm/2Wm/UVXxhKPg7Nwu6Q19iTmf4x53Y4KsSALgxGYPVOEoj0ST5 X-Received: by 10.180.75.233 with SMTP id f9mr51460039wiw.5.1426094728912; Wed, 11 Mar 2015 10:25:28 -0700 (PDT) Received: from alcyon.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id fy2sm2195149wic.15.2015.03.11.10.25.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2015 10:25:26 -0700 (PDT) From: David Marchand To: dev@dpdk.org Date: Wed, 11 Mar 2015 18:25:23 +0100 Message-Id: <1426094723-18766-1-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 Subject: [dpdk-dev] [PATCH] eal: fix tailq init for uio/vfio resources X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Commit a2348166ea18 ("tailq: move to dynamic tailq") introduced a bug in uio/vfio resources list init. These resources list were pointed at through a pointer initialised only once but too early in the eal init (before tailqs init). Fix this by "resolving" this pointer when used (which is well after tailqs init). Fixes: a2348166ea18 ("tailq: move to dynamic tailq") Reported-by: Marvin Liu Reported-by: Tetsuya Mukawa Signed-off-by: David Marchand --- This patch is an alternative to the patch proposed by Marvin. It has been tested only on Linux and with uio driver. lib/librte_eal/bsdapp/eal/eal_pci.c | 11 +++++------ lib/librte_eal/linuxapp/eal/eal_pci.c | 8 -------- lib/librte_eal/linuxapp/eal/eal_pci_init.h | 1 - lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 17 +++++++++++++---- lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 11 +++++++++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 3a0fda5..fe3ef86 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -105,12 +105,10 @@ struct uio_resource { TAILQ_HEAD(uio_res_list, uio_resource); -static struct uio_res_list *uio_res_list = NULL; - -static struct rte_tailq_elem rte_pci_tailq = { - .name = "PCI_RESOURCE_LIST", +static struct rte_tailq_elem rte_uio_tailq = { + .name = "UIO_RESOURCE_LIST", }; -EAL_REGISTER_TAILQ(rte_pci_tailq) +EAL_REGISTER_TAILQ(rte_uio_tailq) /* unbind kernel driver for this device */ static int @@ -165,6 +163,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) { size_t i; struct uio_resource *uio_res; + struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list); TAILQ_FOREACH(uio_res, uio_res_list, next) { @@ -202,6 +201,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) uint64_t pagesz; struct rte_pci_addr *loc = &dev->addr; struct uio_resource *uio_res; + struct uio_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, uio_res_list); struct uio_map *maps; dev->intr_handle.fd = -1; @@ -497,7 +497,6 @@ rte_eal_pci_init(void) { TAILQ_INIT(&pci_driver_list); TAILQ_INIT(&pci_device_list); - uio_res_list = RTE_TAILQ_CAST(rte_pci_tailq.head, uio_res_list); /* for debug purposes, PCI can be disabled */ if (internal_config.no_pci) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index c42e843..83c589e 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -56,13 +56,6 @@ * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ -struct mapped_pci_res_list *pci_res_list = NULL; - -static struct rte_tailq_elem rte_pci_tailq = { - .name = "PCI_RESOURCE_LIST", -}; -EAL_REGISTER_TAILQ(rte_pci_tailq) - /* unbind kernel driver for this device */ static int pci_unbind_kernel_driver(struct rte_pci_device *dev) @@ -770,7 +763,6 @@ rte_eal_pci_init(void) { TAILQ_INIT(&pci_driver_list); TAILQ_INIT(&pci_device_list); - pci_res_list = RTE_TAILQ_CAST(rte_pci_tailq.head, mapped_pci_res_list); /* for debug purposes, PCI can be disabled */ if (internal_config.no_pci) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h index 6af84d1..aa7b755 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h +++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h @@ -58,7 +58,6 @@ struct mapped_pci_resource { }; TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource); -extern struct mapped_pci_res_list *pci_res_list; /* * Helper function to map PCI resources right after hugepages in virtual memory diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index ebbc2d3..2d1c69b 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -50,6 +51,10 @@ void *pci_map_addr = NULL; +static struct rte_tailq_elem rte_uio_tailq = { + .name = "UIO_RESOURCE_LIST", +}; +EAL_REGISTER_TAILQ(rte_uio_tailq) #define OFF_MAX ((uint64_t)(off_t)-1) @@ -87,8 +92,9 @@ pci_uio_map_secondary(struct rte_pci_device *dev) { int fd, i; struct mapped_pci_resource *uio_res; + struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); - TAILQ_FOREACH(uio_res, pci_res_list, next) { + TAILQ_FOREACH(uio_res, uio_res_list, next) { /* skip this element if it doesn't match our PCI address */ if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) @@ -266,6 +272,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) uint64_t phaddr; struct rte_pci_addr *loc = &dev->addr; struct mapped_pci_resource *uio_res; + struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); struct pci_map *maps; dev->intr_handle.fd = -1; @@ -382,7 +389,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) uio_res->nb_maps = map_idx; - TAILQ_INSERT_TAIL(pci_res_list, uio_res, next); + TAILQ_INSERT_TAIL(uio_res_list, uio_res, next); return 0; } @@ -405,11 +412,12 @@ static struct mapped_pci_resource * pci_uio_find_resource(struct rte_pci_device *dev) { struct mapped_pci_resource *uio_res; + struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); if (dev == NULL) return NULL; - TAILQ_FOREACH(uio_res, pci_res_list, next) { + TAILQ_FOREACH(uio_res, uio_res_list, next) { /* skip this element if it doesn't match our PCI address */ if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr)) @@ -423,6 +431,7 @@ void pci_uio_unmap_resource(struct rte_pci_device *dev) { struct mapped_pci_resource *uio_res; + struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); if (dev == NULL) return; @@ -436,7 +445,7 @@ pci_uio_unmap_resource(struct rte_pci_device *dev) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return pci_uio_unmap(uio_res); - TAILQ_REMOVE(pci_res_list, uio_res, next); + TAILQ_REMOVE(uio_res_list, uio_res, next); /* unmap all resources */ pci_uio_unmap(uio_res); diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c index 9b0c151..aea1fb1 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c @@ -64,6 +64,11 @@ #define PAGE_SIZE (sysconf(_SC_PAGESIZE)) #define PAGE_MASK (~(PAGE_SIZE - 1)) +static struct rte_tailq_elem rte_vfio_tailq = { + .name = "VFIO_RESOURCE_LIST", +}; +EAL_REGISTER_TAILQ(rte_vfio_tailq) + #define VFIO_DIR "/dev/vfio" #define VFIO_CONTAINER_PATH "/dev/vfio/vfio" #define VFIO_GROUP_FMT "/dev/vfio/%u" @@ -546,6 +551,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev) struct rte_pci_addr *loc = &dev->addr; int i, ret, msix_bar; struct mapped_pci_resource *vfio_res = NULL; + struct mapped_pci_res_list *vfio_res_list = RTE_TAILQ_CAST(rte_vfio_tailq.head, mapped_pci_res_list); + struct pci_map *maps; uint32_t msix_table_offset = 0; uint32_t msix_table_size = 0; @@ -700,7 +707,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev) VFIO_PCI_BAR5_REGION_INDEX + 1); } else { /* if we're in a secondary process, just find our tailq entry */ - TAILQ_FOREACH(vfio_res, pci_res_list, next) { + TAILQ_FOREACH(vfio_res, vfio_res_list, next) { if (memcmp(&vfio_res->pci_addr, &dev->addr, sizeof(dev->addr))) continue; break; @@ -854,7 +861,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev) } if (internal_config.process_type == RTE_PROC_PRIMARY) - TAILQ_INSERT_TAIL(pci_res_list, vfio_res, next); + TAILQ_INSERT_TAIL(vfio_res_list, vfio_res, next); return 0; }