linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg()
@ 2022-04-01 10:40 Ivan Vecera
  2022-04-08 13:47 ` Alexander Lobakin
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Vecera @ 2022-04-01 10:40 UTC (permalink / raw)
  To: netdev
  Cc: poros, mschmidt, jacob.e.keller, Jesse Brandeburg, Tony Nguyen,
	David S. Miller, Jakub Kicinski, Paolo Abeni, Brett Creeley,
	moderated list:INTEL ETHERNET DRIVERS, open list

Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect
because message sent from VF is ignored and never processed.

Use mutex_lock() instead to fix the issue. It is safe because this
mutex is used to prevent races between VF related NDOs and
handlers processing request messages from VF and these handlers
are running in ice_service_task() context. Additionally move this
mutex lock prior ice_vc_is_opcode_allowed() call to avoid potential
races during allowlist acccess.

Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops")
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
index 3f1a63815bac..a465f3743ffc 100644
--- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
+++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
@@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
 			err = -EINVAL;
 	}
 
-	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
-		ice_vc_send_msg_to_vf(vf, v_opcode,
-				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
-				      0);
-		ice_put_vf(vf);
-		return;
-	}
-
 error_handler:
 	if (err) {
 		ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
@@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
 		return;
 	}
 
-	/* VF is being configured in another context that triggers a VFR, so no
-	 * need to process this message
-	 */
-	if (!mutex_trylock(&vf->cfg_lock)) {
-		dev_info(dev, "VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n",
-			 vf->vf_id);
+	mutex_lock(&vf->cfg_lock);
+
+	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
+		ice_vc_send_msg_to_vf(vf, v_opcode,
+				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
+				      0);
+		mutex_unlock(&vf->cfg_lock);
 		ice_put_vf(vf);
 		return;
 	}
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg()
  2022-04-01 10:40 [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg() Ivan Vecera
@ 2022-04-08 13:47 ` Alexander Lobakin
  2022-04-08 16:01   ` Tony Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2022-04-08 13:47 UTC (permalink / raw)
  To: Tony Nguyen
  Cc: Alexander Lobakin, Ivan Vecera, netdev, poros, mschmidt,
	jacob.e.keller, Jesse Brandeburg, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Brett Creeley,
	moderated list:INTEL ETHERNET DRIVERS, open list

From: Ivan Vecera <ivecera@redhat.com>
Date: Fri,  1 Apr 2022 12:40:52 +0200

> Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect
> because message sent from VF is ignored and never processed.
> 
> Use mutex_lock() instead to fix the issue. It is safe because this
> mutex is used to prevent races between VF related NDOs and
> handlers processing request messages from VF and these handlers
> are running in ice_service_task() context. Additionally move this
> mutex lock prior ice_vc_is_opcode_allowed() call to avoid potential
> races during allowlist acccess.
> 
> Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops")
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>

Hey Tony,

I guess you missed this one due to being on a vacation previously.
It's been previously reviewed IIRC, could you take it into
net-queue?

> ---
>  drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------
>  1 file changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> index 3f1a63815bac..a465f3743ffc 100644
> --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> @@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
>  			err = -EINVAL;
>  	}
>  
> -	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
> -		ice_vc_send_msg_to_vf(vf, v_opcode,
> -				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
> -				      0);
> -		ice_put_vf(vf);
> -		return;
> -	}
> -
>  error_handler:
>  	if (err) {
>  		ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
> @@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
>  		return;
>  	}
>  
> -	/* VF is being configured in another context that triggers a VFR, so no
> -	 * need to process this message
> -	 */
> -	if (!mutex_trylock(&vf->cfg_lock)) {
> -		dev_info(dev, "VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n",
> -			 vf->vf_id);
> +	mutex_lock(&vf->cfg_lock);
> +
> +	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
> +		ice_vc_send_msg_to_vf(vf, v_opcode,
> +				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
> +				      0);
> +		mutex_unlock(&vf->cfg_lock);
>  		ice_put_vf(vf);
>  		return;
>  	}
> -- 
> 2.35.1

Thanks,
Al

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg()
  2022-04-08 13:47 ` Alexander Lobakin
@ 2022-04-08 16:01   ` Tony Nguyen
  2022-04-12 10:39     ` [Intel-wired-lan] " Jankowski, Konrad0
  0 siblings, 1 reply; 4+ messages in thread
From: Tony Nguyen @ 2022-04-08 16:01 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Ivan Vecera, netdev, poros, mschmidt, jacob.e.keller,
	Jesse Brandeburg, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Brett Creeley, moderated list:INTEL ETHERNET DRIVERS, open list


On 4/8/2022 6:47 AM, Alexander Lobakin wrote:
> From: Ivan Vecera <ivecera@redhat.com>
> Date: Fri,  1 Apr 2022 12:40:52 +0200
>
>> Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect
>> because message sent from VF is ignored and never processed.
>>
>> Use mutex_lock() instead to fix the issue. It is safe because this
>> mutex is used to prevent races between VF related NDOs and
>> handlers processing request messages from VF and these handlers
>> are running in ice_service_task() context. Additionally move this
>> mutex lock prior ice_vc_is_opcode_allowed() call to avoid potential
>> races during allowlist acccess.
>>
>> Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl handling and VF ndo ops")
>> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> Hey Tony,
>
> I guess you missed this one due to being on a vacation previously.
> It's been previously reviewed IIRC, could you take it into
> net-queue?

