From patchwork Fri Jul 13 10:11:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takeshi Yoshimura X-Patchwork-Id: 43012 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BAAB13237; Fri, 13 Jul 2018 12:11:53 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 56E492C36 for ; Fri, 13 Jul 2018 12:11:52 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id r5-v6so4813235pgv.0 for ; Fri, 13 Jul 2018 03:11:52 -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=RjhG/2DkHeKKKkyYMuRFYcMaa/+ADazvr7y6wle6Opo=; b=DSVgLbH3LsZEFNEhZJesjmKlH7yEEF2tLTaT2YrbuyvBENRj75mRhrS9tWO0WIHa9l y+Hk2aTKttcpJ4hY29ReA9a/Tlv+GGqHGCf435iestoocnLHjHz2TukTtAlcKXkFtr+O a7+oPSxZDuzus0TsDA6ZoHY76OVuXsqAYpxn3dHU+VjCr4cOwzLGa6FXqJrypFZsZAm4 PNoHsNsh8IowdYZR4LC3+M3/Y9niT0AiVz3j3Wipek19aCGPmiGus7HT59bN7tF81gtK iq4tYTPTf2/wvwku3XiGgzapzhbNpUN9wj1A50c+gZfC5b7g7BMCIYJM748KtJDr5HYn sr+A== 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=RjhG/2DkHeKKKkyYMuRFYcMaa/+ADazvr7y6wle6Opo=; b=LzmNfUXGtu7Kq13NivO3NS+RWStPXO0qsvUOi/odpZHyi4Lwih95EhQELBlRQMNe1k 1RTlz1LvmEz8nLdnMHJwfuK8LdMA1s9FByJ4LMrqxL9FBI3F9BzpbunDXv3cztleb+Ts ik8LYIqQXDSHymtZOdvv0w1LZBW5oaKJoCsumF31wNcfjZpFZSqLSmeevOoZJa+xu+Bf TQxkaEpIziBAFYW2RfAbeRULAi5p0OFwLCkT8/Vpkjz5Ok67FClcmshLyROJRsZ41X66 6hc85+LJNE3NpBTdVgzhrk5gQApFSFLwuGBXGqTKeIMS+fkT8eYH5VnCgJ5l8APMMy+y 3CLQ== X-Gm-Message-State: AOUpUlEOHMWTqD1mpz2LcjOjkLbEUSNI9wQVappxf0jlMVyRn3VHi84w OLFffDCuf3gzcOtsXeEonpI= X-Google-Smtp-Source: AAOMgpeZSUpftaXLIP2uZWdCSoBTVQtXST/j7JoRXrW0SqRPbcpBVRKYGmp77FaoZ5lgP+lpR1Wx6g== X-Received: by 2002:a62:4bc6:: with SMTP id d67-v6mr6315229pfj.175.1531476711531; Fri, 13 Jul 2018 03:11:51 -0700 (PDT) Received: from takeshi-no-air.dhcp.hakozaki.ibm.com (sg-fw-ice-redblue-p6.sagamino.jp.ibm.com. [203.141.91.15]) by smtp.gmail.com with ESMTPSA id j72-v6sm47833794pge.19.2018.07.13.03.11.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Jul 2018 03:11:50 -0700 (PDT) From: Takeshi Yoshimura To: Anatoly Burakov Cc: dev@dpdk.org, Takeshi Yoshimura Date: Fri, 13 Jul 2018 19:11:45 +0900 Message-Id: <20180713101145.4795-1-t.yoshimura8869@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180712030833.4887-1-t.yoshimura8869@gmail.com> References: <20180712030833.4887-1-t.yoshimura8869@gmail.com> Subject: [dpdk-dev] [PATCH v3] vfio: fix workaround of BAR0 mapping X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The workaround of BAR0 mapping gives up and immediately returns an error if it cannot map around the MSI-X. However, recent version of VFIO allows MSIX mapping (*). I fixed not to return immediately but try mapping. In old Linux, mmap just fails and returns the same error as the code before my fix . In recent Linux, mmap succeeds and this patch enables running DPDK in specific environments (e.g., ppc64le with HGST NVMe) (*): "vfio-pci: Allow mapping MSIX BAR", https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ commit/id=a32295c612c57990d17fb0f41e7134394b2f35f6 Fixes: 90a1633b2347 ("eal/linux: allow to map BARs with MSI-X tables") Signed-off-by: Takeshi Yoshimura --- Thanks, Anatoly. I updated the patch not to affect behaviors of older Linux and other environments as well as possible. This patch adds another chance to mmap BAR0. I noticed that the check at line 350 already includes the check of page size, so this patch does not fix the check. Regards, Takeshi drivers/bus/pci/linux/pci_vfio.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index aeeaa9ed8..eb9b8031d 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -348,24 +348,25 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, table_start &= PAGE_MASK; if (table_start == 0 && table_end >= bar->size) { - /* Cannot map this BAR */ - RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index); - bar->size = 0; - bar->addr = 0; - return 0; + /* Cannot map around this BAR, but try */ + RTE_LOG(DEBUG, EAL, + "Trying to map BAR%d that contains the MSI-X\n", + bar_index); + memreg[0].offset = bar->offset; + memreg[0].size = bar->size; + } else { + memreg[0].offset = bar->offset; + memreg[0].size = table_start; + memreg[1].offset = bar->offset + table_end; + memreg[1].size = bar->size - table_end; + + 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, + memreg[0].offset, memreg[0].size, + memreg[1].offset, memreg[1].size); } - - memreg[0].offset = bar->offset; - memreg[0].size = table_start; - memreg[1].offset = bar->offset + table_end; - memreg[1].size = bar->size - table_end; - - 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, - memreg[0].offset, memreg[0].size, - memreg[1].offset, memreg[1].size); } else { memreg[0].offset = bar->offset; memreg[0].size = bar->size;