From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 400D819755B for ; Fri, 19 Sep 2025 10:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758279363; cv=none; b=h+soqQfPWrkr3WNC31EpY4oVU/9O0uJfYgdPUBO0jxlunAsIASkyHFTOapk9QZrbi01qPmuJKT3hZOjEKZO46KG8ewfyBW98vo8vLK+PfB3NL72Y8IPKXMfI0EHy9RVjb9QSR+wD2TOCFCT3N2A3dd9aPa3UeKJpAXBk6VN+Ebg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758279363; c=relaxed/simple; bh=e23ONrNwd6j0B7ufboHq4DnDsT30NnxZb/YaBTwxzjc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rq0gUgOOGkW6eT6zD8VRYPiLwMf//5uenvI4baw6oUbXdnxg+Vxiyh7eSaRQkzGXjKBfgT9KDIvdYHuTmSfxdQKTqwGA0pk5FXWTVdDzHmmcyFLGf+lqTmjkPk8mAJN4BGExHeC4uheiwH40K5DLV1jBXJhabrZGhBa6vQ1Gi7o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Y9rD8d5S; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Y9rD8d5S" Message-ID: <9bf5066a-a006-4f93-93fd-38e4c063e59e@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1758279359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5mmmnjsu9xXx/i0h/Qsh8uWABNz0Q9My1OhrKczY0Xc=; b=Y9rD8d5Sbz9S1OKeW/Jp5GeodEl2YYtUqvdsIE1Yb/Dkhie9iiUVtroew6SRci8G1AQzxU ccyz5npLbFup2oDOEjJZKJjvK7qEJaJnyMZpKfZW+BdC5yjWCe4cVbvHrEQw+l9w5cssY+ asYNJxLiThEz/qK2fBy9glSQECLa5ws= Date: Fri, 19 Sep 2025 11:55:56 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [Intel-wired-lan] [PATCH iwl-net v1] igc: fix race condition in TX timestamp read for register 0 To: "Choong, Chwee Lin" , "Keller, Jacob E" , "Nguyen, Anthony L" , "Kitszel, Przemyslaw" , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , "Gomes, Vinicius" Cc: "intel-wired-lan@lists.osuosl.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Shalev, Avi" , "Song, Yoong Siang" References: <20250918183811.31270-1-chwee.lin.choong@intel.com> <0fc877a5-4b35-4802-9cda-e4eca561c5d1@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vadim Fedorenko In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 19/09/2025 08:17, Choong, Chwee Lin wrote: > > On Friday, September 19, 2025 6:11 AM, Keller, Jacob E wrote: >> On 9/18/2025 1:47 PM, Vadim Fedorenko wrote: >>> On 18/09/2025 19:38, Chwee-Lin Choong wrote: >>>> The current HW bug workaround checks the TXTT_0 ready bit first, then >>>> reads LOW -> HIGH -> LOW from register 0 to detect if a timestamp was >>>> captured. >>>> >>>> This sequence has a race: if a new timestamp is latched after reading >>>> the TXTT mask but before the first LOW read, both old and new >>>> timestamp match, causing the driver to drop a valid timestamp. >>>> >>>> Fix by reading the LOW register first, then the TXTT mask, so a newly >>>> latched timestamp will always be detected. >>>> >>>> This fix also prevents TX unit hangs observed under heavy >>>> timestamping load. >>>> >>>> Fixes: c789ad7cbebc ("igc: Work around HW bug causing missing >>>> timestamps") >>>> Suggested-by: Avi Shalev >>>> Signed-off-by: Song Yoong Siang >>>> Signed-off-by: Chwee-Lin Choong >>>> --- >>>> drivers/net/ethernet/intel/igc/igc_ptp.c | 10 ++++++++-- >>>> 1 file changed, 8 insertions(+), 2 deletions(-) >>>> >>> >>> [...] >>> >>>> * timestamp was captured, we can read the "high" >>>> * register again. >>>> */ >>> >>> This comment begins with 'read the "high" register (to latch a new >>> timestamp)' ... >>> >>>> - u32 txstmpl_old, txstmpl_new; >>>> + u32 txstmpl_new; >>>> >>>> - txstmpl_old = rd32(IGC_TXSTMPL); >>>> rd32(IGC_TXSTMPH); >>>> txstmpl_new = rd32(IGC_TXSTMPL); >>> >>> and a couple of lines later in this function you have >>> >>> regval = txstmpl_new; >>> regval |= (u64)rd32(IGC_TXSTMPH) << 32; >>> >>> According to the comment above, the value in the register will be >>> latched after reading IGC_TXSTMPH. As there will be no read of "low" >>> part of the register, it will stay latched with old value until the >>> next call to the same function. Could it be the reason of unit hangs? >>> >>> It looks like the value of previous read of IGC_TXSTMPH should be >>> stored and used to construct new timestamp, right? >>> >> >> I wouldn't trust the comment, but instead double check the data sheets. >> Unfortunately, I don't seem to have a copy of the igc hardware data sheet handy :( >> >> Thanks, >> Jake > > Flow before this patch: > 1. Read the TXTT bits into mask > 2. if TXTT_0 == 0, go to workaround ->If at this point register 0 captures TX timestamp, and TXTT_0 is set but we think it is 0. > 3. Read LOW to OLD > 4. Read HIGH – this clears the TXTT_0 > 5. Read LOW again , now to NEW. > 6. NEW==OLD, so the timestamp is discarded -> causing timestamp timeout > > Flow after this patch: > 1. Read LOW to OLD > 2. Read the TXTT bits into mask > 3. if TXTT_0 == 0, go to workaround -> If at this point register 0 captures TX timestamp, and TXTT_0 is set but we think it is 0. > 4. Read HIGH – this clears the TXTT_0 > 5. Read LOW again , now to NEW. > 6. NEW!=OLD, so we detect this is a valid timestamp > 7. Read HIGH again and use the timestamp > > Let me know if this address your questions? Unfortunately, it doesn't. The question is "what will happen to register after step 7?" The comment above says it will stay latched until LOW is read, will it affect performance/stability?