Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2673477pxj; Mon, 31 May 2021 07:59:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm7AqmUSJJ4h9PiAxcVa7yQMaTHubQTiSdPDqZtfIjFvEkwO7sWYPmal9Ji6CDGoBh36lU X-Received: by 2002:a92:7403:: with SMTP id p3mr7200589ilc.290.1622473146520; Mon, 31 May 2021 07:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622473146; cv=none; d=google.com; s=arc-20160816; b=JAlsE2sxjYfkaZrQuLDM+lbe9avxv9p+mRb8ul+2hPufP+/2DfqdiQaZb2K3QeYoO7 As5w9BuOxflZ7G8tJoZ2ktXHkFsUhUunxJYh4NqefAO0dLge/LMWdA/ZVgLD4cjktnmp 8wGPvURr3KQ3QWnmIh+PMO+Zv7B6/OT5Zt450cLANOffcSBOTIwrPcyqcC9qMyKEhT3j NNeiA9+kja6FMLmr3Nt5mIHFimXxI5pEmCxPYCb8vvW8onRPxsDCGvvfhns5uQbkEdIh QaKp23m79hoH09RIlLMz3Fxfh4G+0DO2ulg/XvqbRatq7Iu4ufBxHDxgX+bcZYvGTWaq soeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ETDQsKJk4atBTnmjX9cu5CDN5egklU9YGL9n7QZHXSc=; b=MLzQ396LwVIVFzagZKl8jYI0JZl/xccq1NdFylpeKWQ8jRprwpN/r9QCEEy1eUbBoo YK6e5xX8nmmsaSupQDfeye/p4xwrQA1fyUdA/yKlEizfhtFcdkng1QoGnVyoZflRKl5B nJ//qH7uLy/R2cH1dJVxoaGbb3KU+iDYcvcFHf9+Ajh8Bp6x8O9jnmS4v6gIuUUAVdkK XqcZfZlwaV4e2QCfLRYs4eOELsOKP4Xxqw0Zw82V5nL7vYvlhMh6ReJUEhQbQa3RFWFR Ab/v/3q6bONJ3kxRETlmYhChp264ZzBannApna1kYCA0ygIBvn5wTLbXQoFpv0c6v2JR Ko5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cycSiKPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y17si1196006iod.74.2021.05.31.07.58.53; Mon, 31 May 2021 07:59:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cycSiKPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234426AbhEaO7c (ORCPT + 99 others); Mon, 31 May 2021 10:59:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:36982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232409AbhEaOFa (ORCPT ); Mon, 31 May 2021 10:05:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A3BAD6195B; Mon, 31 May 2021 13:38:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468318; bh=ebNnMwwjjVv80bNKpOOVN10orfa088utWhEJctIc40c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cycSiKPVbC9PBgn4jkPwj9V1YfI1o91Kj43YN6CmpPv32AAubMLFbvemxSwrHzXkC RyFPeEeg8AYTdVRpd6h9Jo/k5tJPFS+aa0/rdHZLlBaDkgKlQPbP4ey2fB4IaRePEo PS8DVKB5M6N828pcGYxX0dgar6h8O8zyWkhaWZRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Willem de Bruijn , Richard Sanger , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 199/252] net: packetmmap: fix only tx timestamp on request Date: Mon, 31 May 2021 15:14:24 +0200 Message-Id: <20210531130704.780472179@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Sanger [ Upstream commit 171c3b151118a2fe0fc1e2a9d1b5a1570cfe82d2 ] The packetmmap tx ring should only return timestamps if requested via setsockopt PACKET_TIMESTAMP, as documented. This allows compatibility with non-timestamp aware user-space code which checks tp_status == TP_STATUS_AVAILABLE; not expecting additional timestamp flags to be set in tp_status. Fixes: b9c32fb27170 ("packet: if hw/sw ts enabled in rx/tx ring, report which ts we got") Cc: Daniel Borkmann Cc: Willem de Bruijn Signed-off-by: Richard Sanger Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/packet/af_packet.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 449625c2ccc7..ddb68aa836f7 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -421,7 +421,8 @@ static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts, ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts)) return TP_STATUS_TS_RAW_HARDWARE; - if (ktime_to_timespec64_cond(skb->tstamp, ts)) + if ((flags & SOF_TIMESTAMPING_SOFTWARE) && + ktime_to_timespec64_cond(skb->tstamp, ts)) return TP_STATUS_TS_SOFTWARE; return 0; @@ -2339,7 +2340,12 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, skb_copy_bits(skb, 0, h.raw + macoff, snaplen); - if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp))) + /* Always timestamp; prefer an existing software timestamp taken + * closer to the time of capture. + */ + ts_status = tpacket_get_timestamp(skb, &ts, + po->tp_tstamp | SOF_TIMESTAMPING_SOFTWARE); + if (!ts_status) ktime_get_real_ts64(&ts); status |= ts_status; -- 2.30.2