From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id B27C61B857 for ; Fri, 8 Feb 2019 04:44:24 +0100 (CET) Received: by mail-pf1-f195.google.com with SMTP id m6so1020741pfa.9 for ; Thu, 07 Feb 2019 19:44:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/MqK8UDStPd5wVP8rUHvet3+T9Mv+3+WkMrG6pNWrmw=; b=Gk+7GKfz66pU0wtSjr15KPy1ku0ALl1ltEuhoEoTYhVYyG/5lRyHnu6LAiIIET3K8k XoNOapN3YMtbHbXQvLwjlLtaOesufSOUQKcOsEKcAaYDdVddufoIufgByYS2y3zLMf+6 8rjM74TJEHupsD9yFLQ9NOEUvXss8L+K0reHY/TW0+yvlrUXlMJbmqUyKXq2s70qxW7I GQqJvinBDSw939T7Vpvw+Z6NY4lXSoc31pe+OtrQi7heHdDntuBm7dn/5nqrvI7n2IAj ksYg4eeT7f1EFfkRPa8g1DrKW55DOobJnnKfFHwq8j4CtziKohbsrH7SD/Q0Kya/vERk teJw== 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=/MqK8UDStPd5wVP8rUHvet3+T9Mv+3+WkMrG6pNWrmw=; b=IOgEirdjlU+riEa09x0T5GZCjAeEPYcFRa/5/jTk9komWxKgv9ZH/cNp1YoZuu5hN/ 1BIoyihpU7xVmYjAr6lvKm4sEU9jRJFaICEcZ5TsIAoBEjstb4/eiPAP2fH4t9DPA7Hv uST9faaMSXbytiIbcuvpj1IrXi5JYrU3Pnep4VKNkSSSgtsMweuCjbfleVhhnVY3CB+W JLVRnX+1mXZ1wex7zE+rou6/dTIUuW+Fr+MaBnHZXecsDTVdQfhjjk2VZqocUhHlbdLX ct4OlvFXtl53kCOyT022bNAO+k8oAOffNL3Wy4I3wNgtT3Bd2uwVp1jTxLECn/eqYPBO EBXQ== X-Gm-Message-State: AHQUAuYDVdAATvEQsUDTo5FjVEgQbVihSPV3pwQbOaSQ2OUClPn1AdKU 5QsHMVDikchglvU6jmRxuE2jIWcMPX4= X-Google-Smtp-Source: AHgI3IZ5OLhHfa88s9YvWXKbgcFyoYLJQeeG7vAK7gH6fzN0zArmWTpSgkGpR8+w7dyt8Rd76g/3zg== X-Received: by 2002:a62:1112:: with SMTP id z18mr19782175pfi.173.1549597463847; Thu, 07 Feb 2019 19:44:23 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id i4sm873275pfj.82.2019.02.07.19.44.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Feb 2019 19:44:23 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: stable@dpdk.org, Stephen Hemminger Date: Thu, 7 Feb 2019 19:44:06 -0800 Message-Id: <20190208034407.7865-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190208034407.7865-1-stephen@networkplumber.org> References: <20190208034407.7865-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] [PATCH 6/7] bus/vmbus: refactor secondary mapping 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: Fri, 08 Feb 2019 03:44:25 -0000 From: Stephen Hemminger The secondary mapping function was duplicating the code used to search the uio_resource list. Skip the unwinding since map failure already makes device unusable. Signed-off-by: Stephen Hemminger --- drivers/bus/vmbus/vmbus_common_uio.c | 132 ++++++++++++--------------- 1 file changed, 58 insertions(+), 74 deletions(-) diff --git a/drivers/bus/vmbus/vmbus_common_uio.c b/drivers/bus/vmbus/vmbus_common_uio.c index 9947f82ab194..1aa5cb2e4b92 100644 --- a/drivers/bus/vmbus/vmbus_common_uio.c +++ b/drivers/bus/vmbus/vmbus_common_uio.c @@ -23,79 +23,82 @@ static struct rte_tailq_elem vmbus_tailq = { }; EAL_REGISTER_TAILQ(vmbus_tailq) -static int -vmbus_uio_map_secondary(struct rte_vmbus_device *dev) +struct mapped_vmbus_resource * +vmbus_uio_find_resource(const struct rte_vmbus_device *dev) { - int fd, i; - struct vmbus_channel *chan; struct mapped_vmbus_resource *uio_res; - struct mapped_vmbus_res_list *uio_res_list - = RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list); + struct mapped_vmbus_res_list *uio_res_list = + RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list); + + if (dev == NULL) + return NULL; TAILQ_FOREACH(uio_res, uio_res_list, next) { + if (rte_uuid_compare(uio_res->id, dev->device_id) == 0) + return uio_res; + } + return NULL; +} - /* skip this element if it doesn't match our UUID */ - if (rte_uuid_compare(uio_res->id, dev->device_id) != 0) - continue; +static int +vmbus_uio_map_secondary(struct rte_vmbus_device *dev) +{ + struct mapped_vmbus_resource *uio_res; + struct vmbus_channel *chan; + int fd, i; - /* open /dev/uioX */ - fd = open(uio_res->path, O_RDWR); - if (fd < 0) { - VMBUS_LOG(ERR, "Cannot open %s: %s", - uio_res->path, strerror(errno)); - return -1; - } + uio_res = vmbus_uio_find_resource(dev); + if (!uio_res) { + VMBUS_LOG(ERR, "Cannot find resource for device"); + return -1; + } - for (i = 0; i != uio_res->nb_maps; i++) { - void *mapaddr; - off_t offset = i * PAGE_SIZE; + /* open /dev/uioX */ + fd = open(uio_res->path, O_RDWR); + if (fd < 0) { + VMBUS_LOG(ERR, "Cannot open %s: %s", + uio_res->path, strerror(errno)); + return -1; + } - mapaddr = vmbus_map_resource(uio_res->maps[i].addr, - fd, offset, - uio_res->maps[i].size, 0); + for (i = 0; i != uio_res->nb_maps; i++) { + void *mapaddr; + off_t offset = i * PAGE_SIZE; - if (mapaddr == uio_res->maps[i].addr) - continue; + mapaddr = vmbus_map_resource(uio_res->maps[i].addr, + fd, offset, + uio_res->maps[i].size, 0); - VMBUS_LOG(ERR, - "Cannot mmap device resource file %s to address: %p", - uio_res->path, uio_res->maps[i].addr); + if (mapaddr == uio_res->maps[i].addr) + continue; /* successful map */ - if (mapaddr != MAP_FAILED) - /* unmap addr wrongly mapped */ - vmbus_unmap_resource(mapaddr, - (size_t)uio_res->maps[i].size); + if (mapaddr == MAP_FAILED) + VMBUS_LOG(ERR, + "mmap resource %d in secondary failed", i); + else + VMBUS_LOG(ERR, + "mmap resource %d address mismatch", i); - /* unmap addrs correctly mapped */ - while (--i >= 0) - vmbus_unmap_resource(uio_res->maps[i].addr, - (size_t)uio_res->maps[i].size); + close(fd); + return -1; + } - close(fd); - return -1; - } + /* fd is not needed in slave process, close it */ + close(fd); - /* fd is not needed in slave process, close it */ - close(fd); + dev->primary = uio_res->primary; + if (!dev->primary) { + VMBUS_LOG(ERR, "missing primary channel"); + return -1; + } - dev->primary = uio_res->primary; - if (!dev->primary) { - VMBUS_LOG(ERR, "missing primary channel"); + STAILQ_FOREACH(chan, &dev->primary->subchannel_list, next) { + if (vmbus_uio_map_secondary_subchan(dev, chan) != 0) { + VMBUS_LOG(ERR, "cannot map secondary subchan"); return -1; } - - STAILQ_FOREACH(chan, &dev->primary->subchannel_list, next) { - if (vmbus_uio_map_secondary_subchan(dev, chan) != 0) { - VMBUS_LOG(ERR, "cannot map secondary subchan"); - return -1; - } - } - - return 0; } - - VMBUS_LOG(ERR, "Cannot find resource for device"); - return 1; + return 0; } static int @@ -136,25 +139,6 @@ vmbus_uio_map_primary(struct rte_vmbus_device *dev) return -1; } - -struct mapped_vmbus_resource * -vmbus_uio_find_resource(const struct rte_vmbus_device *dev) -{ - struct mapped_vmbus_resource *uio_res; - struct mapped_vmbus_res_list *uio_res_list = - RTE_TAILQ_CAST(vmbus_tailq.head, mapped_vmbus_res_list); - - if (dev == NULL) - return NULL; - - TAILQ_FOREACH(uio_res, uio_res_list, next) { - /* skip this element if it doesn't match our VMBUS address */ - if (rte_uuid_compare(uio_res->id, dev->device_id) == 0) - return uio_res; - } - return NULL; -} - /* map the VMBUS resource of a VMBUS device in virtual memory */ int vmbus_uio_map_resource(struct rte_vmbus_device *dev) -- 2.20.1