Received: by 10.192.165.156 with SMTP id m28csp1114784imm; Wed, 11 Apr 2018 12:42:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx48XIdUGlPVKTj77DzRsrZI2IfD5iihyWUGx6GUONvCJLScDJrWLy2VSS+EdDtj9iPHh52ns X-Received: by 2002:a17:902:8c8c:: with SMTP id t12-v6mr6476115plo.100.1523475754354; Wed, 11 Apr 2018 12:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523475754; cv=none; d=google.com; s=arc-20160816; b=KLJZjn9ppzCTH4BVhG1cPWD0+rmM1Q/eBBlAaGBImNzeLMKLlOtaJbOOs7/2mZrnqm h36sKo+O5H4IkbUL8zqE329gWmd1mZVX2eqZIV2u89tNQzsMs/aOaCGIl4QgBUsicmRH 3eQZDTSLB0QFB2er12D3QQ9LFvHD35uP2Fy1JQzjv/alhMWIMU8gmTfTEW20koAr4hNy SLGelhOgTMkGL0bc9YN0SMicLGqK2DPXEXHaHNx7OoIDmlDMjIXSfb7mytkjwnf+Ce0v kqKMPdLrdQOv1cbZ96u4eh2qKVWM6Jxzcha2iHv+iRx0hkJ1mimN/rP1fkRJLA1dSdPB rWCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=um+L26S3aRPI1ERO5jBju3AKlBaLBKUYe9XHhqRXFOk=; b=Q/BH9V4FVOuQI4BE8572zTXl4ozUYJUzkhHuDa7N4mlp7jFKQTbzSqaHR1JzvisgCE xcZaw+1n7ZpQhVIx9lxYGlgN+8nCW/wep3iXgmb56dpN4XcGvqKSWiBSKOvORNogQloQ JwWnqk+9zvKv+AJTMeUwB1E0ZJpkeQ/RdK6CjihYVJGYieYKQRlxqV2bC8W/JDHdN1hP c5Kzo+eXYFWrXmbxmprqi23nj6clB0Mwnc6S+NheaL7aeNhUawSiU0bqgiaoTOufES3L QPgwMA6fA8so4L92gVVraEcXQB8lChrxY7aMR2Sjp9lXtZzsBS/ItmvueaENBmaY7/// LoXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a64si1116204pgc.265.2018.04.11.12.41.57; Wed, 11 Apr 2018 12:42:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934390AbeDKTCL (ORCPT + 99 others); Wed, 11 Apr 2018 15:02:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38414 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934356AbeDKTCH (ORCPT ); Wed, 11 Apr 2018 15:02:07 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BCADCE30; Wed, 11 Apr 2018 19:02:06 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Mirabito , Jacob Keller , Aaron Brown , Jeff Kirsher , Sasha Levin Subject: [PATCH 4.9 206/310] igb: fix race condition with PTP_TX_IN_PROGRESS bits Date: Wed, 11 Apr 2018 20:35:45 +0200 Message-Id: <20180411183631.431217258@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jacob Keller [ Upstream commit 4ccdc013b0ae04755a8f7905e0525955d52a77d0 ] Hardware related to the igb driver has a limitation of only handling one Tx timestamp at a time. Thus, the driver uses a state bit lock to enforce that only one timestamp request is honored at a time. Unfortunately this suffers from a simple race condition. The bit lock is not cleared until after skb_tstamp_tx() is called notifying the stack of a new Tx timestamp. Even a well behaved application which sends only one timestamp request at once and waits for a response might wake up and send a new packet before the bit lock is cleared. This results in needlessly dropping some Tx timestamp requests. We can fix this by unlocking the state bit as soon as we read the Timestamp register, as this is the first point at which it is safe to unlock. To avoid issues with the skb pointer, we'll use a copy of the pointer and set the global variable in the driver structure to NULL first. This ensures that the next timestamp request does not modify our local copy of the skb pointer. This ensures that well behaved applications do not accidentally race with the unlock bit. Obviously an application which sends multiple Tx timestamp requests at once will still only timestamp one packet at a time. Unfortunately there is nothing we can do about this. Reported-by: David Mirabito Signed-off-by: Jacob Keller Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/intel/igb/igb_ptp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/intel/igb/igb_ptp.c +++ b/drivers/net/ethernet/intel/igb/igb_ptp.c @@ -721,6 +721,7 @@ void igb_ptp_rx_hang(struct igb_adapter **/ static void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter) { + struct sk_buff *skb = adapter->ptp_tx_skb; struct e1000_hw *hw = &adapter->hw; struct skb_shared_hwtstamps shhwtstamps; u64 regval; @@ -748,10 +749,17 @@ static void igb_ptp_tx_hwtstamp(struct i shhwtstamps.hwtstamp = ktime_add_ns(shhwtstamps.hwtstamp, adjust); - skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps); - dev_kfree_skb_any(adapter->ptp_tx_skb); + /* Clear the lock early before calling skb_tstamp_tx so that + * applications are not woken up before the lock bit is clear. We use + * a copy of the skb pointer to ensure other threads can't change it + * while we're notifying the stack. + */ adapter->ptp_tx_skb = NULL; clear_bit_unlock(__IGB_PTP_TX_IN_PROGRESS, &adapter->state); + + /* Notify the stack and free the skb after we've unlocked */ + skb_tstamp_tx(skb, &shhwtstamps); + dev_kfree_skb_any(skb); } /**