diff mbox series

net/ice: fix representor port segmentation fault

Message ID 20210902094408.1294361-1-dapengx.yu@intel.com (mailing list archive)
State Superseded
Delegated to: Qi Zhang
Headers show
Series net/ice: fix representor port segmentation fault | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/intel-Testing fail Testing issues
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Yu, DapengX Sept. 2, 2021, 9:44 a.m. UTC
From: Dapeng Yu <dapengx.yu@intel.com>

If DCF representor port is closed after DCF port is closed, there will
be segmentation fault because representor accesses the released resource
of DCF port.

This patch makes DCF representor port is always closed before DCF port is
closed.

Fixes: 5674465a32c8 ("net/ice: add DCF VLAN handling")
Cc: stable@dpdk.org

Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
---
 drivers/net/ice/ice_dcf_ethdev.c         |  1 +
 drivers/net/ice/ice_dcf_ethdev.h         |  1 +
 drivers/net/ice/ice_dcf_vf_representor.c | 26 ++++++++++++++++++++----
 3 files changed, 24 insertions(+), 4 deletions(-)

Comments

Wang, Haiyue Sept. 2, 2021, 2:45 p.m. UTC | #1
> -----Original Message-----
> From: Yu, DapengX <dapengx.yu@intel.com>
> Sent: Thursday, September 2, 2021 17:44
> To: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> Cc: dev@dpdk.org; Wang, Haiyue <haiyue.wang@intel.com>; Yu, DapengX <dapengx.yu@intel.com>;
> stable@dpdk.org
> Subject: [PATCH] net/ice: fix representor port segmentation fault
> 
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> If DCF representor port is closed after DCF port is closed, there will
> be segmentation fault because representor accesses the released resource
> of DCF port.
> 
> This patch makes DCF representor port is always closed before DCF port is
> closed.
> 
> Fixes: 5674465a32c8 ("net/ice: add DCF VLAN handling")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>  drivers/net/ice/ice_dcf_ethdev.c         |  1 +
>  drivers/net/ice/ice_dcf_ethdev.h         |  1 +
>  drivers/net/ice/ice_dcf_vf_representor.c | 26 ++++++++++++++++++++----
>  3 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
> index cab7c4da87..b837f69fd4 100644
> --- a/drivers/net/ice/ice_dcf_ethdev.c
> +++ b/drivers/net/ice/ice_dcf_ethdev.c
> @@ -874,6 +874,7 @@ ice_dcf_dev_close(struct rte_eth_dev *dev)
>  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
>  		return 0;
> 
> +	ice_dcf_vf_repr_close_all(adapter);
>  	ice_dcf_free_repr_info(adapter);
>  	ice_dcf_uninit_parent_adapter(dev);
>  	ice_dcf_uninit_hw(dev, &adapter->real_hw);
> diff --git a/drivers/net/ice/ice_dcf_ethdev.h b/drivers/net/ice/ice_dcf_ethdev.h
> index 8510e37119..9e8d3ef0c5 100644
> --- a/drivers/net/ice/ice_dcf_ethdev.h
> +++ b/drivers/net/ice/ice_dcf_ethdev.h
> @@ -64,5 +64,6 @@ int ice_dcf_vf_repr_init(struct rte_eth_dev *vf_rep_eth_dev, void *init_param);
>  int ice_dcf_vf_repr_uninit(struct rte_eth_dev *vf_rep_eth_dev);
>  int ice_dcf_vf_repr_init_vlan(struct rte_eth_dev *vf_rep_eth_dev);
>  void ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter);
> +void ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter);
> 
>  #endif /* _ICE_DCF_ETHDEV_H_ */
> diff --git a/drivers/net/ice/ice_dcf_vf_representor.c b/drivers/net/ice/ice_dcf_vf_representor.c
> index 970461f3e9..121dea7483 100644
> --- a/drivers/net/ice/ice_dcf_vf_representor.c
> +++ b/drivers/net/ice/ice_dcf_vf_representor.c
> @@ -46,6 +46,7 @@ static int
>  ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
>  {
>  	dev->data->dev_link.link_status = ETH_LINK_DOWN;
> +	dev->data->dev_started = 0;
> 
>  	return 0;
>  }
> @@ -53,6 +54,7 @@ ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
>  static int
>  ice_dcf_vf_repr_dev_close(struct rte_eth_dev *dev)
>  {
> +	(void)ice_dcf_vf_repr_dev_stop(dev);

Do we truly need the "(void)" ?

>  	return ice_dcf_vf_repr_uninit(dev);
>  }
> 
> @@ -464,7 +466,6 @@ void
>  ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter)
>  {
>  	uint16_t vf_id;
> -	int ret;
> 
>  	if (!dcf_adapter->repr_infos)
>  		return;
> @@ -475,8 +476,25 @@ ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter)
>  		if (!vf_rep_eth_dev || vf_rep_eth_dev->data->dev_started == 0)
>  			continue;
> 
> -		ret = ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
> -		if (!ret)
> -			vf_rep_eth_dev->data->dev_started = 0;
> +		(void)ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
> +	}
> +}
> +
> +void
> +ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter)
> +{
> +	uint16_t vf_id;
> +
> +	if (!dcf_adapter->repr_infos)
> +		return;
> +
> +	for (vf_id = 0; vf_id < dcf_adapter->real_hw.num_vfs; vf_id++) {
> +		struct rte_eth_dev *vf_rep_eth_dev =
> +				dcf_adapter->repr_infos[vf_id].vf_rep_eth_dev;
> +		if (!vf_rep_eth_dev)
> +			continue;
> +
> +		(void)ice_dcf_vf_repr_dev_close(vf_rep_eth_dev);
> +		(void)rte_eth_dev_release_port(vf_rep_eth_dev);
>  	}
>  }
> --
> 2.27.0
Yu, DapengX Sept. 3, 2021, 3:08 a.m. UTC | #2
> -----Original Message-----
> From: Wang, Haiyue <haiyue.wang@intel.com>
> Sent: Thursday, September 2, 2021 10:45 PM
> To: Yu, DapengX <dapengx.yu@intel.com>; Yang, Qiming
> <qiming.yang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: RE: [PATCH] net/ice: fix representor port segmentation fault
> 
> > -----Original Message-----
> > From: Yu, DapengX <dapengx.yu@intel.com>
> > Sent: Thursday, September 2, 2021 17:44
> > To: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> > <qi.z.zhang@intel.com>
> > Cc: dev@dpdk.org; Wang, Haiyue <haiyue.wang@intel.com>; Yu, DapengX
> > <dapengx.yu@intel.com>; stable@dpdk.org
> > Subject: [PATCH] net/ice: fix representor port segmentation fault
> >
> > From: Dapeng Yu <dapengx.yu@intel.com>
> >
> > If DCF representor port is closed after DCF port is closed, there will
> > be segmentation fault because representor accesses the released
> > resource of DCF port.
> >
> > This patch makes DCF representor port is always closed before DCF port
> > is closed.
> >
> > Fixes: 5674465a32c8 ("net/ice: add DCF VLAN handling")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> > ---
> >  drivers/net/ice/ice_dcf_ethdev.c         |  1 +
> >  drivers/net/ice/ice_dcf_ethdev.h         |  1 +
> >  drivers/net/ice/ice_dcf_vf_representor.c | 26
> > ++++++++++++++++++++----
> >  3 files changed, 24 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/net/ice/ice_dcf_ethdev.c
> > b/drivers/net/ice/ice_dcf_ethdev.c
> > index cab7c4da87..b837f69fd4 100644
> > --- a/drivers/net/ice/ice_dcf_ethdev.c
> > +++ b/drivers/net/ice/ice_dcf_ethdev.c
> > @@ -874,6 +874,7 @@ ice_dcf_dev_close(struct rte_eth_dev *dev)
> >  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> >  		return 0;
> >
> > +	ice_dcf_vf_repr_close_all(adapter);
> >  	ice_dcf_free_repr_info(adapter);
> >  	ice_dcf_uninit_parent_adapter(dev);
> >  	ice_dcf_uninit_hw(dev, &adapter->real_hw); diff --git
> > a/drivers/net/ice/ice_dcf_ethdev.h b/drivers/net/ice/ice_dcf_ethdev.h
> > index 8510e37119..9e8d3ef0c5 100644
> > --- a/drivers/net/ice/ice_dcf_ethdev.h
> > +++ b/drivers/net/ice/ice_dcf_ethdev.h
> > @@ -64,5 +64,6 @@ int ice_dcf_vf_repr_init(struct rte_eth_dev
> > *vf_rep_eth_dev, void *init_param);  int ice_dcf_vf_repr_uninit(struct
> > rte_eth_dev *vf_rep_eth_dev);  int ice_dcf_vf_repr_init_vlan(struct
> > rte_eth_dev *vf_rep_eth_dev);  void ice_dcf_vf_repr_stop_all(struct
> > ice_dcf_adapter *dcf_adapter);
> > +void ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter);
> >
> >  #endif /* _ICE_DCF_ETHDEV_H_ */
> > diff --git a/drivers/net/ice/ice_dcf_vf_representor.c
> > b/drivers/net/ice/ice_dcf_vf_representor.c
> > index 970461f3e9..121dea7483 100644
> > --- a/drivers/net/ice/ice_dcf_vf_representor.c
> > +++ b/drivers/net/ice/ice_dcf_vf_representor.c
> > @@ -46,6 +46,7 @@ static int
> >  ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)  {
> >  	dev->data->dev_link.link_status = ETH_LINK_DOWN;
> > +	dev->data->dev_started = 0;
> >
> >  	return 0;
> >  }
> > @@ -53,6 +54,7 @@ ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
> > static int  ice_dcf_vf_repr_dev_close(struct rte_eth_dev *dev)  {
> > +	(void)ice_dcf_vf_repr_dev_stop(dev);
> 
> Do we truly need the "(void)" ?

Here use (void) to make discarding of return value explicit.
There will be no compiler(clang, icc, and gcc) warning even if remove (void)
So it is fine without that.

> 
> >  	return ice_dcf_vf_repr_uninit(dev);
> >  }
> >
> > @@ -464,7 +466,6 @@ void
> >  ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter)  {
> >  	uint16_t vf_id;
> > -	int ret;
> >
> >  	if (!dcf_adapter->repr_infos)
> >  		return;
> > @@ -475,8 +476,25 @@ ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter
> *dcf_adapter)
> >  		if (!vf_rep_eth_dev || vf_rep_eth_dev->data->dev_started
> == 0)
> >  			continue;
> >
> > -		ret = ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
> > -		if (!ret)
> > -			vf_rep_eth_dev->data->dev_started = 0;
> > +		(void)ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
> > +	}
> > +}
> > +
> > +void
> > +ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter) {
> > +	uint16_t vf_id;
> > +
> > +	if (!dcf_adapter->repr_infos)
> > +		return;
> > +
> > +	for (vf_id = 0; vf_id < dcf_adapter->real_hw.num_vfs; vf_id++) {
> > +		struct rte_eth_dev *vf_rep_eth_dev =
> > +				dcf_adapter-
> >repr_infos[vf_id].vf_rep_eth_dev;
> > +		if (!vf_rep_eth_dev)
> > +			continue;
> > +
> > +		(void)ice_dcf_vf_repr_dev_close(vf_rep_eth_dev);
> > +		(void)rte_eth_dev_release_port(vf_rep_eth_dev);
> >  	}
> >  }
> > --
> > 2.27.0
Wang, Haiyue Sept. 3, 2021, 4:37 a.m. UTC | #3
> -----Original Message-----
> From: Yu, DapengX <dapengx.yu@intel.com>
> Sent: Friday, September 3, 2021 11:09
> To: Wang, Haiyue <haiyue.wang@intel.com>; Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: RE: [PATCH] net/ice: fix representor port segmentation fault
> 
> 
> 
> > -----Original Message-----
> > From: Wang, Haiyue <haiyue.wang@intel.com>
> > Sent: Thursday, September 2, 2021 10:45 PM
> > To: Yu, DapengX <dapengx.yu@intel.com>; Yang, Qiming
> > <qiming.yang@intel.com>; Zhang, Qi Z <qi.z.zhang@intel.com>
> > Cc: dev@dpdk.org; stable@dpdk.org
> > Subject: RE: [PATCH] net/ice: fix representor port segmentation fault
> >
> > > -----Original Message-----
> > > From: Yu, DapengX <dapengx.yu@intel.com>
> > > Sent: Thursday, September 2, 2021 17:44
> > > To: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> > > <qi.z.zhang@intel.com>
> > > Cc: dev@dpdk.org; Wang, Haiyue <haiyue.wang@intel.com>; Yu, DapengX
> > > <dapengx.yu@intel.com>; stable@dpdk.org
> > > Subject: [PATCH] net/ice: fix representor port segmentation fault
> > >
> > > From: Dapeng Yu <dapengx.yu@intel.com>
> > >
> > > If DCF representor port is closed after DCF port is closed, there will
> > > be segmentation fault because representor accesses the released
> > > resource of DCF port.
> > >
> > > This patch makes DCF representor port is always closed before DCF port
> > > is closed.
> > >
> > > Fixes: 5674465a32c8 ("net/ice: add DCF VLAN handling")
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> > > ---
> > >  drivers/net/ice/ice_dcf_ethdev.c         |  1 +
> > >  drivers/net/ice/ice_dcf_ethdev.h         |  1 +
> > >  drivers/net/ice/ice_dcf_vf_representor.c | 26
> > > ++++++++++++++++++++----
> > >  3 files changed, 24 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/net/ice/ice_dcf_ethdev.c
> > > b/drivers/net/ice/ice_dcf_ethdev.c
> > > index cab7c4da87..b837f69fd4 100644
> > > --- a/drivers/net/ice/ice_dcf_ethdev.c
> > > +++ b/drivers/net/ice/ice_dcf_ethdev.c
> > > @@ -874,6 +874,7 @@ ice_dcf_dev_close(struct rte_eth_dev *dev)
> > >  	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
> > >  		return 0;
> > >
> > > +	ice_dcf_vf_repr_close_all(adapter);
> > >  	ice_dcf_free_repr_info(adapter);
> > >  	ice_dcf_uninit_parent_adapter(dev);
> > >  	ice_dcf_uninit_hw(dev, &adapter->real_hw); diff --git
> > > a/drivers/net/ice/ice_dcf_ethdev.h b/drivers/net/ice/ice_dcf_ethdev.h
> > > index 8510e37119..9e8d3ef0c5 100644
> > > --- a/drivers/net/ice/ice_dcf_ethdev.h
> > > +++ b/drivers/net/ice/ice_dcf_ethdev.h
> > > @@ -64,5 +64,6 @@ int ice_dcf_vf_repr_init(struct rte_eth_dev
> > > *vf_rep_eth_dev, void *init_param);  int ice_dcf_vf_repr_uninit(struct
> > > rte_eth_dev *vf_rep_eth_dev);  int ice_dcf_vf_repr_init_vlan(struct
> > > rte_eth_dev *vf_rep_eth_dev);  void ice_dcf_vf_repr_stop_all(struct
> > > ice_dcf_adapter *dcf_adapter);
> > > +void ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter);
> > >
> > >  #endif /* _ICE_DCF_ETHDEV_H_ */
> > > diff --git a/drivers/net/ice/ice_dcf_vf_representor.c
> > > b/drivers/net/ice/ice_dcf_vf_representor.c
> > > index 970461f3e9..121dea7483 100644
> > > --- a/drivers/net/ice/ice_dcf_vf_representor.c
> > > +++ b/drivers/net/ice/ice_dcf_vf_representor.c
> > > @@ -46,6 +46,7 @@ static int
> > >  ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)  {
> > >  	dev->data->dev_link.link_status = ETH_LINK_DOWN;
> > > +	dev->data->dev_started = 0;
> > >
> > >  	return 0;
> > >  }
> > > @@ -53,6 +54,7 @@ ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
> > > static int  ice_dcf_vf_repr_dev_close(struct rte_eth_dev *dev)  {
> > > +	(void)ice_dcf_vf_repr_dev_stop(dev);
> >
> > Do we truly need the "(void)" ?
> 
> Here use (void) to make discarding of return value explicit.

No need so paranoid ;-)

