[net,06/13] mlx5: reject unsupported external timestamp flags
diff mbox series

Message ID 20191114184507.18937-7-richardcochran@gmail.com
State Awaiting Upstream
Headers show
Series
  • ptp: Validate the ancillary ioctl flags more carefully.
Related show

Commit Message

Richard Cochran Nov. 14, 2019, 6:45 p.m. UTC
From: Jacob Keller <jacob.e.keller@intel.com>

Fix the mlx5 core PTP support to explicitly reject any future flags that
get added to the external timestamp request ioctl.

In order to maintain currently functioning code, this patch accepts all
three current flags. This is because the PTP_RISING_EDGE and
PTP_FALLING_EDGE flags have unclear semantics and each driver seems to
have interpreted them slightly differently.

[ RC: I'm not 100% sure what this driver does, but if I'm not wrong it
      follows the dp83640:

  flags                                                 Meaning
  ----------------------------------------------------  --------------------------
  PTP_ENABLE_FEATURE                                    Time stamp rising edge
  PTP_ENABLE_FEATURE|PTP_RISING_EDGE                    Time stamp rising edge
  PTP_ENABLE_FEATURE|PTP_FALLING_EDGE                   Time stamp falling edge
  PTP_ENABLE_FEATURE|PTP_RISING_EDGE|PTP_FALLING_EDGE   Time stamp falling edge
]

