netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Keller, Jacob E" <jacob.e.keller@intel.com>
To: Jakub Kicinski <kuba@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Cc: "Nguyen, Anthony L" <anthony.l.nguyen@intel.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"sassmann@redhat.com" <sassmann@redhat.com>,
	"Brelinski, TonyX" <tonyx.brelinski@intel.com>
Subject: RE: [PATCH net-next 5/8] ice: register 1588 PTP clock device object for E810 devices
Date: Mon, 14 Jun 2021 19:48:28 +0000	[thread overview]
Message-ID: <95887203e7094ffea2306c2130c2b7d6@intel.com> (raw)
In-Reply-To: <20210614115043.4e2b48da@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>



> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Monday, June 14, 2021 11:51 AM
> To: Richard Cochran <richardcochran@gmail.com>
> Cc: Keller, Jacob E <jacob.e.keller@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; davem@davemloft.net;
> netdev@vger.kernel.org; sassmann@redhat.com; Brelinski, TonyX
> <tonyx.brelinski@intel.com>
> Subject: Re: [PATCH net-next 5/8] ice: register 1588 PTP clock device object for
> E810 devices
> 
> On Mon, 14 Jun 2021 11:12:20 -0700 Richard Cochran wrote:
> > On Mon, Jun 14, 2021 at 09:43:17AM -0700, Jacob Keller wrote:
> > > > Since dialed_freq is updated regardless of return value of .adjfine
> > > > the driver has no clear way to reject bad scaled_ppm>
> > >
> > > I'm not sure. +Richard?
> >
> > The driver advertises "max_adj".  The PHC layer checks user space inputs:
> >
> > ptp_clock.c line 140:
> > 	} else if (tx->modes & ADJ_FREQUENCY) {
> > 		s32 ppb = scaled_ppm_to_ppb(tx->freq);
> > 		if (ppb > ops->max_adj || ppb < -ops->max_adj)
> > 			return -ERANGE;
> >
> > So, if the max_adj is correct for the driver/HW, then all is well.
> 
> tx->freq is a long, and the conversion to ppb can overflow the s32 type.
> E.g. 281474976645 will become -2 AFAICT. I hacked up phc_ctl to not do
> range checking and kernel happily accepted that value. Shall we do this?
> 
> --->8----
> 
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index 03a246e60fd9..ed32fc98d9d8 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -63,7 +63,7 @@ static void enqueue_external_timestamp(struct
> timestamp_event_queue *queue,
>         spin_unlock_irqrestore(&queue->lock, flags);
>  }
> 
> -s32 scaled_ppm_to_ppb(long ppm)
> +s64 scaled_ppm_to_ppb(long ppm)
>  {
>         /*
>          * The 'freq' field in the 'struct timex' is in parts per
> @@ -80,7 +80,7 @@ s32 scaled_ppm_to_ppb(long ppm)
>         s64 ppb = 1 + ppm;
>         ppb *= 125;
>         ppb >>= 13;
> -       return (s32) ppb;
> +       return ppb;
>  }
>  EXPORT_SYMBOL(scaled_ppm_to_ppb);
> 
> @@ -138,7 +138,7 @@ static int ptp_clock_adjtime(struct posix_clock *pc, struct
> __kernel_timex *tx)
>                 delta = ktime_to_ns(kt);
>                 err = ops->adjtime(ops, delta);
>         } else if (tx->modes & ADJ_FREQUENCY) {
> -               s32 ppb = scaled_ppm_to_ppb(tx->freq);
> +               s64 ppb = scaled_ppm_to_ppb(tx->freq);
>                 if (ppb > ops->max_adj || ppb < -ops->max_adj)
>                         return -ERANGE;
>                 if (ops->adjfine)

This looks correct to me.

  reply	other threads:[~2021-06-14 19:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11 16:19 [PATCH net-next 0/8][pull request] 100GbE Intel Wired LAN Driver Updates 2021-06-11 Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 1/8] ice: add support for sideband messages Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 2/8] ice: process 1588 PTP capabilities during initialization Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 3/8] ice: add support for set/get of driver-stored firmware parameters Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 4/8] ice: add low level PTP clock access functions Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 5/8] ice: register 1588 PTP clock device object for E810 devices Tony Nguyen
2021-06-11 21:18   ` Jakub Kicinski
2021-06-14 16:43     ` Jacob Keller
2021-06-14 18:08       ` Jakub Kicinski
2021-06-14 19:50         ` Keller, Jacob E
2021-06-14 20:48           ` Jakub Kicinski
2021-06-14 20:51             ` Jacob Keller
2021-06-14 22:25               ` Jakub Kicinski
2021-06-14 18:12       ` Richard Cochran
2021-06-14 18:50         ` Jakub Kicinski
2021-06-14 19:48           ` Keller, Jacob E [this message]
2021-06-15  5:08           ` Richard Cochran
2021-06-11 16:19 ` [PATCH net-next 6/8] ice: report the PTP clock index in ethtool .get_ts_info Tony Nguyen
2021-06-11 16:19 ` [PATCH net-next 7/8] ice: enable receive hardware timestamping Tony Nguyen
2021-06-11 16:20 ` [PATCH net-next 8/8] ice: enable transmit timestamps for E810 devices Tony Nguyen
2021-06-11 21:00 ` [PATCH net-next 0/8][pull request] 100GbE Intel Wired LAN Driver Updates 2021-06-11 patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=95887203e7094ffea2306c2130c2b7d6@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=sassmann@redhat.com \
    --cc=tonyx.brelinski@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).