Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2747610pxj; Mon, 31 May 2021 09:43:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBhUezxcjLeutwAdY4gpkF9HZodx62VCRMZEmmNKoNFyMhO6CTwDpbsn28wKKdOxQKYmJS X-Received: by 2002:a17:906:76c6:: with SMTP id q6mr23866637ejn.387.1622479417330; Mon, 31 May 2021 09:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479417; cv=none; d=google.com; s=arc-20160816; b=n/Qk+Qh9oSXKdsST+3PeBsqIUYyaJSQaoGkHWoZB3irob4pn3k91j+9rQgT5h6/spN h1QAB18c5Lf/70wjKdz2Gg+xuj5VvPacWfbV/Y3+W1wXw7MkV8HBaM3JRuiH5Ifs5Hr9 KT354dVSpdGYnOnJwqOt7ZzJSYUyU7CmcP9zN6BnG21XkscoQ72K++hMsZOJl716YG88 YrpGMENYNyy646JdActRnhvHxIRH0ZqbK+NNjVxwvq+rZLF9dcdY77YnNFlhp0CzKm+t ZQB4KyeqPgT74lLsEqQ4LgJz7RgSqkpebM/3hspvH5v8HW2BY1KS1GjIzl0+LE1glFUE dSMw== 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=SyMCko71XTxNvL/hQ7PieA/YHwRemQ4y7XCyICj850A=; b=eGDN7QSeZvwi8adxlW7hCs4IfpG9z7OIY/evuCrcJNYJQeSD0Hrxhw8b25jKRcN8pM glUM72om1VKxhfHDgf+w6V2yVMZEPAA/5S/d1DSn0Ge1JFRJrnRoWZTLlwmkEZDci0PP JttHZ5XaGPurspTPDFgrbiznekSsTIUHl7DzfA0abR5Y+7kILU/SO0WpUyReOsWdyn/q O6ibGryk5Pu3H+g1LEAvJSA4qTIMJwsIxJfDoCK5lxmZt1w8R/UKEG7rfL0pFhGjACHs daqQiD2KlRGTiDR8A0Y2KhbQHxWL9D/RkMoW9tzsJ+j9/+7aVw5TseDjJ3sMDmoDKMWN FTKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mdontsgZ; 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 b11si12911840edz.116.2021.05.31.09.43.14; Mon, 31 May 2021 09:43:37 -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=mdontsgZ; 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 S234010AbhEaQmm (ORCPT + 99 others); Mon, 31 May 2021 12:42:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:47898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234060AbhEaOxS (ORCPT ); Mon, 31 May 2021 10:53:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C83D613F5; Mon, 31 May 2021 13:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469529; bh=Q6mA6D0soW/kCeWiI5cvmV+dDk1a114klHTObJLnEXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mdontsgZPH6QX/gfeZfEABrWK9I6XMA12YsJf6Qvy1cv97WU1n9eeKZHQ7N0u/R5E fofEYv9Gk2wPhO7lMjBU085ZbrutK3cFvPJu2G6669vL2Vqd1ccD8uTvU+0oxPREM1 8Zeap6/lVmS3W4RLhlf9KjZYFXEj2uuyGtJrNPNk= 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.12 232/296] net: packetmmap: fix only tx timestamp on request Date: Mon, 31 May 2021 15:14:47 +0200 Message-Id: <20210531130711.608742062@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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 9611e41c7b8b..c52557ec7fb3 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -422,7 +422,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; @@ -2340,7 +2341,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