From: "Keller, Jacob E" <jacob.e.keller@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "Nguyen, Anthony L" <anthony.l.nguyen@intel.com>,
Richard Cochran <richardcochran@gmail.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:50:23 +0000 [thread overview]
Message-ID: <427ddb2579f14d77b537aae9c2fa9759@intel.com> (raw)
In-Reply-To: <20210614110831.65d21c8b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Monday, June 14, 2021 11:09 AM
> To: Keller, Jacob E <jacob.e.keller@intel.com>
> Cc: Nguyen, Anthony L <anthony.l.nguyen@intel.com>; Richard Cochran
> <richardcochran@gmail.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 09:43:17 -0700 Jacob Keller wrote:
> > >> +static int ice_ptp_adjfine(struct ptp_clock_info *info, long scaled_ppm)
> > >> +{
> > >> + struct ice_pf *pf = ptp_info_to_pf(info);
> > >> + u64 freq, divisor = 1000000ULL;
> > >> + struct ice_hw *hw = &pf->hw;
> > >> + s64 incval, diff;
> > >> + int neg_adj = 0;
> > >> + int err;
> > >> +
> > >> + incval = ICE_PTP_NOMINAL_INCVAL_E810;
> > >> +
> > >> + if (scaled_ppm < 0) {
> > >> + neg_adj = 1;
> > >> + scaled_ppm = -scaled_ppm;
> > >> + }
> > >> +
> > >> + while ((u64)scaled_ppm > div_u64(U64_MAX, incval)) {
> > >> + /* handle overflow by scaling down the scaled_ppm and
> > >> + * the divisor, losing some precision
> > >> + */
> > >> + scaled_ppm >>= 2;
> > >> + divisor >>= 2;
> > >> + }
> > >
> > > I have a question regarding ppm overflows.
> > >
> > > We have the max_adj field in struct ptp_clock_info which is checked
> > > against ppb, but ppb is a signed 32 bit and scaled_ppm is a long,
> > > meaning values larger than S32_MAX << 16 / 1000 will overflow
> > > the ppb calculation, and therefore the check.
> >
> > Hmmm.. I thought ppb was a s64, not an s32.
> >
> > In general, I believe max_adj is usually capped at 1 billion anyways,
> > since it doesn't make sense to slow a clock by more than 1billioln ppb,
> > and increasing it more than that isn't really useful either.
>
> Do you mean it's capped somewhere in the code to 1B?
>
> I'm no time expert but this is not probability where 1 is a magic
> value, adjusting clock by 1 - 1ppb vs 1 + 1ppb makes little difference,
> no? Both mean something is super fishy with the nominal or expected
> frequency, but the hardware can do that and more.
>
> Flipping the question, if adjusting by large ppb values is not correct,
> why not cap the adjustment at the value which would prevent the u64
> overflow?
Large ppb values are sometimes used when you want to slew a clock to bring it in sync when its a few milliseconds to seconds off, without performing a time jump (so that you maintain monotonic increasing time).
That being said, we are supposed to be checking max_adj, except that you're right the conversion to ppb could overflow, and there's no check prior to the conversion from scaled_ppm to ppb.
>
> I don't really have a preferences here, I'm mostly disturbed by
> the overflow in the ppb vs max_adj check.
>
> > > Are we okay with that? Is my math off? Did I miss some part
> > > of the kernel which filters crazy high scaled_ppm/freq?
> > >
> > > 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?
next prev parent reply other threads:[~2021-06-14 19:50 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 [this message]
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
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=427ddb2579f14d77b537aae9c2fa9759@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.