bus/pci: fix mmap PCI resource
PATCH 1/1 bus/pci: fix mmap PCI resource
From: Alvin Zhang <[email protected]>
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.
--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/pci/linux/pci_vfio.c +11 -1
@@ -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 ; + } }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; +if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
Signature · 1 line
1.8.3.1
Quoted 8 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
From: Alvin Zhang <[email protected]>
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.
Quoted 4 lines
Fixes 2fd3567e5425 ("pci: use OS generic memory mapping functions")Signed-off-by Alvin Zhang <[email protected]>
I guess this had to do with:
https://bugs.dpdk.org/show_bug.cgi?id=503
Review please.
Signature · 1 line
David Marchand
Quoted 37 lines
--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +11
-2@@ -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 ; + } }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; +if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, --1.8.3.1
Hi Alvin,
CC the maintainers. Comments below.
Quoted 28 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, July 8, 2020 5:25 PM
To: [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceFrom: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +0
-0@@ -547,6 +547,14 @@ bar_index,
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c +8
-0memreg[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.
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 11 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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.
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
Quoted 5 lines
drivers/bus/pci/linux/pci_vfio.c +0
-1if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, --1.8.3.1
Hi Chenbo,
Thanks your comments.
Quoted 47 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Wednesday, July 8, 2020 9:58 PM
To: Zhang, AlvinX <[email protected]>; [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>; David Marchand <[email protected]>; Tal Shnaiderman <[email protected]>; Burakov, Anatoly <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceHi Alvin,
CC the maintainers. Comments below.
Quoted 33 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, July 8, 2020 5:25 PM
To: [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceFrom: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +2
-0@@ -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 ) {
Quoted 8 lines
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 6 lines
drivers/bus/pci/linux/pci_vfio.c +6
-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.
Quoted 18 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 12 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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)
Quoted 3 lines
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.
Quoted 12 lines
So I'm fine with this part of code change. As this issue is blocking test, we should do fast confirm and review.
Thanks,
ChenboQuoted 5 lines
drivers/bus/pci/linux/pci_vfio.c +0
-1if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, --1.8.3.1
Xia, Chenbo
Acked-byQuoted 92 lines
-----Original Message-----
From: Zhang, AlvinX <[email protected]>
Sent: Thursday, July 9, 2020 1:14 PM
To: Xia, Chenbo <[email protected]>; [email protected]
Cc: David Marchand <[email protected]>; Tal Shnaiderman <[email protected]>; Burakov, Anatoly <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceHi Chenbo,
Thanks your comments.
Quoted 48 lines
-----Original Message-----
From: Xia, Chenbo <[email protected]>
Sent: Wednesday, July 8, 2020 9:58 PM
To: Zhang, AlvinX <[email protected]>; [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>; David Marchand <[email protected]>; Tal Shnaiderman <[email protected]>; Burakov, Anatoly <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceHi Alvin,
CC the maintainers. Comments below.
Quoted 34 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, July 8, 2020 5:25 PM
To: [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceFrom: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +2
-0@@ -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 ) {Quoted 8 lines
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 6 lines
drivers/bus/pci/linux/pci_vfio.c +6
-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.
Quoted 19 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 12 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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)
Quoted 18 lines
Quoted 3 lines
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.
Quoted 12 lines
So I'm fine with this part of code change. As this issue is blocking test, we should do fast confirm and review.
Thanks,
ChenboQuoted 5 lines
drivers/bus/pci/linux/pci_vfio.c +0
-1if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, --1.8.3.1
Regards,
Xiao Qimai
Quoted 56 lines
-----Original Message-----
From: dev <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, July 8, 2020 5:25 PM
To: [email protected]
Cc: Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceFrom: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +8
-0@@ -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 ; + } }else { memreg[0 ].offset = bar->offset;drivers/bus/pci/linux/pci_vfio.c +3
-1memreg[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; +if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr,
vfio_dev_fd,
--
1.8.3.1
Quoted 22 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
From: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +0
-0@@ -547,6 +547,14 @@ bar_index,
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c +8
-0memreg[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?
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 11 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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.
Quoted 6 lines
drivers/bus/pci/linux/pci_vfio.c +0
-1if (memreg[0 ].size) {/* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, --1.8.3.1
Thanks.
Signature · 1 line
David Marchand
10/07/2020 11:54, David Marchand:
Quoted 7 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
Quoted 6 lines
From: Alvin Zhang <[email protected]>
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.
Note: this regression would not have happened if we had some CI tests for simple device probing.
Please let's invest more in CI.
Quoted 2 lines
Quoted 2 lines
Fixes 2fd3567e5425 ("pci: use OS generic memory mapping functions")
No he was not Cc in the thread. Same for Anatoly.
Adding more people in Cc...
Quoted 22 lines
Quoted 6 lines
Signed-off-by Alvin Zhang <[email protected]>---
drivers/bus/pci/linux/pci_vfio.c +0
-0@@ -547,6 +547,14 @@ bar_index,drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c +8
-0memreg[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?
Quoted 15 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 11 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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.
Yes, I am going to send a fix.
Quoted 1 line
We can cleanup this code later.
Yes please, this function isn't understandable and lack of comments. Anatoly please?
10/07/2020 12:07, Thomas Monjalon:
Quoted 8 lines
10/07/2020 11:54, David Marchand:
Quoted 7 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
Quoted 6 lines
From: Alvin Zhang <[email protected]>
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.
[...]
Quoted 36 lines
Quoted 20 lines
Quoted 4 lines
drivers/bus/pci/linux/pci_vfio.c +0
-0@@ -547,6 +547,14 @@ bar_index,drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c +8
-0memreg[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?Quoted 15 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 11 lines
drivers/bus/pci/linux/pci_vfio.c +3
-1}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.
Quoted 1 line
Yes, I am going to send a fix.
Patch sent: https://patches.dpdk.org/patch/73741/
This patch is marked as rejected, but please follow-up on cleanup.
Quoted 4 lines
Quoted 1 line
We can cleanup this code later.
Yes please, this function isn't understandable and lack of comments. Anatoly please?
Quoted 9 lines · Thomas Monjalon
10/07/2020 11:54, David Marchand:
Quoted 7 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
Quoted 6 lines
From: Alvin Zhang <[email protected]>
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.
Quoted 5 lines
Note: this regression would not have happened if we had some CI tests for simple device probing.
Please let's invest more in CI.Are you referring to adding tests to specifically check these conditions,
or would this have been caught just from the continued expansion of testing on real hardware / NICs, or both? It seems like the issue is caused by a combination of hardware behaviors and "broken code". My point is, without having some of those behaviors in the CI, we might still not have caught this issue, even with probing checks. Of course, more checks are always a good thing.
Quoted 56 lines
Quoted 3 lines
Quoted 3 lines
Fixes 2fd3567e5425 ("pci: use OS generic memory mapping functions")No he was not Cc in the thread. Same for Anatoly.
Adding more people in Cc...Quoted 4 lines
Quoted 4 lines
Signed-off-by Alvin Zhang <[email protected]>---
drivers/bus/pci/linux/pci_vfio.c +0
-0Quoted 8 lines
drivers/bus/pci/linux/pci_vfio.c line 553
Quoted 8 lines
drivers/bus/pci/linux/pci_vfio.c +4
-0@@ -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);Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 4 lines
drivers/bus/pci/linux/pci_vfio.c +4
-0+ 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?Quoted 9 lines
drivers/bus/pci/linux/pci_vfio.c line 567
Quoted 9 lines
drivers/bus/pci/linux/pci_vfio.c +1
-1}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 */
Quoted 6 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 2 lines
drivers/bus/pci/linux/pci_vfio.c +2
-0+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.Yes, I am going to send a fix.
Quoted 1 line
We can cleanup this code later.
Yes please, this function isn't understandable and lack of comments. Anatoly please?
Signature · 7 lines
*Lincoln Lavoie* Senior Engineer, Broadband Technologies 21 Madbury Rd., Ste. 100, Durham, NH 03824 [email protected] https://www.iol.unh.edu +1-603-674-2755 (m) <https://www.iol.unh.edu/>
Quoted 10 lines · Thomas Monjalon
Quoted 3 lines
It took me some time to understand this code...
Anyway, we have a regression in thelibrte_pci.
This is where the fix should be.Yes, I am going to send a fix.
Quoted 1 line
We can cleanup this code later.
Yes please, this function isn't understandable and lack of comments. Anatoly please?
Now that the workaround on the pci mapping API has been reverted, we are back with this issue.
https://bugs.dpdk.org/show_bug.cgi?id=539
Volunteer(s) to fix and clean this code?
Thanks.
Signature · 1 line
David Marchand
Quoted 39 lines
-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, July 10, 2020 5:54 PM
To: Zhang, AlvinX <[email protected]>
Cc: dev <[email protected]>; Xing, Beilei <[email protected]>; Guo, Jia <[email protected]>
Subject: Re: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resourceQuoted 22 lines · On Wed, Jul 8, 2020 at 11:26 AM <[email protected]> wrote:
From: Alvin Zhang <[email protected]>
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")Signed-off-by Alvin Zhang <[email protected]>--- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/bus/pci/linux/pci_vfio.c +0
-0drivers/bus/pci/linux/pci_vfio.c line 553
Quoted 7 lines
drivers/bus/pci/linux/pci_vfio.c +4
-0@@ -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);
Quoted 9 lines
drivers/bus/pci/linux/pci_vfio.c line 557
Quoted 4 lines
drivers/bus/pci/linux/pci_vfio.c +4
-0+ 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?
If the misx-table size is equal to the bar size, the memreg[0].size and memreg[1].size will be zero at same time although the bar size is not zero
Quoted 10 lines
drivers/bus/pci/linux/pci_vfio.c
Quoted 9 lines
drivers/bus/pci/linux/pci_vfio.c +0
-0}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) {drivers/bus/pci/linux/pci_vfio.c +1
-1-void *map_addr =NULL ; +/* Set non NULL initial value for in case of no PCI mapping */
Quoted 8 lines
drivers/bus/pci/linux/pci_vfio.c line 569
Quoted 2 lines
drivers/bus/pci/linux/pci_vfio.c +2
-0+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.
The key cause is the value of memreg[0].size is 0
Quoted 14 lines
Quoted 8 lines
if (memreg[0].size) { /* actual map of first part */ map_addr = pci_map_resource(bar_addr,
vfio_dev_fd,
--
1.8.3.1Thanks.
--
David Marchand