Cc: Feras Daoud <ferasda@mellanox.com>
Cc: Eugenia Emantayev <eugenia@mellanox.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Richard Cochran <richardcochran@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Saeed Mahameed Nov. 15, 2019, 12:03 a.m. UTC | #1
On Thu, 2019-11-14 at 10:45 -0800, Richard Cochran wrote:
> From: Jacob Keller <jacob.e.keller@intel.com>
> 
> Fix the mlx5 core PTP support to explicitly reject any future flags
> that
> get added to the external timestamp request ioctl.
> 
> In order to maintain currently functioning code, this patch accepts
> all
> three current flags. This is because the PTP_RISING_EDGE and
> PTP_FALLING_EDGE flags have unclear semantics and each driver seems
> to
> have interpreted them slightly differently.
> 
> [ RC: I'm not 100% sure what this driver does, but if I'm not wrong
> it
>       follows the dp83640:
> 

The driver will check if the PTP_FALLING_EDGE flag was set then it will
set it in HW, if not then it is going to default to PTP_RISING_EDGE, so
LGTM.

Reviewed-by: Saeed Mahameed <saeedm@mellanox.com>

But same story here, old tools that lazily set 0xffff or 0x0000 and
expected every thing to work.. again not sure if they do exist.

Ariel please have a look at this patch.

>   flags                                                 Meaning
>   ----------------------------------------------------  -------------
> -------------
>   PTP_ENABLE_FEATURE                                    Time stamp
> rising edge
>   PTP_ENABLE_FEATURE|PTP_RISING_EDGE                    Time stamp
> rising edge
>   PTP_ENABLE_FEATURE|PTP_FALLING_EDGE                   Time stamp
> falling edge
>   PTP_ENABLE_FEATURE|PTP_RISING_EDGE|PTP_FALLING_EDGE   Time stamp
> falling edge
> ]
> 
> Cc: Feras Daoud <ferasda@mellanox.com>
> Cc: Eugenia Emantayev <eugenia@mellanox.com>
> Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
> Reviewed-by: Richard Cochran <richardcochran@gmail.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> index cff6b60de304..9a40f24e3193 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
> @@ -236,6 +236,12 @@ static int mlx5_extts_configure(struct
> ptp_clock_info *ptp,
>  	if (!MLX5_PPS_CAP(mdev))
>  		return -EOPNOTSUPP;
>  
> +	/* Reject requests with unsupported flags */
> +	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
> +				PTP_RISING_EDGE |
> +				PTP_FALLING_EDGE))
> +		return -EOPNOTSUPP;
> +
>  	if (rq->extts.index >= clock->ptp_info.n_pins)
>  		return -EINVAL;
>
Jacob Keller Nov. 15, 2019, 1:15 a.m. UTC | #2
> -----Original Message-----
> From: Saeed Mahameed <saeedm@mellanox.com>
> Sent: Thursday, November 14, 2019 4:03 PM
> To: Ariel Levkovich <lariel@mellanox.com>; richardcochran@gmail.com;
> netdev@vger.kernel.org
> Cc: Hall, Christopher S <christopher.s.hall@intel.com>; Eugenia Emantayev
> <eugenia@mellanox.com>; davem@davemloft.net;
> sergei.shtylyov@cogentembedded.com; Feras Daoud <ferasda@mellanox.com>;
> stefan.sorensen@spectralink.com; brandon.streiff@ni.com; Keller, Jacob E
> <jacob.e.keller@intel.com>; Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>;
> intel-wired-lan@lists.osuosl.org; felipe.balbi@linux.intel.com
> Subject: Re: [PATCH net 06/13] mlx5: reject unsupported external timestamp
> flags
> 
> On Thu, 2019-11-14 at 10:45 -0800, Richard Cochran wrote:
> > From: Jacob Keller <jacob.e.keller@intel.com>
> >
> > Fix the mlx5 core PTP support to explicitly reject any future flags
> > that
> > get added to the external timestamp request ioctl.
> >
> > In order to maintain currently functioning code, this patch accepts
> > all
> > three current flags. This is because the PTP_RISING_EDGE and
> > PTP_FALLING_EDGE flags have unclear semantics and each driver seems
> > to
> > have interpreted them slightly differently.
> >
> > [ RC: I'm not 100% sure what this driver does, but if I'm not wrong
> > it
> >       follows the dp83640:
> >
> 
> The driver will check if the PTP_FALLING_EDGE flag was set then it will
> set it in HW, if not then it is going to default to PTP_RISING_EDGE, so
> LGTM.
> 
> Reviewed-by: Saeed Mahameed <saeedm@mellanox.com>
> 
> But same story here, old tools that lazily set 0xffff or 0x0000 and
> expected every thing to work.. again not sure if they do exist.
> 
> Ariel please have a look at this patch.
> 

As long as they stick to the original ioctls this won't be a problem, because the v1 ioctl now explicitly clears unsupported bits before calling driver, so this check will pass. Obviously, this change should not be backported to earlier than 5.4 without also backporting that masking in the original ioctl functions.

Thanks,
Jake
Ariel Levkovich Nov. 15, 2019, 6:23 p.m. UTC | #3
On 11/14/19 8:15 PM, Keller, Jacob E wrote:
>> -----Original Message-----
>> From: Saeed Mahameed <saeedm@mellanox.com>
>> Sent: Thursday, November 14, 2019 4:03 PM
>> To: Ariel Levkovich <lariel@mellanox.com>; richardcochran@gmail.com;
>> netdev@vger.kernel.org
>> Cc: Hall, Christopher S <christopher.s.hall@intel.com>; Eugenia Emantayev
>> <eugenia@mellanox.com>; davem@davemloft.net;
>> sergei.shtylyov@cogentembedded.com; Feras Daoud <ferasda@mellanox.com>;
>> stefan.sorensen@spectralink.com; brandon.streiff@ni.com; Keller, Jacob E
>> <jacob.e.keller@intel.com>; Kirsher, Jeffrey T <jeffrey.t.kirsher@intel.com>;
>> intel-wired-lan@lists.osuosl.org; felipe.balbi@linux.intel.com
>> Subject: Re: [PATCH net 06/13] mlx5: reject unsupported external timestamp
>> flags
>>
>> On Thu, 2019-11-14 at 10:45 -0800, Richard Cochran wrote:
>>> From: Jacob Keller <jacob.e.keller@intel.com>
>>>
>>> Fix the mlx5 core PTP support to explicitly reject any future flags
>>> that
>>> get added to the external timestamp request ioctl.
>>>
>>> In order to maintain currently functioning code, this patch accepts
>>> all
>>> three current flags. This is because the PTP_RISING_EDGE and
>>> PTP_FALLING_EDGE flags have unclear semantics and each driver seems
>>> to
>>> have interpreted them slightly differently.
>>>
>>> [ RC: I'm not 100% sure what this driver does, but if I'm not wrong
>>> it
>>>        follows the dp83640:
>>>
>> The driver will check if the PTP_FALLING_EDGE flag was set then it will
>> set it in HW, if not then it is going to default to PTP_RISING_EDGE, so
>> LGTM.
>>
>> Reviewed-by: Saeed Mahameed <saeedm@mellanox.com>
>>
>> But same story here, old tools that lazily set 0xffff or 0x0000 and
>> expected every thing to work.. again not sure if they do exist.
>>
>> Ariel please have a look at this patch.
>>
> As long as they stick to the original ioctls this won't be a problem, because the v1 ioctl now explicitly clears unsupported bits before calling driver, so this check will pass. Obviously, this change should not be backported to earlier than 5.4 without also backporting that masking in the original ioctl functions.
>
> Thanks,
> Jake
>
Agree.

Just a small suggestion, you can perform the check with simply 
PTP_EXTTS_V1_VALID_FLAGS. Italready combines all the bits we need to check.

Patch
diff mbox series

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index cff6b60de304..9a40f24e3193 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -236,6 +236,12 @@  static int mlx5_extts_configure(struct ptp_clock_info *ptp,
 	if (!MLX5_PPS_CAP(mdev))
 		return -EOPNOTSUPP;
 
+	/* Reject requests with unsupported flags */
+	if (rq->extts.flags & ~(PTP_ENABLE_FEATURE |
+				PTP_RISING_EDGE |
+				PTP_FALLING_EDGE))
+		return -EOPNOTSUPP;
+
 	if (rq->extts.index >= clock->ptp_info.n_pins)
 		return -EINVAL;