> There will be no compiler(clang, icc, and gcc) warning even if remove (void)
> So it is fine without that.

Then code is clean.

> > > --
> > > 2.27.0
diff mbox series

Patch

diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index cab7c4da87..b837f69fd4 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -874,6 +874,7 @@  ice_dcf_dev_close(struct rte_eth_dev *dev)
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
+	ice_dcf_vf_repr_close_all(adapter);
 	ice_dcf_free_repr_info(adapter);
 	ice_dcf_uninit_parent_adapter(dev);
 	ice_dcf_uninit_hw(dev, &adapter->real_hw);
diff --git a/drivers/net/ice/ice_dcf_ethdev.h b/drivers/net/ice/ice_dcf_ethdev.h
index 8510e37119..9e8d3ef0c5 100644
--- a/drivers/net/ice/ice_dcf_ethdev.h
+++ b/drivers/net/ice/ice_dcf_ethdev.h
@@ -64,5 +64,6 @@  int ice_dcf_vf_repr_init(struct rte_eth_dev *vf_rep_eth_dev, void *init_param);
 int ice_dcf_vf_repr_uninit(struct rte_eth_dev *vf_rep_eth_dev);
 int ice_dcf_vf_repr_init_vlan(struct rte_eth_dev *vf_rep_eth_dev);
 void ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter);
