linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Arnd Bergmann" <arnd@kernel.org>,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Tianfei Zhang" <tianfei.zhang@intel.com>,
	"Jonathan Lemon" <jonathan.lemon@gmail.com>,
	"Vadim Fedorenko" <vadim.fedorenko@linux.dev>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Calvin Owens" <calvin@wbinvd.org>,
	"Philipp Stanner" <pstanner@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-fpga@vger.kernel.org
Subject: Re: [PATCH] RFC: ptp: add comment about register access race
Date: Sun, 2 Mar 2025 12:55:08 -0800	[thread overview]
Message-ID: <Z8TFrPv1oajA3H4V@hoboy.vegasvil.org> (raw)
In-Reply-To: <Z8CDhIN5vhcSm1ge@smile.fi.intel.com>

On Thu, Feb 27, 2025 at 05:23:48PM +0200, Andy Shevchenko wrote:
> On Thu, Feb 27, 2025 at 03:17:27PM +0100, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> > 
> > While reviewing a patch to the ioread64_hi_lo() helpers, I noticed
> > that there are several PTP drivers that use multiple register reads
> > to access a 64-bit hardware register in a racy way.
> > 
> > There are usually safe ways of doing this, but at least these four
> > drivers do that.  A third register read obviously makes the hardware
> > access 50% slower. If the low word counds nanoseconds and a single
> > register read takes on the order of 1µs, the resulting value is
> > wrong in one of 4 million cases, which is pretty rare but common
> > enough that it would be observed in practice.

If the hardware does NOT latch the registers together, then the driver must do:

  1. hi1 = read hi
  2. low = read lo
  3. hi2 = read h1
  4. if (hi2 == hi1 return (hi1 << 32) | low;
  5. goto step 1.

This for correctness, and correctness > performance.

> > Sorry I hadn't sent this out as a proper patch so far. Any ideas
> > what we should do here?

Need to have driver authors check the data sheet because ...

> Actually this reminds me one of the discussion where it was some interesting
> HW design that latches the value on the first read of _low_ part (IIRC), but
> I might be mistaken with the details.
> 
> That said, it's from HW to HW, it might be race-less in some cases.

... of this.

Thanks,
Richard

  reply	other threads:[~2025-03-02 20:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27 14:17 [PATCH] RFC: ptp: add comment about register access race Arnd Bergmann
2025-02-27 15:23 ` Andy Shevchenko
2025-03-02 20:55   ` Richard Cochran [this message]
2025-03-03  7:50     ` Andy Shevchenko
2025-03-04  4:09       ` Richard Cochran
2025-03-04  8:24         ` Arnd Bergmann

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=Z8TFrPv1oajA3H4V@hoboy.vegasvil.org \
    --to=richardcochran@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=calvin@wbinvd.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pstanner@redhat.com \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=tianfei.zhang@intel.com \
    --cc=vadim.fedorenko@linux.dev \
    /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).