ethdev: fix secondary process change share memory

Message ID 20200109031425.1338-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-mellanox-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS

Commit Message

方统浩50450 Jan. 9, 2020, 3:14 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.

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

Stephen Hemminger Jan. 10, 2020, 3:32 p.m. UTC | #1
On Thu,  9 Jan 2020 11:14:25 +0800
Fang TongHao <fangtonghao@sangfor.com.cn> 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.
> 
> Signed-off-by: Fang TongHao <fangtonghao@sangfor.com.cn>

Most of the drivers avoid calling rte_eth_dev_pci_copy_info
in the secondary process, which one are you using?
  
方统浩50450 Jan. 13, 2020, 3:02 a.m. UTC | #2
secondary process will enter rte_eth_copy_pci_info function when initializing.
rte_eth_dev_pci_copy_info -> rte_eth_copy_pci_info




发件人:Stephen Hemminger <stephen@networkplumber.org>
发送日期:2020-01-10 23:32:15
收件人:Fang TongHao <fangtonghao@sangfor.com.cn>
抄送人:thomas@monjalon.net,ferruh.yigit@intel.com,arybchenko@solarflare.com,dev@dpdk.org,stable@dpdk.org,cunming.liang@intel.com,jia.guo@intel.com
主题:Re: [dpdk-dev] [PATCH] ethdev: fix secondary process change share memory>On Thu,  9 Jan 2020 11:14:25 +0800
>Fang TongHao <fangtonghao@sangfor.com.cn> 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.
>> 
>> Signed-off-by: Fang TongHao <fangtonghao@sangfor.com.cn>
>
>Most of the drivers avoid calling rte_eth_dev_pci_copy_info
>in the secondary process, which one are you using?
  

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