DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Zhang, AlvinX" <alvinx.zhang@intel.com>
To: "Xia, Chenbo" <chenbo.xia@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: David Marchand <david.marchand@redhat.com>,
	Tal Shnaiderman <talshn@mellanox.com>,
	"Burakov, Anatoly" <anatoly.burakov@intel.com>,
	"thomas@monjalon.net" <thomas@monjalon.net>
Subject: Re: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource
Date: Thu, 9 Jul 2020 05:13:53 +0000	[thread overview]
Message-ID: <SN6PR11MB29607F6D22C26D2FD2F1EE0B9F640@SN6PR11MB2960.namprd11.prod.outlook.com> (raw)
In-Reply-To: <MN2PR11MB4063A9376C7FFFC772C2C1909C670@MN2PR11MB4063.namprd11.prod.outlook.com>

Hi Chenbo,

Thanks your comments.

> -----Original Message-----
> From: Xia, Chenbo <chenbo.xia@intel.com>
> Sent: Wednesday, July 8, 2020 9:58 PM
> To: Zhang, AlvinX <alvinx.zhang@intel.com>; dev@dpdk.org
> Cc: Xing, Beilei <beilei.xing@intel.com>; Guo, Jia <jia.guo@intel.com>; David
> Marchand <david.marchand@redhat.com>; Tal Shnaiderman
> <talshn@mellanox.com>; Burakov, Anatoly <anatoly.burakov@intel.com>;
> thomas@monjalon.net
> Subject: RE: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource
> 
> Hi Alvin,
> 
> CC the maintainers. Comments below.
> 
> > -----Original Message-----
> > From: dev <dev-bounces@dpdk.org> On Behalf Of alvinx.zhang@intel.com
> > Sent: Wednesday, July 8, 2020 5:25 PM
> > To: dev@dpdk.org
> > Cc: Xing, Beilei <beilei.xing@intel.com>; Guo, Jia <jia.guo@intel.com>
> > Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource
> >
> > From: Alvin Zhang <alvinx.zhang@intel.com>
> >
> > 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 <alvinx.zhang@intel.com>
> > ---
> >  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;
> > +		}
> 
> I'm not sure if this corner case will happen. If you confirmed it, Just ignore this.

In theory, it is entirely possible if the misx-table size is equal to the bar size.

> 
> >  	} 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;
> > +
> 
> I see the issue that this patch wants to fix is based on an old kernel.
> In older vfio-pci kernel module, MSI related reg cannot be mmaped in userspace
> while in newer kernel it can be. That's why sometimes it cannot be reproduced
> (https://bugs.dpdk.org/show_bug.cgi?id=503)
> 
> So under the condition of old kernel, there could be an example that Memreg 0
> has size 0 but Memreg 1 has non-zero size, which leads to Memreg 1 cannot be
> mmaped.

Yes, it is.

> 
> So I'm fine with this part of code change. As this issue is blocking test, we should
> do fast confirm and review.
> 
> Thanks,
> Chenbo
> 
> >  		if (memreg[0].size) {
> >  			/* actual map of first part */
> >  			map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
> > --
> > 1.8.3.1


  reply	other threads:[~2020-07-09  5:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08  9:24 alvinx.zhang
2020-07-08  9:38 ` David Marchand
2020-07-08 13:58 ` Xia, Chenbo
2020-07-09  5:13   ` Zhang, AlvinX [this message]
2020-07-09  5:21     ` Xia, Chenbo
2020-07-09  2:25 ` Xiao, QimaiX
2020-07-10  9:54 ` David Marchand
2020-07-10 10:07   ` Thomas Monjalon
2020-07-10 12:31     ` Thomas Monjalon
2020-07-10 12:43     ` [dpdk-dev] [dpdk-ci] " Lincoln Lavoie
2020-09-23  7:34     ` [dpdk-dev] " David Marchand
2020-07-11  6:57   ` Zhang, AlvinX

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SN6PR11MB29607F6D22C26D2FD2F1EE0B9F640@SN6PR11MB2960.namprd11.prod.outlook.com \
    --to=alvinx.zhang@intel.com \
    --cc=anatoly.burakov@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=talshn@mellanox.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).