netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andre Guedes <andre.guedes@intel.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>,
	davem@davemloft.net, netdev@vger.kernel.org, nhorman@redhat.com,
	sassmann@redhat.com, Aaron Brown <aaron.f.brown@intel.com>
Subject: Re: [net-next 05/13] igc: Check __IGC_PTP_TX_IN_PROGRESS instead of ptp_tx_skb
Date: Mon, 29 Jun 2020 17:07:00 -0700	[thread overview]
Message-ID: <159347562079.35713.11550779660753529150@shabnaja-mobl.amr.corp.intel.com> (raw)
In-Reply-To: <20200629151117.63b466c0@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>

Quoting Jakub Kicinski (2020-06-29 15:11:17)
> On Mon, 29 Jun 2020 13:51:32 -0700 Andre Guedes wrote:
> > > > @@ -435,6 +432,9 @@ static void igc_ptp_tx_hwtstamp(struct igc_adapter *adapter)
> > > >       struct igc_hw *hw = &adapter->hw;
> > > >       u64 regval;
> > > >  
> > > > +     if (WARN_ON_ONCE(!skb))
> > > > +             return;
> > > > +
> > > >       regval = rd32(IGC_TXSTMPL);
> > > >       regval |= (u64)rd32(IGC_TXSTMPH) << 32;
> > > >       igc_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
> > > > @@ -466,7 +466,7 @@ static void igc_ptp_tx_work(struct work_struct *work)
> > > >       struct igc_hw *hw = &adapter->hw;
> > > >       u32 tsynctxctl;
> > > >  
> > > > -     if (!adapter->ptp_tx_skb)
> > > > +     if (!test_bit(__IGC_PTP_TX_IN_PROGRESS, &adapter->state))
> > > >               return;  
> > > 
> > > Not that reading ptp_tx_skb is particularly correct here, but I think
> > > it's better. See how they get set:
> > > 
> > >                 if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
> > >                     !test_and_set_bit_lock(__IGC_PTP_TX_IN_PROGRESS,
> > >                                            &adapter->state)) {
> > >                         skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
> > >                         tx_flags |= IGC_TX_FLAGS_TSTAMP;
> > > 
> > >                         adapter->ptp_tx_skb = skb_get(skb);
> > >                         adapter->ptp_tx_start = jiffies;
> > > 
> > > bit is set first and other fields after. Since there is no locking here
> > > we may just see the bit but none of the fields set.  
> > 
> > I see your point, but note that the code within the if-block and the code in
> > igc_ptp_tx_work() don't execute concurrently. adapter->ptp_tx_work is scheduled
> > only on a time-sync interrupt, which is triggered if IGC_TX_FLAGS_TSTAMP is
> > set (so adapter->ptp_tx_skb is valid).
> 
> What if timeout happens, igc_ptp_tx_hang() starts cleaning up and then
> irq gets delivered half way through? Perhaps we should just add a spin
> lock around the ptp_tx_s* fields?

Yep, I think this other scenario is possible indeed, and we should probably
protect ptp_tx_s* with a lock. Thanks for pointing that out. In fact, it seems
this issue can happen even with current net-next code.

Since that issue is not introduced by this patch, would it be OK we move forward
with it, and fix the issue in a separate patch?

- Andre

  reply	other threads:[~2020-06-30  0:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-27  1:54 [net-next 00/13][pull request] 1GbE Intel Wired LAN Driver Updates 2020-06-26 Jeff Kirsher
2020-06-27  1:54 ` [net-next 01/13] igc: Add initial EEE support Jeff Kirsher
2020-06-28  0:28   ` David Miller
2020-06-27  1:54 ` [net-next 02/13] igc: Add initial LTR support Jeff Kirsher
2020-06-27  1:54 ` [net-next 03/13] igc: Clean up Rx timestamping logic Jeff Kirsher
2020-06-27  1:54 ` [net-next 04/13] igc: Remove duplicate code in Tx timestamp handling Jeff Kirsher
2020-06-27  1:54 ` [net-next 05/13] igc: Check __IGC_PTP_TX_IN_PROGRESS instead of ptp_tx_skb Jeff Kirsher
2020-06-27  4:30   ` Jakub Kicinski
2020-06-29 20:51     ` Andre Guedes
2020-06-29 22:11       ` Jakub Kicinski
2020-06-30  0:07         ` Andre Guedes [this message]
2020-06-30  0:19           ` Jakub Kicinski
2020-06-30  0:23             ` Kirsher, Jeffrey T
2020-06-27  1:54 ` [net-next 06/13] igc: Remove UDP filter setup in PTP code Jeff Kirsher
2020-06-27  1:54 ` [net-next 07/13] igc: Refactor igc_ptp_set_timestamp_mode() Jeff Kirsher
2020-06-27  1:54 ` [net-next 08/13] igc: Fix Rx timestamp disabling Jeff Kirsher
2020-06-27  1:54 ` [net-next 09/13] igc: Add LPI counters Jeff Kirsher
2020-06-27  1:54 ` [net-next 10/13] igc: Remove TCP segmentation TX fail counter Jeff Kirsher
2020-06-27  1:54 ` [net-next 11/13] igc: Refactor the igc_power_down_link() Jeff Kirsher
2020-06-27  1:54 ` [net-next 12/13] igc: Remove unneeded check for copper media type Jeff Kirsher
2020-06-27  1:54 ` [net-next 13/13] igc: Remove checking media type during MAC initialization Jeff Kirsher

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=159347562079.35713.11550779660753529150@shabnaja-mobl.amr.corp.intel.com \
    --to=andre.guedes@intel.com \
    --cc=aaron.f.brown@intel.com \
    --cc=davem@davemloft.net \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.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).