+void ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter);
 
 #endif /* _ICE_DCF_ETHDEV_H_ */
diff --git a/drivers/net/ice/ice_dcf_vf_representor.c b/drivers/net/ice/ice_dcf_vf_representor.c
index 970461f3e9..121dea7483 100644
--- a/drivers/net/ice/ice_dcf_vf_representor.c
+++ b/drivers/net/ice/ice_dcf_vf_representor.c
@@ -46,6 +46,7 @@  static int
 ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
 {
 	dev->data->dev_link.link_status = ETH_LINK_DOWN;
+	dev->data->dev_started = 0;
 
 	return 0;
 }
@@ -53,6 +54,7 @@  ice_dcf_vf_repr_dev_stop(struct rte_eth_dev *dev)
 static int
 ice_dcf_vf_repr_dev_close(struct rte_eth_dev *dev)
 {
+	(void)ice_dcf_vf_repr_dev_stop(dev);
 	return ice_dcf_vf_repr_uninit(dev);
 }
 
@@ -464,7 +466,6 @@  void
 ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter)
 {
 	uint16_t vf_id;
-	int ret;
 
 	if (!dcf_adapter->repr_infos)
 		return;
@@ -475,8 +476,25 @@  ice_dcf_vf_repr_stop_all(struct ice_dcf_adapter *dcf_adapter)
 		if (!vf_rep_eth_dev || vf_rep_eth_dev->data->dev_started == 0)
 			continue;
 
-		ret = ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
-		if (!ret)
-			vf_rep_eth_dev->data->dev_started = 0;
+		(void)ice_dcf_vf_repr_dev_stop(vf_rep_eth_dev);
+	}
+}
+
+void
+ice_dcf_vf_repr_close_all(struct ice_dcf_adapter *dcf_adapter)
+{
+	uint16_t vf_id;
+
+	if (!dcf_adapter->repr_infos)
+		return;
+
+	for (vf_id = 0; vf_id < dcf_adapter->real_hw.num_vfs; vf_id++) {
+		struct rte_eth_dev *vf_rep_eth_dev =
+				dcf_adapter->repr_infos[vf_id].vf_rep_eth_dev;
+		if (!vf_rep_eth_dev)
+			continue;
+
+		(void)ice_dcf_vf_repr_dev_close(vf_rep_eth_dev);
+		(void)rte_eth_dev_release_port(vf_rep_eth_dev);
 	}
 }