Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp272069lqt; Thu, 18 Apr 2024 14:57:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUm9f3Gj5eqWebbjDToXC6+BsHbA4bbECzj2Iq0vDzUcxBnaJYAmYlnDNV9+yla+3OfszCZ6r7+t5e/ugZErwxiGvbt448oV0MGtc+FYA== X-Google-Smtp-Source: AGHT+IFgMvXyjBw/qiwvxTNRhTbuxcYyCYgoKQKNDSdOYPNAFByRxoiz+gD2b0U0gDlF2mZ8J1gh X-Received: by 2002:a05:6a21:168b:b0:1a3:bd97:4cab with SMTP id np11-20020a056a21168b00b001a3bd974cabmr6022639pzb.6.1713477455320; Thu, 18 Apr 2024 14:57:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713477455; cv=pass; d=google.com; s=arc-20160816; b=bavD9YkkR7bYoUplcaHCokIC9VnX06keJlZHrELfd+izAWWQj8Q/PDevZ6gBnsmvG8 qEfSXHi7ZOfRBCqNmttig/Y8/4NXRYyEiPhkS2Fpxik68obgIixJqK2/RBvdY6C4F7FU QAUyPQNYlYgM9VlCWMlyelRnJ69nGrWdolCP8doETPZYBmJQaFjH6Mmob37gzbCeTKnt mTpf1szPM63LqbXaFZ0l0LfOxWCyNM/L9Uska2QNp87QFVbfpztD0xK2Xj+vPhB7drQG gNhJMzFbiTFluvr3iGoB6xIz8AEAViG6hzOgijR929x3xFd4fX0MajMWSIBkbYG7FHBu IUaA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=biLTizcyKoXID4ZbzhVKkocFif6oiK6wrP0PDSnRgzg=; fh=dWy2TC+kdzjb7ePn/XHS2d3jYZP2x0qcbZbIUQ7kTvU=; b=KXCmxgNrMEYgB+18NmUStIwRLtXw0nrXmxzyNrGiVULQz7sf6XuCgk1FdWxquWA9L8 n70ZskcO7d0p69+sq2g2YUlE4aqs/ruZadpRKVSOq5WxKmu0ogApBpBosF/EAnW/Bz3K 7xRHs9yw1tJYbBL9Ziw80SGliR8nl7QJEVkkRsOvTTzA8woQzr/N2JBVlqFV9MV1btg3 sx47v4R4SYaDLfGyVMQzX8HrrImrcGqsaHRHkeflGYjLVChK5iVCpUpREnhCHsoAtJVt fsKU1AICngXbv1RnS4MVakt98BYmPGdzyXkciyhFCmUE5/9vAUK7LXgcjky4CFZHHVK2 jCWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hdDV1nrZ; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-150818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h32-20020a635760000000b005f77b2c2b71si2197440pgm.333.2024.04.18.14.57.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 14:57:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hdDV1nrZ; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-150818-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150818-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E0F02282F84 for ; Thu, 18 Apr 2024 21:57:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13E8B199EAB; Thu, 18 Apr 2024 21:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hdDV1nrZ" Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 EFD6418131D for ; Thu, 18 Apr 2024 21:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713477444; cv=none; b=BB+BGvvAJeIjC5sB3sY3Xws2Pn/rwn4KhB/X0ELb4m/iLpTagXDvFRfftjq4KIUL74QyQ6K2l5cDQOYiXUsbrdpyoHMayI3IQn7pESSTkROZCdsrSNA086eZYZ+k0OhlMXaJkHfeuzarc72M3E6ILOJraVYMUJExuPb6sxbuUuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713477444; c=relaxed/simple; bh=zooV8U1KdjxrLXansfLdXT2+NI7EJnxfn32RZkboLRk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Ab4dowA2pKXcZUwz2HCqFR6Uodkell68GaUfs3izE+1JUAbnCGf5foPNKNMjbQ/rWYk4iQ9YJg4Y4hb1+BE3xSyivaayMQaJ/qPe1WXc2fbvJmBO4dWPrMhabwb/1Byx0nvwHPUNpKhk425E59Q2DgTAqjgSzHeacFV77m/Xzc8= 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=hdDV1nrZ; arc=none smtp.client-ip=95.215.58.187 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 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1713477439; 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=biLTizcyKoXID4ZbzhVKkocFif6oiK6wrP0PDSnRgzg=; b=hdDV1nrZbThWa8XN/NOAuO1TL/Ie+Qg92kBzCL9omoSluxR1TfCLUx3kwj9uwhbZkQYaly uNfd4ePrxFLgf+WRQfHgp2SaiXqpRKDRAXNl3xVPpKLOw7cA/oobIZEK8kVA4zAI/YhO1e GatKGoshXof6N78AwIH65m7xeSRUk7E= Date: Thu, 18 Apr 2024 14:57:12 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC PATCH bpf-next v4 2/2] net: Add additional bit to support clockid_t timestamp type To: "Abhishek Chauhan (ABC)" , Willem de Bruijn Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Halaney , Martin KaFai Lau , Daniel Borkmann , bpf , kernel@quicinc.com References: <20240418004308.1009262-1-quic_abchauha@quicinc.com> <20240418004308.1009262-3-quic_abchauha@quicinc.com> <66216f3ec638b_f648a294ec@willemb.c.googlers.com.notmuch> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 4/18/24 1:10 PM, Abhishek Chauhan (ABC) wrote: >>> #ifdef CONFIG_NET_XGRESS >>> __u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */ >>> __u8 tc_skip_classify:1; >>> @@ -1096,10 +1100,12 @@ struct sk_buff { >>> */ >>> #ifdef __BIG_ENDIAN_BITFIELD >>> #define SKB_MONO_DELIVERY_TIME_MASK (1 << 7) >>> -#define TC_AT_INGRESS_MASK (1 << 6) >>> +#define SKB_TAI_DELIVERY_TIME_MASK (1 << 6) >> >> SKB_TSTAMP_TYPE_BIT2_MASK? nit. Shorten it to just SKB_TSTAMP_TYPE_MASK? #ifdef __BIG_ENDIAN_BITFIELD #define SKB_TSTAMP_TYPE_MASK (3 << 6) #define SKB_TSTAMP_TYPE_RSH (6) /* more on this later */ #else #define SKB_TSTAMP_TYPE_MASK (3) #endif >> > I was thinking to keep it as TAI because it will confuse developers. I hope thats okay. I think it is not very useful to distinguish each bit since it is an enum value now. It becomes more like the "pkt_type:3" and its PKT_TYPE_MAX. >>> +#define TC_AT_INGRESS_MASK (1 << 5) >>> #else >>> #define SKB_MONO_DELIVERY_TIME_MASK (1 << 0) >>> -#define TC_AT_INGRESS_MASK (1 << 1) >>> +#define SKB_TAI_DELIVERY_TIME_MASK (1 << 1) >>> +#define TC_AT_INGRESS_MASK (1 << 2) >>> #endif >>> #define SKB_BF_MONO_TC_OFFSET offsetof(struct sk_buff, __mono_tc_offset) >>> >>> @@ -4206,6 +4212,11 @@ static inline void skb_set_delivery_time(struct sk_buff *skb, ktime_t kt, >>> case CLOCK_MONOTONIC: >>> skb->tstamp_type = SKB_CLOCK_MONO; >>> break; >>> + case CLOCK_TAI: >>> + skb->tstamp_type = SKB_CLOCK_TAI; >>> + break; >>> + default: >>> + WARN_ONCE(true, "clockid %d not supported", tstamp_type); >> >> and set to 0 and default tstamp_type? >> Actually thinking about it. I feel if its unsupported just fall back to default is the correct thing. I will take care of this. >>> } >>> } >> >>> > >> @@ -9372,10 +9378,16 @@ static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, >>> *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, >>> SKB_BF_MONO_TC_OFFSET); >>> *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, >>> - SKB_MONO_DELIVERY_TIME_MASK, 2); >>> + SKB_MONO_DELIVERY_TIME_MASK | SKB_TAI_DELIVERY_TIME_MASK, 2); >>> + *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, >>> + SKB_MONO_DELIVERY_TIME_MASK, 3); >>> + *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, >>> + SKB_TAI_DELIVERY_TIME_MASK, 4); >>> *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_UNSPEC); >>> *insn++ = BPF_JMP_A(1); >>> *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_DELIVERY_MONO); >>> + *insn++ = BPF_JMP_A(1); >>> + *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_DELIVERY_TAI); With SKB_TSTAMP_TYPE_MASK defined like above, this could be simplified like this (untested): static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, struct bpf_insn *insn) { __u8 value_reg = si->dst_reg; __u8 skb_reg = si->src_reg; BUILD_BUG_ON(__SKB_CLOCK_MAX != BPF_SKB_TSTAMP_DELIVERY_TAI); *insn++ = BPF_LDX_MEM(BPF_B, value_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); *insn++ = BPF_ALU32_IMM(BPF_AND, value_reg, SKB_TSTAMP_TYPE_MASK); #ifdef __BIG_ENDIAN_BITFIELD *insn++ = BPF_ALU32_IMM(BPF_RSH, value_reg, SKB_TSTAMP_TYPE_RSH); #else BUILD_BUG_ON(!(SKB_TSTAMP_TYPE_MASK & 0x1)); #endif return insn; } >>> >>> return insn; >>> } >>> @@ -9418,10 +9430,26 @@ static struct bpf_insn *bpf_convert_tstamp_read(const struct bpf_prog *prog, >>> __u8 tmp_reg = BPF_REG_AX; >>> >>> *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, SKB_BF_MONO_TC_OFFSET); >>> + /*check if all three bits are set*/ >>> *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, >>> - TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK); >>> - *insn++ = BPF_JMP32_IMM(BPF_JNE, tmp_reg, >>> - TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK, 2); >>> + TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK | >>> + SKB_TAI_DELIVERY_TIME_MASK); >>> + /*if all 3 bits are set jump 3 instructions and clear the register */ >>> + *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, >>> + TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK | >>> + SKB_TAI_DELIVERY_TIME_MASK, 4); >>> + /*Now check Mono is set with ingress mask if so clear */ >>> + *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, >>> + TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK, 3); >>> + /*Now Check tai is set with ingress mask if so clear */ >>> + *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, >>> + TC_AT_INGRESS_MASK | SKB_TAI_DELIVERY_TIME_MASK, 2); >>> + /*Now Check tai and mono are set if so clear */ >>> + *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, >>> + SKB_MONO_DELIVERY_TIME_MASK | >>> + SKB_TAI_DELIVERY_TIME_MASK, 1); Same as the bpf_convert_tstamp_type_read, this could be simplified with SKB_TSTAMP_TYPE_MASK. >> >> This looks as if all JEQ result in "if so clear"? >> >> Is the goal to only do something different for the two bits being 0x1, >> can we have a single test with a two-bit mask, rather than four tests? >> > I think Martin wanted to take care of TAI as well. I will wait for his comment here > > My Goal was to take care of invalid combos which does not hold valid > 1. If all 3 bits are set => invalid combo (Test case written is Insane) > 2. If 2 bits are set (tai+mono)(Test case written is Insane) => this cannot happen (because clock base can only be one in skb) > 3. If 2 bit are set (ingress + tai/mono) => This is existing logic + tai being added (clear tstamp in ingress) > 4. For all other cases go ahead and fill in the tstamp in the dest register. If it is to ensure no new type is added without adding BPF_SKB_TSTAMP_DELIVERY_XYZ, I would simplify this runtime bpf insns here and use a BUILD_BUG_ON to catch it at compile time. Something like, enum skb_tstamp_type { SKB_CLOCK_REAL, /* Time base is skb is REALTIME */ SKB_CLOCK_MONO, /* Time base is skb is MONOTONIC */ SKB_CLOCK_TAI, /* Time base in skb is TAI */ __SKB_CLOCK_MAX = SKB_CLOCK_TAI, }; /* Same one used in the bpf_convert_tstamp_type_read() above */ BUILD_BUG_ON(__SKB_CLOCK_MAX != BPF_SKB_TSTAMP_DELIVERY_TAI); Another thing is, the UDP test in test_tc_dtime.c probably needs to be adjusted, the userspace is using the CLOCK_TAI in SO_TXTIME and it is getting forwarded now.