From: Jacob Keller <jacob.e.keller@intel.com>
To: Intel Wired LAN <intel-wired-lan@lists.osuosl.org>
Subject: [Intel-wired-lan] [PATCH net-next v3 08/15] ice: synchronize the misc IRQ when tearing down Tx tracker
Date: Mon, 5 Dec 2022 11:52:46 -0800 [thread overview]
Message-ID: <20221205195253.2475492-9-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20221205195253.2475492-1-jacob.e.keller@intel.com>
Since commit 1229b33973c7 ("ice: Add low latency Tx timestamp read") the
ice driver has used a threaded IRQ for handling Tx timestamps. This change
did not add a call to synchronize_irq during ice_ptp_release_tx_tracker.
Thus it is possible that an interrupt could occur just as the tracker is
being removed. This could lead to a use-after-free of the Tx tracker
structure data.
Fix this by calling sychronize_irq in ice_ptp_release_tx_tracker after
we've cleared the init flag. In addition, make sure that we re-check the
init flag at the end of ice_ptp_tx_tstamp before we exit ensuring that we
will stop polling for new timestamps once the tracker de-initialization has
begun.
Refactor the ts_handled variable into "more_timestamps" so that we can
simply directly assign this boolean instead of relying on an initialized
value of true. This makes the new combined check easier to read.
With this change, the ice_ptp_release_tx_tracker function will now wait for
the threaded interrupt to complete if it was executing while the init flag
was cleared.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
New patch since v2:
* This was pointed out by me as I reviewed comments from Leon at
https://lore.kernel.org/netdev/ba949af0-7de6-ab12-6501-46a5af06001f@intel.com/
drivers/net/ethernet/intel/ice/ice_ptp.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
index 30061598912b..0282ccc55819 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -656,7 +656,7 @@ static u64 ice_ptp_extend_40b_ts(struct ice_pf *pf, u64 in_tstamp)
static bool ice_ptp_tx_tstamp(struct ice_ptp_tx *tx)
{
struct ice_ptp_port *ptp_port;
- bool ts_handled = true;
+ bool more_timestamps;
struct ice_pf *pf;
struct ice_hw *hw;
u64 tstamp_ready;
@@ -761,11 +761,10 @@ static bool ice_ptp_tx_tstamp(struct ice_ptp_tx *tx)
* poll for remaining timestamps.
*/
spin_lock(&tx->lock);
- if (!bitmap_empty(tx->in_use, tx->len))
- ts_handled = false;
+ more_timestamps = tx->init && !bitmap_empty(tx->in_use, tx->len);
spin_unlock(&tx->lock);
- return ts_handled;
+ return !more_timestamps;
}
/**
@@ -836,6 +835,9 @@ ice_ptp_release_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx)
{
tx->init = 0;
+ /* wait for potentially outstanding interrupt to complete */
+ synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
+
ice_ptp_flush_tx_tracker(pf, tx);
kfree(tx->tstamps);
--
2.38.1.420.g319605f8f00e
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
next prev parent reply other threads:[~2022-12-05 19:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 19:52 [Intel-wired-lan] [PATCH net-next v3 00/15] ice: improve Tx timestamp corner cases Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 01/15] ice: Use more generic names for ice_ptp_tx fields Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 02/15] ice: Remove the E822 vernier "bypass" logic Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 03/15] ice: Reset TS memory for all quads Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 04/15] ice: fix misuse of "link err" with "link status" Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 05/15] ice: always call ice_ptp_link_change and make it void Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 06/15] ice: handle discarding old Tx requests in ice_ptp_tx_tstamp Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 07/15] ice: check Tx timestamp memory register for ready timestamps Jacob Keller
2022-12-05 19:52 ` Jacob Keller [this message]
2022-12-07 9:04 ` [Intel-wired-lan] [PATCH net-next v3 08/15] ice: synchronize the misc IRQ when tearing down Tx tracker G, GurucharanX
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 09/15] ice: protect init and calibrating check in ice_ptp_request_ts Jacob Keller
2022-12-07 9:05 ` G, GurucharanX
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 10/15] ice: disable Tx timestamps while link is down Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 11/15] ice: cleanup allocations in ice_ptp_alloc_tx_tracker Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 12/15] ice: handle flushing stale Tx timestamps in ice_ptp_tx_tstamp Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 13/15] ice: only check set bits in ice_ptp_flush_tx_tracker Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 14/15] ice: make Tx and Rx vernier offset calibration independent Jacob Keller
2022-12-05 19:52 ` [Intel-wired-lan] [PATCH net-next v3 15/15] ice: reschedule ice_ptp_wait_for_offset_valid during reset Jacob Keller
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=20221205195253.2475492-9-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=intel-wired-lan@lists.osuosl.org \
/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