Intel-Wired-Lan Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Kurt Kanzenbach <kurt@linutronix.de>
To: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	intel-wired-lan@lists.osuosl.org
Cc: Andre Guedes <andre.guedes@intel.com>,
	vladimir.oltean@nxp.com, anthony.l.nguyen@intel.com
Subject: Re: [Intel-wired-lan] [PATCH iwl v1 2/5] igc: Fix race condition in PTP tx code
Date: Fri, 05 May 2023 11:51:17 +0200	[thread overview]
Message-ID: <87cz3fumwa.fsf@kurt> (raw)
In-Reply-To: <20230504235233.1850428-3-vinicius.gomes@intel.com>


[-- Attachment #1.1: Type: text/plain, Size: 1983 bytes --]

On Thu May 04 2023, Vinicius Costa Gomes wrote:
> Currently, the igc driver supports timestamping only one tx packet at a
> time. During the transmission flow, the skb that requires hardware
> timestamping is saved in adapter->ptp_tx_skb. Once hardware has the
> timestamp, an interrupt is delivered, and adapter->ptp_tx_work is
> scheduled. In igc_ptp_tx_work(), we read the timestamp register, update
> adapter->ptp_tx_skb, and notify the network stack.
>
> While the thread executing the transmission flow (the user process
> running in kernel mode) and the thread executing ptp_tx_work don't
> access adapter->ptp_tx_skb concurrently, there are two other places
> where adapter->ptp_tx_skb is accessed: igc_ptp_tx_hang() and
> igc_ptp_suspend().
>
> igc_ptp_tx_hang() is executed by the adapter->watchdog_task worker
> thread which runs periodically so it is possible we have two threads
> accessing ptp_tx_skb at the same time. Consider the following scenario:
> right after __IGC_PTP_TX_IN_PROGRESS is set in igc_xmit_frame_ring(),
> igc_ptp_tx_hang() is executed. Since adapter->ptp_tx_start hasn't been
> written yet, this is considered a timeout and adapter->ptp_tx_skb is
> cleaned up.
>
> This patch fixes the issue described above by adding the ptp_tx_lock to
> protect access to ptp_tx_skb and ptp_tx_start fields from igc_adapter.
> Since igc_xmit_frame_ring() called in atomic context by the networking
> stack, ptp_tx_lock is defined as a spinlock.

... and you use the _irqsave/restore variants, because patch #4 is going
to retrieve the timestamp directly from the IRQ context.

>
> With the introduction of the ptp_tx_lock, the __IGC_PTP_TX_IN_PROGRESS
> flag doesn't provide much of a use anymore so this patch gets rid of it.
>
> Fixes: 2c344ae24501 ("igc: Add support for TX timestamping")
> Signed-off-by: Andre Guedes <andre.guedes@intel.com>
> Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

[-- Attachment #2: Type: text/plain, Size: 162 bytes --]

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

  reply	other threads:[~2023-05-05  9:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 23:52 [Intel-wired-lan] [PATCH iwl v1 0/5] igc: TX timestamping fixes Vinicius Costa Gomes
2023-05-04 23:52 ` [Intel-wired-lan] [PATCH iwl v1 1/5] igc: Fix marking some timestamps as skipped wrongly Vinicius Costa Gomes
2023-05-05  9:49   ` Kurt Kanzenbach
2023-05-04 23:52 ` [Intel-wired-lan] [PATCH iwl v1 2/5] igc: Fix race condition in PTP tx code Vinicius Costa Gomes
2023-05-05  9:51   ` Kurt Kanzenbach [this message]
2023-05-04 23:52 ` [Intel-wired-lan] [PATCH iwl v1 3/5] igc: Fix checking for tstamp timeouts TX tstamp is off Vinicius Costa Gomes
2023-05-05  9:51   ` Kurt Kanzenbach
2023-05-04 23:52 ` [Intel-wired-lan] [PATCH iwl v1 4/5] igc: Retrieve TX timestamp during interrupt handling Vinicius Costa Gomes
2023-05-05  9:51   ` Kurt Kanzenbach
2023-05-04 23:52 ` [Intel-wired-lan] [PATCH iwl v1 5/5] igc: Add workaround for missing timestamps Vinicius Costa Gomes
2023-05-08 20:55 ` [Intel-wired-lan] [PATCH iwl v1 0/5] igc: TX timestamping fixes Tony Nguyen
2023-05-08 22:18   ` Vinicius Costa Gomes
2023-05-09 17:23     ` Tony Nguyen
2023-05-09 20:51       ` Vinicius Costa Gomes

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=87cz3fumwa.fsf@kurt \
    --to=kurt@linutronix.de \
    --cc=andre.guedes@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=vinicius.gomes@intel.com \
    --cc=vladimir.oltean@nxp.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