ethdev: fix secondary process change share memory

Message ID 20200109023529.1285-1-fangtonghao@sangfor.com.cn (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: fix secondary process change share memory |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

方统浩50450 Jan. 9, 2020, 2:35 a.m. UTC
  Hi all,I am from Sangfor Tech.I found a bug when using DPDK in
multiprocess scenario.The secondary process enters
"rte_eth_dev_pci_copy_info" function when initializing.Then it
sets the value of struct "rte_eth_dev_data.dev_flags" to zero,
but this struct is shared by primary process and secondary
process, and the value change is unexpected by primary process.
This may cause very serious damage.I think
the secondary process should not enter "rte_eth_dev_pci_copy_info"
function or changes the value of struct "rte_eth_dev_data.dev_flags"
in shared memory.
I fixed this bug by adding an if-statement to forbid the secondary
process changing the above-mentioned value.
Thansk, All.
Cc: stable@dpdk.org

Signed-off-by: Fang TongHao <fangtonghao@sangfor.com.cn>
---
 lib/librte_ethdev/rte_ethdev_pci.h | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
  

Comments

Anatoly Burakov Jan. 15, 2020, 10:30 a.m. UTC | #1
On 09-Jan-20 2:35 AM, Fang TongHao wrote:
> Hi all,I am from Sangfor Tech.I found a bug when using DPDK in
> multiprocess scenario.The secondary process enters
> "rte_eth_dev_pci_copy_info" function when initializing.Then it
> sets the value of struct "rte_eth_dev_data.dev_flags" to zero,
> but this struct is shared by primary process and secondary
> process, and the value change is unexpected by primary process.
> This may cause very serious damage.I think
> the secondary process should not enter "rte_eth_dev_pci_copy_info"
> function or changes the value of struct "rte_eth_dev_data.dev_flags"
> in shared memory.
> I fixed this bug by adding an if-statement to forbid the secondary
> process changing the above-mentioned value.
> Thansk, All.

Hi,

Thanks for your contribution! However, your patch could use some 
improvements, as it currently doesn't meet the standards expected by the 
DPDK community.

First of all, the commit log shouldn't read like an email :) Suggested 
rewording:

----
When secondary process enters `rte_eth_copy_pci_info`, it resets the 
rte_eth_dev_data.dev_flags to zero. This may cause unintended 
consequences because this is a structure that is shared between primary 
and secondary processes. Fix it by only overwriting the flags if the 
process is primary.
---

Your commit message has also incorrectly called out the offending 
function as `rte_eth_dev_copy_pci_info`, while it is actually named 
`rte_eth_copy_pci_info`.

Also, a Fixes: tag is missing. Please use git blame to find the commit 
that introduced the issue, and use the 'fixline' formatting. Please see 
Contribution Guidelines[1] on how to properly format fixline.

You will find instructions on how to submit a version 2 of the patch in 
the same document[2].

[1] 
https://doc.dpdk.org/guides/contributing/patches.html#commit-messages-body

[2] 
https://doc.dpdk.org/guides/contributing/patches.html#steps-to-getting-your-patch-merged
  

Patch

diff --git a/lib/librte_ethdev/rte_ethdev_pci.h b/lib/librte_ethdev/rte_ethdev_pci.h
index ccdbb46ec..916de8a14 100644
--- a/lib/librte_ethdev/rte_ethdev_pci.h
+++ b/lib/librte_ethdev/rte_ethdev_pci.h
@@ -59,15 +59,16 @@  rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev,
 	}
 
 	eth_dev->intr_handle = &pci_dev->intr_handle;
-
-	eth_dev->data->dev_flags = 0;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
-	if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_RMV)
-		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_RMV;
-
-	eth_dev->data->kdrv = pci_dev->kdrv;
-	eth_dev->data->numa_node = pci_dev->device.numa_node;
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		eth_dev->data->dev_flags = 0;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
+		if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_RMV)
+			eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_RMV;
+
+		eth_dev->data->kdrv = pci_dev->kdrv;
+		eth_dev->data->numa_node = pci_dev->device.numa_node;
+	}
 }
 
 static inline int