Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp326870pxm; Wed, 2 Mar 2022 16:28:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgwpAo3n9jfgFIk/i/ThFNp3rDjVTTcbSf7tx3YnOw9EuVA4xVOZTBm838r2bYdTagStaK X-Received: by 2002:a05:6a00:13aa:b0:4f1:1e5f:1c39 with SMTP id t42-20020a056a0013aa00b004f11e5f1c39mr35477232pfg.24.1646267301932; Wed, 02 Mar 2022 16:28:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646267301; cv=none; d=google.com; s=arc-20160816; b=hhJC/t0ebekdJ4vE6Ou3+PIOegu53k8BaPQ1t5A+3s05ZhSZsEYyRmr9DHVky493kk lLapZlwJTmzFH+bmI9yjlLjwFTj0nbIzJr4HXIyN1inPZCH7FciKyLYbjNP7hJwa+Sls 9MIuI/cjjkBZaZpGKrMIfLSTQJcHWYH/yqIH9/liPOooUwfrVMkrBoajWoUEVRs3kyEr k6ZnOCSdlngAasW2EPSFVyV9ObodSfb7F8aKmYcFhMKiwpiqDOLVfjM95zJPl5ci4YQo s0cHuAPdot7d51Y4SMN4x15qHZNsT4LvlUFa1g+E6UZcZ6SvHIOzNsU1sE34cZUk6SGB v9wg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=XZ2+vLPKYKi6WwtNhMlhZg5FNddmluP4D/wmhwXgWPs=; b=cIQ8Q3Z3DBmMxIfv12m76zWXXnqpZSycC9ukRvaKboOVbwDa6j0jARuqxajo488sXZ xbTKbF+5EZoDshuOKuoRB6VV4NBCzNt2j7PTkJXiuii5xuCsypcg3WLjLpsKF3Ly6bBo u2r3JbEg/G6pZQW85fjluM46ri1Kwm8GvZvNwhKj2iaUkBOiJ1v6V/F9tUJuXT1voUGi as+BmNq+GtNnsPkUVt9aaPLpJdKs1X+gxjocuPuRga49fW4BatoO55XpmhobfTNpPOWn hkygfRI0RpsPle/SN7M5jsiR3YPOFnpLd/tlq3n6pAIiBBoPQQp/V69exqNYMerGPS3J JPMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CT5/d8lr"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r6-20020a17090a4dc600b001bc11f9ba1asi6549458pjl.66.2022.03.02.16.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:28:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="CT5/d8lr"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C19420B383; Wed, 2 Mar 2022 15:39:10 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236395AbiCBTSU (ORCPT + 99 others); Wed, 2 Mar 2022 14:18:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240728AbiCBTSS (ORCPT ); Wed, 2 Mar 2022 14:18:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034DAA187; Wed, 2 Mar 2022 11:17:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4FB0D61632; Wed, 2 Mar 2022 19:17:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C94DC004E1; Wed, 2 Mar 2022 19:17:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646248653; bh=/Z9NL1R6Uwfmg3+ggDEmUITGmY/PGsenpQnwgnFGBCw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=CT5/d8lrPSRXqPX3lQErLUXiAvTtxI0LrBVyWTYAZJSadHlCNSL9UHC63GXIEfF3+ tn+JRjIlHyvZhm4YxvbKZdayrrlH4OqaO9mdT04sir14vOKJwJaIFvme/ViMx28R78 0LpPIahWyc/GU9aHeE/SyUaGVxsBs4YKHj03oheh1n2SPWneZq4gNqH79j+NaJxbYV TfD83doSTWw0kascuOG3ef/Mhh6TzhBhPKNUQ9Gpj3LZK++pu5C108VY71TaNz+NYU mzHMcrLo+BBQmKFDdA5u1tvaXL9p02Zwz/7nv9sbaGgC1RhHzV31Fw6Q/oF/vY7q4V OnpVqa5bYKBkA== Date: Wed, 2 Mar 2022 11:17:31 -0800 From: Jakub Kicinski To: Dongli Zhang Cc: dsahern@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, rostedt@goodmis.org, mingo@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, imagedong@tencent.com, joao.m.martins@oracle.com, joe.jin@oracle.com, edumazet@google.com Subject: Re: [PATCH net-next v4 4/4] net: tun: track dropped skb via kfree_skb_reason() Message-ID: <20220302111731.00746020@kicinski-fedora-PC1C0HJN.hsd1.ca.comcast.net> In-Reply-To: References: <20220226084929.6417-1-dongli.zhang@oracle.com> <20220226084929.6417-5-dongli.zhang@oracle.com> <20220301185021.7cba195d@kicinski-fedora-PC1C0HJN.hsd1.ca.comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2 Mar 2022 10:19:30 -0800 Dongli Zhang wrote: > On 3/1/22 6:50 PM, Jakub Kicinski wrote: > > On Sat, 26 Feb 2022 00:49:29 -0800 Dongli Zhang wrote: > >> + SKB_DROP_REASON_SKB_PULL, /* failed to pull sk_buff data */ > >> + SKB_DROP_REASON_SKB_TRIM, /* failed to trim sk_buff data */ > > > > IDK if these are not too low level and therefore lacking meaning. > > > > What are your thoughts David? > > > > Would it be better to up level the names a little bit and call SKB_PULL > > something like "HDR_TRUNC" or "HDR_INV" or "HDR_ERR" etc or maybe > > "L2_HDR_ERR" since in this case we seem to be pulling off ETH_HLEN? > > This is for device driver and I think for most of cases the people understanding > source code will be involved. I think SKB_PULL is more meaningful to people > understanding source code. > > The functions to pull data to skb is commonly used with the same pattern, and > not only for ETH_HLEN. E.g., I randomly found below in kernel source code. > > 1071 static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb) > 1072 { > ... ... > 1102 pulled_sci = pskb_may_pull(skb, macsec_extra_len(true)); > 1103 if (!pulled_sci) { > 1104 if (!pskb_may_pull(skb, macsec_extra_len(false))) > 1105 goto drop_direct; > 1106 } > ... ... > 1254 drop_direct: > 1255 kfree_skb(skb); > 1256 *pskb = NULL; > 1257 return RX_HANDLER_CONSUMED; > > > About 'L2_HDR_ERR', I am curious what the user/administrator may do as next > step, while the 'SKB_PULL' will be very clear to the developers which kernel > operation (e.g., to pull some protocol/hdr data to sk_buff data) is with the issue. > > I may use 'L2_HDR_ERR' if you prefer. We don't have to break it out per layer if you prefer. Let's call it HDR_TRUNC. I don't like SKB_PULL, people using these trace points are as likely to be BPF developers as kernel developers and skb_pull will not be meaningful to them. Besides the code can check if header is not truncated in other ways than pskb_may_pull(). And calling things by the name of the helper that failed is bad precedent. > > For SKB_TRIM the error comes from allocation failures, there may be > > a whole bunch of skb helpers which will fail only under mem pressure, > > would it be better to identify them and return some ENOMEM related > > reason, since, most likely, those will be noise to whoever is tracking > > real errors? > > The reasons I want to use SKB_TRIM: > > 1. To have SKB_PULL and SKB_TRIM (perhaps more SKB_XXX in the future in the same > set). > > 2. Although so that SKB_TRIM is always caused by ENOMEM, suppose if there is new > return values by pskb_trim(), the reason is not going to be valid any longer. > > > I may use SKB_DROP_REASON_NOMEM if you prefer. > > Another concern is that many functions may return -ENOMEM. It is more likely > that if there are two "goto drop" to return -ENOMEM, we will not be able to tell > from which function the sk_buff is dropped, e.g., > > if (function_A()) { > reason = -ENOMEM; > goto drop; > } > > if (function_B()) { > reason = -ENOMEM; > goto drop; > } Are you saying that you're intending to break out skb drop reasons by what entity failed to allocate memory? I'd think "skb was dropped because of OOM" is what should be reported. What we were trying to allocate is not very relevant (and can be gotten from the stack trace if needed). > >> SKB_DROP_REASON_DEV_HDR, /* there is something wrong with > >> * device driver specific header > >> */ > >> + SKB_DROP_REASON_DEV_READY, /* device is not ready */ > > > > What is ready? link is not up? peer not connected? can we expand? > > In this patchset, it is for either: > > - tun->tfiles[txq] is not set, or > > - !(tun->dev->flags & IFF_UP) > > I want to make it very generic so that the sk_buff dropped due to any device > level data structure that is not up/ready/initialized/allocated will use this > reason in the future. Let's expand the documentation so someone reading thru the enum can feel confident if they are using this reason correctly. Side note - you may want to switch to inline comments to make writing more verbose documentation, I mean: /* This is the explanation of reason one which explains what * reason ones means, and how it should be used. We can make * use of full line width this way. */ SKB_DROP_REASON_ONE, /* And this is an explanation for reason two. */ SKB_DROP_REASON_TWO,