windows/netuio: fix bar parsing
For certain PCIe devices, BAR values are not continuous. This patch maps all the BARs and avoids skipping the next BAR addresses.
--- windows/netuio/netuio_dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
windows/netuio/netuio_dev.c +4 -1
@@ -172,6 +172,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST RULONG next_descriptor =0 ;ULONG curr_bar =0 ;ULONG prev_bar =0 ; +BOOLEAN bar_done = FALSE;/* * ResourcesTranslated report MMIO BARs in the correct order, but their
@@ -197,7 +198,8 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST Rfor (INT bar_index =0 ; bar_index <PCI_MAX_BAR ; bar_index++) { prev_bar = curr_bar; curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +if (curr_bar ==0 || ((prev_bar &PCI_TYPE_64BIT ) && (bar_done))) { + bar_done = FALSE;continue ; }
@@ -219,6 +221,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R ctx->bar[bar_index].virt_addr =MmMapIoSpace (descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached); + bar_done = TRUE;if (ctx->bar[bar_index].virt_addr ==NULL ) { status =STATUS_INSUFFICIENT_RESOURCES ; goto end;
Signature · 1 line
2.31.1.windows.1
2022-08-02 12:10 (UTC-0700), Pallavi Kadam:
Quoted 35 lines
For certain PCIe devices, BAR values are not continuous. This patch maps all the BARs and avoids skipping the next BAR addresses.
Fixes e28aabd88279 ("windows/netuio: introduce NetUIO kernel driver")Signed-off-by Qiao Liu <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>--- windows/netuio/netuio_dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)windows/netuio/netuio_dev.c +3
-1@@ -172,6 +172,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST RULONG next_descriptor =0 ;ULONG curr_bar =0 ;ULONG prev_bar =0 ; +BOOLEAN bar_done = FALSE;/* * ResourcesTranslated report MMIO BARs in the correct order, but their @@ -197,7 +198,8 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST Rfor (INT bar_index =0 ; bar_index <PCI_MAX_BAR ; bar_index++) { prev_bar = curr_bar; curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +if (curr_bar ==0 || ((prev_bar &PCI_TYPE_64BIT ) && (bar_done))) { + bar_done = FALSE;continue ; }
windows/netuio/netuio_dev.c netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R · line 227
Quoted 7 lines
windows/netuio/netuio_dev.c +1
-0@@ -219,6 +221,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R ctx->bar[bar_index].virt_addr =MmMapIoSpace (descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached); + bar_done = TRUE;if (ctx->bar[bar_index].virt_addr ==NULL ) { status =STATUS_INSUFFICIENT_RESOURCES ; goto end;
Hi Pallavi,
In the first place, it was wrong to always test prev_bar & PCI_TYPE_64BIT because only the first BAR slot of a 64-bit BAR contains flags. The current code has a state to track (curr_bar, prev_bar),
and the fix is complicating it even more without solving the root cause. I suggest a simpler fix (not tested!)
that eliminates both the incorrectness and the state to maintain:
windows/netuio/netuio_dev.c +0 -0
@@ -273,8 +273,6 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST
Resources, WDFCMRESLIST R
PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor;
ULONG next_descriptor = 0;- ULONG curr_bar = 0;
- ULONG prev_bar = 0;
/*
* ResourcesTranslated report MMIO BARs in the correct order, but their
@@ -298,9 +296,9 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R
* searching for the next MMIO resource each time.
*/
for (INT bar_index = 0; bar_index < PCI_MAX_BAR; bar_index++) {
- prev_bar = curr_bar;
- curr_bar = pci_config.u.type0.BaseAddresses[bar_index];
- if (curr_bar == 0 || (prev_bar & PCI_TYPE_64BIT)) {
+ ULONG bar_value = pci_config.u.type0.BaseAddresses[bar_index];
+
+ if (bar_value == 0) {
continue;
}@@ -339,6 +337,11 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R
}
ctx->dpdk_hw[bar_index].mem.size = ctx->bar[bar_index].size;+
+ // Skip the next BAR slot used by the current 64-bit address.
+ if (bar_value & PCI_TYPE_64BIT) {
+ bar_index++;
+ }
} // for bar_index
end_of_loop:
Hi Dmitry,
Quoted 45 lines · Dmitry Kozlyuk
2022-08-02 12:10 (UTC-0700), Pallavi Kadam:
Quoted 35 lines
For certain PCIe devices, BAR values are not continuous. This patch maps all the BARs and avoids skipping the next BAR addresses.
Fixes e28aabd88279 ("windows/netuio: introduce NetUIO kernel driver")Signed-off-by Qiao Liu<[email protected]>Signed-off-by Pallavi Kadam<[email protected]>--- windows/netuio/netuio_dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)windows/netuio/netuio_dev.c +3
-1@@ -172,6 +172,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST RULONG next_descriptor =0 ;ULONG curr_bar =0 ;ULONG prev_bar =0 ; +BOOLEAN bar_done = FALSE;/* * ResourcesTranslated report MMIO BARs in the correct order, but their @@ -197,7 +198,8 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST Rfor (INT bar_index =0 ; bar_index <PCI_MAX_BAR ; bar_index++) { prev_bar = curr_bar; curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +if (curr_bar ==0 || ((prev_bar &PCI_TYPE_64BIT ) && (bar_done))) { + bar_done = FALSE;continue ; }windows/netuio/netuio_dev.c netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R · line 227
Quoted 7 lines
windows/netuio/netuio_dev.c +1
-0@@ -219,6 +221,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R ctx->bar[bar_index].virt_addr =MmMapIoSpace (descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached); + bar_done = TRUE;if (ctx->bar[bar_index].virt_addr ==NULL ) { status =STATUS_INSUFFICIENT_RESOURCES ; goto end;Hi Pallavi,
Quoted 6 lines
In the first place, it was wrong to always test
prev_bar & PCI_TYPE_64BITbecause only the first BAR slot of a 64-bit BAR contains flags. The current code has a state to track (curr_bar,prev_bar),
and the fix is complicating it even more without solving the root cause. I suggest a simpler fix (not tested!)
that eliminates both the incorrectness and the state to maintain:
Thank you for these changes. Will test the patch and let you know.
Quoted 41 lines
windows/netuio/netuio_dev.c +0
-0@@ -273,8 +273,6 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor; ULONG next_descriptor = 0;windows/netuio/netuio_dev.c +0
-2-ULONG curr_bar =0 ; -ULONG prev_bar =0 ;/* * ResourcesTranslated report MMIO BARs in the correct order, but their @@ -298,9 +296,9 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
* searching for the next MMIO resource each time. */ for (INT bar_index = 0; bar_index < PCI_MAX_BAR; bar_index++) {windows/netuio/netuio_dev.c +3
-3- prev_bar = curr_bar; - curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +ULONG bar_value = pci_config.u.type0.BaseAddresses[bar_index]; + +if (bar_value ==0 ) {continue ; }@@ -339,6 +337,11 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
} ctx->dpdk_hw[bar_index].mem.size = ctx->bar[bar_index].size;windows/netuio/netuio_dev.c +5
-0+ +// Skip the next BAR slot used by the current 64-bit address. +if (bar_value &PCI_TYPE_64BIT ) { + bar_index++; + } }// for bar_index end_of_loop:
Hi Dmitry,
Quoted 45 lines · Dmitry Kozlyuk
2022-08-02 12:10 (UTC-0700), Pallavi Kadam:
Quoted 35 lines
For certain PCIe devices, BAR values are not continuous. This patch maps all the BARs and avoids skipping the next BAR addresses.
Fixes e28aabd88279 ("windows/netuio: introduce NetUIO kernel driver")Signed-off-by Qiao Liu<[email protected]>Signed-off-by Pallavi Kadam<[email protected]>--- windows/netuio/netuio_dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)windows/netuio/netuio_dev.c +3
-1@@ -172,6 +172,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST RULONG next_descriptor =0 ;ULONG curr_bar =0 ;ULONG prev_bar =0 ; +BOOLEAN bar_done = FALSE;/* * ResourcesTranslated report MMIO BARs in the correct order, but their @@ -197,7 +198,8 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST Rfor (INT bar_index =0 ; bar_index <PCI_MAX_BAR ; bar_index++) { prev_bar = curr_bar; curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +if (curr_bar ==0 || ((prev_bar &PCI_TYPE_64BIT ) && (bar_done))) { + bar_done = FALSE;continue ; }windows/netuio/netuio_dev.c netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R · line 227
Quoted 7 lines
windows/netuio/netuio_dev.c +1
-0@@ -219,6 +221,7 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R ctx->bar[bar_index].virt_addr =MmMapIoSpace (descriptor->u.Memory.Start, descriptor->u.Memory.Length, MmNonCached); + bar_done = TRUE;if (ctx->bar[bar_index].virt_addr ==NULL ) { status =STATUS_INSUFFICIENT_RESOURCES ; goto end;Hi Pallavi,
Quoted 6 lines
In the first place, it was wrong to always test
prev_bar & PCI_TYPE_64BITbecause only the first BAR slot of a 64-bit BAR contains flags. The current code has a state to track (curr_bar,prev_bar),
and the fix is complicating it even more without solving the root cause. I suggest a simpler fix (not tested!)
that eliminates both the incorrectness and the state to maintain:
Thank you. This change works for us.
Please let me know if you would like to submit this change as a new patch or if I should include it as a v2 of this same patch.
Quoted 41 lines
windows/netuio/netuio_dev.c +0
-0@@ -273,8 +273,6 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
PCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor; ULONG next_descriptor = 0;windows/netuio/netuio_dev.c +0
-2-ULONG curr_bar =0 ; -ULONG prev_bar =0 ;/* * ResourcesTranslated report MMIO BARs in the correct order, but their @@ -298,9 +296,9 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
* searching for the next MMIO resource each time. */ for (INT bar_index = 0; bar_index < PCI_MAX_BAR; bar_index++) {windows/netuio/netuio_dev.c +3
-3- prev_bar = curr_bar; - curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +ULONG bar_value = pci_config.u.type0.BaseAddresses[bar_index]; + +if (bar_value ==0 ) {continue ; }@@ -339,6 +337,11 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLISTResources, WDFCMRESLIST R
} ctx->dpdk_hw[bar_index].mem.size = ctx->bar[bar_index].size;windows/netuio/netuio_dev.c +5
-0+ +// Skip the next BAR slot used by the current 64-bit address. +if (bar_value &PCI_TYPE_64BIT ) { + bar_index++; + } }// for bar_index end_of_loop:
2022-08-08 17:33 (UTC-0700), Kadam, Pallavi:
[...]
Quoted 9 lines
Quoted 8 lines
Hi Pallavi,
In the first place, it was wrong to always test
prev_bar & PCI_TYPE_64BITbecause only the first BAR slot of a 64-bit BAR contains flags. The current code has a state to track (curr_bar,prev_bar),
and the fix is complicating it even more without solving the root cause. I suggest a simpler fix (not tested!)
that eliminates both the incorrectness and the state to maintain:
Quoted 3 lines
Thank you. This change works for us.
Please let me know if you would like to submit this change as a new patch or if I should include it as a v2 of this same patch.
Please send v2.
You can include my Signed-off-by.
You might also update the commit message and capitalize "BAR" in the title.
Quoted 10 lines · Dmitry Kozlyuk
2022-08-08 17:33 (UTC-0700), Kadam, Pallavi:
[...]Quoted 8 lines
Quoted 8 lines
Hi Pallavi,
In the first place, it was wrong to always test
prev_bar & PCI_TYPE_64BITbecause only the first BAR slot of a 64-bit BAR contains flags. The current code has a state to track (curr_bar,prev_bar),
and the fix is complicating it even more without solving the root cause. I suggest a simpler fix (not tested!)
that eliminates both the incorrectness and the state to maintain:
Quoted 6 lines
Quoted 3 lines
Thank you. This change works for us.
Please let me know if you would like to submit this change as a new patch or if I should include it as a v2 of this same patch.
Please send v2.
You can include my Signed-off-by.
You might also update the commit message and capitalize "BAR" in the title.
Thanks, Dmitry. Have sent v2.
PATCH v2 1/1 windows/netuio: fix BAR parsing
In reply to Pallavi KadamCurrent code was always checking the 'prev_bar & PCI_TYPE_64BIT' though only the first BAR slot of a 64-bit BAR contains flags. Also for certain PCIe devices, BAR values were not continuous. This patch fixes this incorrectness and maps the BAR addresses correctly.
--- windows/netuio/netuio_dev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
windows/netuio/netuio_dev.c +8 -5
@@ -170,8 +170,6 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST RPCM_PARTIAL_RESOURCE_DESCRIPTOR descriptor;ULONG next_descriptor =0 ; -ULONG curr_bar =0 ; -ULONG prev_bar =0 ;/* * ResourcesTranslated report MMIO BARs in the correct order, but their
@@ -195,9 +193,9 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R* searching for the next MMIO resource each time. */ for (INT bar_index =0 ; bar_index <PCI_MAX_BAR ; bar_index++) { - prev_bar = curr_bar; - curr_bar = pci_config.u.type0.BaseAddresses[bar_index]; -if (curr_bar ==0 || (prev_bar &PCI_TYPE_64BIT )) { +ULONG bar_value = pci_config.u.type0.BaseAddresses[bar_index]; + +if (bar_value ==0 ) {continue ; }
@@ -236,6 +234,11 @@ netuio_map_hw_resources(WDFDEVICE Device, WDFCMRESLIST Resources, WDFCMRESLIST R } ctx->dpdk_hw[bar_index].mem.size = ctx->bar[bar_index].size; + +// Skip the next BAR slot used by the current 64-bit address. +if (bar_value &PCI_TYPE_64BIT ) { + bar_index++; + } }// for bar_index status =STATUS_SUCCESS ;
Signature · 1 line
2.31.1.windows.1
Re: [dpdk-kmods v2] windows/netuio: fix BAR parsing
Quoted 6 lines · Pallavi Kadam
Current code was always checking the '
prev_bar&PCI_TYPE_64BIT' though only the first BAR slot of a 64-bit BAR contains flags. Also for certain PCIe devices, BAR values were not continuous. This patch fixes this incorrectness and maps the BAR addresses correctly.
Quoted 8 lines
Reported-by Qiao Liu<[email protected]>Suggested-by Dmitry Kozlyuk<[email protected]>Signed-off-by Dmitry Kozlyuk<[email protected]>Tested-by Pallavi Kadam<[email protected]>--- windows/netuio/netuio_dev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Thomas Monjalon
AppliedRe: [dpdk-kmods v2] windows/netuio: fix BAR parsing
19/08/2022 20:13, Menon, Ranjit:
Quoted 15 lines · Pallavi Kadam
Quoted 6 lines
Current code was always checking the '
prev_bar&PCI_TYPE_64BIT' though only the first BAR slot of a 64-bit BAR contains flags. Also for certain PCIe devices, BAR values were not continuous. This patch fixes this incorrectness and maps the BAR addresses correctly.Quoted 8 lines
Reported-by Qiao Liu<[email protected]>Suggested-by Dmitry Kozlyuk<[email protected]>Signed-off-by Dmitry Kozlyuk<[email protected]>Tested-by Pallavi Kadam<[email protected]>--- windows/netuio/netuio_dev.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
Quoted 1 line
Acked-by Ranjit Menon <[email protected]>
Applied, thanks.
Re: [dpdk-kmods v2] windows/netuio: fix BAR parsing
In reply to Pallavi KadamQuoted 11 lines · Pallavi Kadam
Current code was always checking the '
prev_bar&PCI_TYPE_64BIT' though only the first BAR slot of a 64-bit BAR contains flags. Also for certain PCIe devices, BAR values were not continuous. This patch fixes this incorrectness and maps the BAR addresses correctly.Reported-by Qiao Liu <[email protected]>Suggested-by Dmitry Kozlyuk <[email protected]>Signed-off-by Dmitry Kozlyuk <[email protected]>Tested-by Pallavi Kadam <[email protected]>---