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 CB4FCA052A; Fri, 10 Jul 2020 11:54:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 83A6C1DCF6; Fri, 10 Jul 2020 11:54:17 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 884E72B9C for ; Fri, 10 Jul 2020 11:54:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594374856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=w153qHBf8nx8QpYHNKgwtvYcsz4iqgILU27yPlZlFIs=; b=WaaOAVf0SLCksN1fqR69wRnpdBHRRZCNm4sMVW4ZkvzIyT8D+J8YlTMfKkJ6+fo1isiLS1 84pgCExPeFftY1IZjk6+OsYHbYKx0TH5V4lC7fJjxmXL9zc6uw0uXyCdXHv/WWbmeBtz4P bZSxcvfWeu3wGhwZTGvsMvjC0YCyw3k= Received: from mail-ua1-f69.google.com (mail-ua1-f69.google.com [209.85.222.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-469-jVNoMTsXMp2IIe2HnG_FGg-1; Fri, 10 Jul 2020 05:54:14 -0400 X-MC-Unique: jVNoMTsXMp2IIe2HnG_FGg-1 Received: by mail-ua1-f69.google.com with SMTP id l2so2255701uae.19 for ; Fri, 10 Jul 2020 02:54:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w153qHBf8nx8QpYHNKgwtvYcsz4iqgILU27yPlZlFIs=; b=F1C/FmXyHWy5lc3Ab/eY8pfYgF0z08egajnvaxrTPzi87fE7yLLZD6dG+3vqASvk0+ Ovw7S5gRUrMT1/PpKux01Yci8CYqEvN0IwuRhl+MZIHxBmdQ4+SypmQQ4hy18FZh9Y+S vIJD8BQngb9npEVwnOp795JHDvXATrG+JQBj7LENmtfHJWxDrhG/LY81tAR0tGUSDFK3 QKwcdUSwjyZJydXs8kQDjdkR8RXpkl9W8u9ryGI2nghzFz67eRGm40NJZyx6Jqa7xm+j k6YhEBLQuExU729Fn0SRf8T+qjLTgNbXXo62ec8PqmrK47Oe5r+pzzkCH7Tw6cPM4Fzj MBYw== X-Gm-Message-State: AOAM532YcBRwf0zSf0xoLc3NneNWXWIbXw75sy75gVXSko8xytUaRMiu /PcKgZSF4pJ2a8ipDV1MLfvo1O0lgLt6oZOoHndkspmb+R5DlENdkTmFpiHW5Kalmyxqu73bCKj DcCXpxvGPZsW21w9ScOs= X-Received: by 2002:a1f:acc2:: with SMTP id v185mr12598401vke.18.1594374853795; Fri, 10 Jul 2020 02:54:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqcoCOAt8Nh3Hj8BeyDCghgxsXcuMdM7pwUNWUhg5xZMV1RiyIhbcPX6+Z3SKl29b+iM0mfVkTbENCE7Xcl4I= X-Received: by 2002:a1f:acc2:: with SMTP id v185mr12598388vke.18.1594374853402; Fri, 10 Jul 2020 02:54:13 -0700 (PDT) MIME-Version: 1.0 References: <20200708092435.9776-1-alvinx.zhang@intel.com> In-Reply-To: <20200708092435.9776-1-alvinx.zhang@intel.com> From: David Marchand Date: Fri, 10 Jul 2020 11:54:02 +0200 Message-ID: To: "Zhang, AlvinX" Cc: dev , Beilei Xing , Jeff Guo X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource 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" On Wed, Jul 8, 2020 at 11:26 AM wrote: > > From: Alvin Zhang > > When mapping a PCI BAR containing an MSI-X table, some devices do not > need to actually map this BAR or only need to map part of them, which > may cause the mapping to fail. Now some checks are added and a non-NULL > initial value is set to the variable to avoid this situation. > > Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions") > Cc: talshn@mellanox.com > > Signed-off-by: Alvin Zhang > --- > drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c > index fdeb9a8..9143bfc 100644 > --- a/drivers/bus/pci/linux/pci_vfio.c > +++ b/drivers/bus/pci/linux/pci_vfio.c > @@ -547,6 +547,14 @@ > bar_index, > memreg[0].offset, memreg[0].size, > memreg[1].offset, memreg[1].size); > + > + if (memreg[0].size == 0 && memreg[1].size == 0) { > + /* No need to map this BAR */ > + RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index); > + bar->size = 0; > + bar->addr = 0; > + return 0; > + } We already have a check on bar size == 0. Why would we have this condition? Broken hw? > } else { > memreg[0].offset = bar->offset; > memreg[0].size = bar->size; > @@ -556,7 +564,9 @@ > bar_addr = mmap(bar->addr, bar->size, 0, MAP_PRIVATE | > MAP_ANONYMOUS | additional_flags, -1, 0); > if (bar_addr != MAP_FAILED) { > - void *map_addr = NULL; > + /* Set non NULL initial value for in case of no PCI mapping */ > + void *map_addr = bar_addr; > + It took me some time to understand this code... Anyway, we have a regression in the librte_pci. This is where the fix should be. We can cleanup this code later. > if (memreg[0].size) { > /* actual map of first part */ > map_addr = pci_map_resource(bar_addr, vfio_dev_fd, > -- > 1.8.3.1 > Thanks. -- David Marchand