I remember applying this but I don't see it on the tree so I must be 
mistaken. :( I'll get it applied, thanks for catching.

-Tony

>> ---
>>   drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------
>>   1 file changed, 7 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
>> index 3f1a63815bac..a465f3743ffc 100644
>> --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
>> +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
>> @@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
>>   			err = -EINVAL;
>>   	}
>>   
>> -	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
>> -		ice_vc_send_msg_to_vf(vf, v_opcode,
>> -				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
>> -				      0);
>> -		ice_put_vf(vf);
>> -		return;
>> -	}
>> -
>>   error_handler:
>>   	if (err) {
>>   		ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
>> @@ -3660,12 +3652,13 @@ void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event)
>>   		return;
>>   	}
>>   
>> -	/* VF is being configured in another context that triggers a VFR, so no
>> -	 * need to process this message
>> -	 */
>> -	if (!mutex_trylock(&vf->cfg_lock)) {
>> -		dev_info(dev, "VF %u is being configured in another context that will trigger a VFR, so there is no need to handle this message\n",
>> -			 vf->vf_id);
>> +	mutex_lock(&vf->cfg_lock);
>> +
>> +	if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
>> +		ice_vc_send_msg_to_vf(vf, v_opcode,
>> +				      VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
>> +				      0);
>> +		mutex_unlock(&vf->cfg_lock);
>>   		ice_put_vf(vf);
>>   		return;
>>   	}
>> -- 
>> 2.35.1
> Thanks,
> Al

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [Intel-wired-lan] [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg()
  2022-04-08 16:01   ` Tony Nguyen
@ 2022-04-12 10:39     ` Jankowski, Konrad0
  0 siblings, 0 replies; 4+ messages in thread
From: Jankowski, Konrad0 @ 2022-04-12 10:39 UTC (permalink / raw)
  To: Nguyen, Anthony L, Lobakin, Alexandr
  Cc: ivecera, netdev, mschmidt, Brett Creeley, open list, poros,
	moderated list:INTEL ETHERNET DRIVERS, Jakub Kicinski,
	Paolo Abeni, David S. Miller



> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Tony Nguyen
> Sent: Friday, April 8, 2022 6:01 PM
> To: Lobakin, Alexandr <alexandr.lobakin@intel.com>
> Cc: ivecera <ivecera@redhat.com>; netdev@vger.kernel.org; mschmidt
> <mschmidt@redhat.com>; Brett Creeley <brett@pensando.io>; open list
> <linux-kernel@vger.kernel.org>; poros <poros@redhat.com>; moderated
> list:INTEL ETHERNET DRIVERS <intel-wired-lan@lists.osuosl.org>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; David S.
> Miller <davem@davemloft.net>
> Subject: Re: [Intel-wired-lan] [PATCH net v2] ice: Fix incorrect locking in
> ice_vc_process_vf_msg()
> 
> 
> On 4/8/2022 6:47 AM, Alexander Lobakin wrote:
> > From: Ivan Vecera <ivecera@redhat.com>
> > Date: Fri,  1 Apr 2022 12:40:52 +0200
> >
> >> Usage of mutex_trylock() in ice_vc_process_vf_msg() is incorrect
> >> because message sent from VF is ignored and never processed.
> >>
> >> Use mutex_lock() instead to fix the issue. It is safe because this
> >> mutex is used to prevent races between VF related NDOs and handlers
> >> processing request messages from VF and these handlers are running in
> >> ice_service_task() context. Additionally move this mutex lock prior
> >> ice_vc_is_opcode_allowed() call to avoid potential races during
> >> allowlist acccess.
> >>
> >> Fixes: e6ba5273d4ed ("ice: Fix race conditions between virtchnl
> >> handling and VF ndo ops")
> >> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> > Hey Tony,
> >
> > I guess you missed this one due to being on a vacation previously.
> > It's been previously reviewed IIRC, could you take it into net-queue?
> 
> I remember applying this but I don't see it on the tree so I must be mistaken.
> :( I'll get it applied, thanks for catching.
> 
> -Tony
> 
> >> ---
> >>   drivers/net/ethernet/intel/ice/ice_virtchnl.c | 21 +++++++------------
> >>   1 file changed, 7 insertions(+), 14 deletions(-)
> >>
> >> diff --git a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> >> b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> >> index 3f1a63815bac..a465f3743ffc 100644
> >> --- a/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> >> +++ b/drivers/net/ethernet/intel/ice/ice_virtchnl.c
> >> @@ -3642,14 +3642,6 @@ void ice_vc_process_vf_msg(struct ice_pf *pf,

Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-12 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 10:40 [PATCH net v2] ice: Fix incorrect locking in ice_vc_process_vf_msg() Ivan Vecera
2022-04-08 13:47 ` Alexander Lobakin
2022-04-08 16:01   ` Tony Nguyen
2022-04-12 10:39     ` [Intel-wired-lan] " Jankowski, Konrad0

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).