Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp390525lqb; Tue, 4 Jun 2024 14:48:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgz0/WDO9tBCprx6D1RCcxoo74qZyAXkRgtK9xv+5UiwHO4wZSkkFhN0+qqFaoYdgtbKgY8A1MJfQQF3vRBbrqXmJMvPDS3BpfA/Lw+g== X-Google-Smtp-Source: AGHT+IEioWJiIVIovENueUVLIQe4jlTa/9wH5DAW+oid1Pl9nB1ZOEWjKL/P+whiUVDj/UTjQn3r X-Received: by 2002:ac2:4c15:0:b0:524:34ad:ba77 with SMTP id 2adb3069b0e04-52bab4b7f9fmr406031e87.12.1717537706209; Tue, 04 Jun 2024 14:48:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717537706; cv=pass; d=google.com; s=arc-20160816; b=yJo/8a/x/jNiPl9gr5NZj6NYKuzDMj4fgnLGkvgLOqR3UBMgm+TiofwOsUYMqnm8YI WbYeBJLfWU7LrLdxFKM5KfUCUqZQykznaB9fU2yuM7fLDk5XHOGdlTNvEYItKHQPcDNj 11GVN4hHhPL6PR2cq3dpm78xZZcUv99yVaUUy+bpB8BjYct1ROLCvtz5tQFmpqoXuHe/ 8IEMCr66+H+p7biTs2yUtlLF2gizom+RIgrHZ0dlNzm3kVsxfdG6/Yrb/JTo7OV/3+67 3f8hkzjeTID7qrEsNMqCCvuQzuzGra68tparxNtbJ2Dupm2GTeJnfIJEVG58z48V858m uXpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8Z9GdxrPO2MLCd8f731wHDlufWSwkyCPNseSHb6h3wQ=; fh=a+Vv8cZ3usD+al5/xCYlIoIkO6I011SMYVbSAiVmpIE=; b=ZJzNdS0egQmq/Z9kgX5iGSKZcjMfm/c+5E4TyvRf+BGRCgFI91a1ggtHDuioTblksB +sGSYrGp5kYYzcPcloQQ6GJo7jcMlv95BYvhO9OFZADDAd0TQagxBata9rrPTt+7GqUp +RsI9pAkaExu7GTeetyNrceF2eZy6SjOQQXrkzVUAW1AGusLeTTbcaZ8zgFCQL2XuQxX LcmC043MaKTSv5Bg1j/BBMwtEnfDzxu3MwEbWXxfymJrO5kB/y+Z/Vww7nOs6CQwrOYA r5+wCaXXpi3vveUPfMdAX4gMw8aNwOpQgYHs4+x6zC+FBoLDvGyrHt1uGiAkLTlG8sPe ZnlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=VBZv5Nkc; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-201421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31b817d3si5542329a12.92.2024.06.04.14.48.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 14:48:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=VBZv5Nkc; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-201421-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201421-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B87BB1F21235 for ; Tue, 4 Jun 2024 21:48:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49EB914D458; Tue, 4 Jun 2024 21:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="VBZv5Nkc" Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54E3314B95B for ; Tue, 4 Jun 2024 21:47:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717537668; cv=none; b=Smc0mp9hTsYeuEG2GOpZwSE+iMjrau5WT2br8ZAEM7uGAiqnt4UwsDe+y58BDcvGGf4Q4wbzFld5VUo3/0clK6FBu5fE0CnfxCe0E8U+pwfc6afdQpqUCOluOpfU6Ouof9JMlUhoXJ1U9R2L36Ru0hA5qqCn8cN457FL0YJlG3U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717537668; c=relaxed/simple; bh=Gs30pldD4IYhwgM9Z2RPF0lE51iD4CooDjoR4sEXvh0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LG95W6m+Cifv1ZWEVHIBKXTLMZkRTe7dbCMM7zTsDIKrx0fC1XdssPza5PcRvP3Zln9QxNXOAGBNnVRQjoWDRyz/d02QDlycth+UKrzdemgUwyQJ/rS26ERRAxhV7H4CJ07Hh0pFlAtK09mqmG6M6McIwxuQt3NCzQLdj9F+JTQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=VBZv5Nkc; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6aedd5167d1so25091366d6.1 for ; Tue, 04 Jun 2024 14:47:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717537665; x=1718142465; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8Z9GdxrPO2MLCd8f731wHDlufWSwkyCPNseSHb6h3wQ=; b=VBZv5Nkc+jzD+6LJXbyKqEoUTOBdAphLvrGEU0Q+0jjmv6XL+72aBZXLQqLFY44gOO xN3A8JWRCvUsNptse5/1dipNTF7OO9ZV3h3iTHcz4hT8meHbNKRZRMrl0gbLsSppz58p HFThAJnGdamc+TkJaGBd0AZKicvuB1lo2M5keqrI+xrEiSnyE8qBN+uQkPxVK8M5FFbc N6LQAjFGZhlE0wo72YR6UX3PZnwHWYkh/93fIQhQbRT750VR7LTV41V/ZIWg1v6pKLN/ cE+i7fOTn64mgM466o4QJSGjvBvmEAZbCPxqEKYNr1t3YUOQAzH8ifuu64yFFBWiA8tU vsLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717537665; x=1718142465; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8Z9GdxrPO2MLCd8f731wHDlufWSwkyCPNseSHb6h3wQ=; b=Ua8qo794qdvXnrkFfT4elgGtj/VPNW3F7/iJyCMOB1Sse70JSviimFjCTC6VonK67U junPlhQP9tRVjRC3evsJACTR7QicKNZE2/ZXI9m93U8uGiRdfIJw8RKEVuJJgakjANcy WBfHdzczrla+Nywq8DEb8kDWL3b8E6Wu0xnYoFcaTq+oKKIDpGsWgkYPrJWYlxXQjKiB +F2sKV3+zv371t05U9b1Duz7AlNribPBhnjcU2UPvmNnSuuBa1WDc0j+jSsdaX4c2kmU lku+lq7WlUVehtlCWCmFDmOF/JlRWTe28PFQkyGLyMpUcM4pyPm2xJ0zjE3dWsYlkZC9 PlzQ== X-Forwarded-Encrypted: i=1; AJvYcCW4w0DRxianeDeP1slPVQJZbitbZBcLzZrM0PusKa3NfwP+V6Gy4H2qV9gsSbBo97xSk23dIcE2xgJ+jyp3J3Oc1VMdXmscsLpjiGU1 X-Gm-Message-State: AOJu0YwcdZgaA6LceRp5iBevqpHpaMLGEEJ5mGuTPIOKbrvY3wntwh5z 9oez4Li0dFngZUIXlglz+JvZbMY5iNguo5xFHXWFEilPWqeOPq3mgAxQTPGmXpU= X-Received: by 2002:a05:6214:4347:b0:6af:4a1f:de64 with SMTP id 6a1803df08f44-6b030a59138mr6247126d6.44.1717537665179; Tue, 04 Jun 2024 14:47:45 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4b417b0bsm42203196d6.108.2024.06.04.14.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 14:47:44 -0700 (PDT) Date: Tue, 4 Jun 2024 14:47:41 -0700 From: Yan Zhai To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , David Ahern , Abhishek Chauhan , Mina Almasry , Florian Westphal , Alexander Lobakin , David Howells , Jiri Pirko , Daniel Borkmann , Sebastian Andrzej Siewior , Lorenzo Bianconi , Pavel Begunkov , linux-kernel@vger.kernel.org, kernel-team@cloudflare.com, Jesper Dangaard Brouer , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Neil Horman , linux-trace-kernel@vger.kernel.org, Dan Carpenter Subject: [RFC v3 net-next 2/7] net: introduce sk_skb_reason_drop function Message-ID: <1fec17924ebc0499b1f62b2af5bda216e4de00b4.1717529533.git.yan@cloudflare.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Long used destructors kfree_skb and kfree_skb_reason do not pass receiving socket to packet drop tracepoints trace_kfree_skb. This makes it hard to track packet drops of a certain netns (container) or a socket (user application). The naming of these destructors are also not consistent with most sk/skb operating functions, i.e. functions named "sk_xxx" or "skb_xxx". Introduce a new functions sk_skb_reason_drop as drop-in replacement for kfree_skb_reason on local receiving path. Callers can now pass receiving sockets to the tracepoints. kfree_skb and kfree_skb_reason are still usable but they are now just inline helpers that call sk_skb_reason_drop. Note it is not feasible to do the same to consume_skb. Packets not dropped can flow through multiple receive handlers, and have multiple receiving sockets. Leave it untouched for now. Suggested-by: Eric Dumazet Signed-off-by: Yan Zhai --- v1->v2: changes function names to be more consistent with common sk/skb operations --- include/linux/skbuff.h | 10 ++++++++-- net/core/skbuff.c | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index fe7d8dbef77e..c479a2515a62 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1251,8 +1251,14 @@ static inline bool skb_data_unref(const struct sk_buff *skb, return true; } -void __fix_address -kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason); +void __fix_address sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason reason); + +static inline void +kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +{ + sk_skb_reason_drop(NULL, skb, reason); +} /** * kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 2854afdd713f..9def11fe42c4 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1190,7 +1190,8 @@ void __kfree_skb(struct sk_buff *skb) EXPORT_SYMBOL(__kfree_skb); static __always_inline -bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +bool __sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb, + enum skb_drop_reason reason) { if (unlikely(!skb_unref(skb))) return false; @@ -1203,26 +1204,27 @@ bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) if (reason == SKB_CONSUMED) trace_consume_skb(skb, __builtin_return_address(0)); else - trace_kfree_skb(skb, __builtin_return_address(0), reason, NULL); + trace_kfree_skb(skb, __builtin_return_address(0), reason, sk); return true; } /** - * kfree_skb_reason - free an sk_buff with special reason + * sk_skb_reason_drop - free an sk_buff with special reason + * @sk: the socket to receive @skb, or NULL if not applicable * @skb: buffer to free * @reason: reason why this skb is dropped * - * Drop a reference to the buffer and free it if the usage count has - * hit zero. Meanwhile, pass the drop reason to 'kfree_skb' - * tracepoint. + * Drop a reference to the buffer and free it if the usage count has hit + * zero. Meanwhile, pass the receiving socket and drop reason to + * 'kfree_skb' tracepoint. */ void __fix_address -kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb, enum skb_drop_reason reason) { - if (__kfree_skb_reason(skb, reason)) + if (__sk_skb_reason_drop(sk, skb, reason)) __kfree_skb(skb); } -EXPORT_SYMBOL(kfree_skb_reason); +EXPORT_SYMBOL(sk_skb_reason_drop); #define KFREE_SKB_BULK_SIZE 16 @@ -1261,7 +1263,7 @@ kfree_skb_list_reason(struct sk_buff *segs, enum skb_drop_reason reason) while (segs) { struct sk_buff *next = segs->next; - if (__kfree_skb_reason(segs, reason)) { + if (__sk_skb_reason_drop(NULL, segs, reason)) { skb_poison_list(segs); kfree_skb_add_bulk(segs, &sa, reason); } -- 2.30.2