From patchwork Thu May 30 21:46:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680867 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 B85B6183977 for ; Thu, 30 May 2024 21:47:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105622; cv=none; b=OFaHixG0xzoMxr3/BCAMwbms/57LT2tXbN0N6hqorJH+8NWnIgowY496vyYvZuuLtrRAzjABVolbcs7L1yrAFyRVxrAfbt3cazYuLX4J4ySf59PeD8DlnCEdK2PapXUge+R9asOVZMcArzouNWIbNBJNaCcY8/VcXjVSH4LyQGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105622; c=relaxed/simple; bh=W2h/LnRyHWTHgTveKmP08DBvMQDEDLRwZs6glWTSns0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K0G1ymINXi+lhWXbMDduznRoiW9SGi4tmb0T2Cy4vpInqo99AqYhTDHneTnDRlNp8Qq6q0gyM9AJkD+EdV0QrE1bxtXiwKEspGDeGXhMsxkhzQfjCpwFv7+a8q9qh228TNkjrFkxJ/2UpKAE49+MutOOekga6gjVG5T8g2oq0mA= 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=JGNDl/Iz; arc=none smtp.client-ip=209.85.167.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="JGNDl/Iz" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3d1bc6e5f01so773214b6e.0 for ; Thu, 30 May 2024 14:47:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105619; x=1717710419; 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=iU0kmb1Q8d2eQhrqkYXLZ8UzXfCX7B5qnp9jHajfNfU=; b=JGNDl/IzYCqu2Mrrfd9qRTedLOgFLIvopB1c16Vy89CmFUNhrMWZxKhpF5EQ7SHdid Wp8VUs5BE5Acep/CtY+740C74H+yvWvZHaWEypm2JTOFIz0pYAeWr8xvc+n5k8+rE8xP FvQQ2qi1766/uy3wlobRWq9ehBzwaB2C/ogKkgUbwmdwzEXeruDN5ge/6HXU5cZFutK3 BsfntBDRMIerX+t4fJiEMa0k15GVUxBwBsKNBTCZcRck9n8fIprf2LaW61iSVGiTn2uq EBjriRF14HAKNESp1x4AjUKEWDJNpcmhMPcka8uHX/2eUsmA+OvEo3N/7F1FW1KQhXy7 KL/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105619; x=1717710419; 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=iU0kmb1Q8d2eQhrqkYXLZ8UzXfCX7B5qnp9jHajfNfU=; b=CIqL6qQX7900eLNHOtZ68TXH2KGS7mJIrwZvJdDhWRRCgvVjo8CPcowqRD8CzwPS1T ryMMiLeIq1IaviaP49smg5nHlxAJ0YPxm182J3utPXTLQ1EwL0/W8QNGIkNesVXMFYQ2 7RwhFZ0Nyz+9KuXeRPSoerqV2HT5XFDaVwRYgVXtufvGvTBi+CJ7OZuMvGxKaxs0NJ6g xXrpPCsKndKFlUhq5L8ruy1V31jD+DDDQsAUXrJwVESSvkqLZW2iQWx8t0ZaFRZmZtYb 75pq3dnV2/D6S7N0Yjmgp+9QQQ0/GjCFyCHytCmizY117MZ+cMOCyfLP10CmyI8TGi1W plJQ== X-Gm-Message-State: AOJu0YwECQjrLjQ8repuVh+LbAEf1p4SRzjViDAEp7VxxbL6jEImCX+K 3v37SVS2+rnKpvfUkjNFYRglMOQWsOq6xx5cwqV4zBiJn55xcevR0aHXd+ACCXoIUhClofJem/t PAXw= X-Google-Smtp-Source: AGHT+IHgbXLNJseQlQk0+KenNC/IVwEM1DAl54VBPXVciNudX/cszFcDimmnbghb5SinYarxHkVXFQ== X-Received: by 2002:aca:1119:0:b0:3c9:966e:32ea with SMTP id 5614622812f47-3d1e34786demr29137b6e.2.1717105618801; Thu, 30 May 2024 14:46:58 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4a73e4absm1963286d6.6.2024.05.30.14.46.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:46:58 -0700 (PDT) Date: Thu, 30 May 2024 14:46:56 -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 Subject: [RFC net-next 1/6] net: add kfree_skb_for_sk function Message-ID: <9be3733eee16bb81a7e8e2e57ebcc008f95cae08.1717105215.git.yan@cloudflare.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Implement a new kfree_skb_for_sk to replace kfree_skb_reason on a few local receive path. The function accepts an extra receiving socket argument, which will be set in skb->cb for kfree_skb/consume_skb tracepoint consumption. With this extra bit of information, it will be easier to attribute dropped packets to netns/containers and sockets/services for performance and error monitoring purpose. Signed-off-by: Yan Zhai --- include/linux/skbuff.h | 48 ++++++++++++++++++++++++++++++++++++++++-- net/core/dev.c | 21 +++++++----------- net/core/skbuff.c | 29 +++++++++++++------------ 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index fe7d8dbef77e..66f5b06798f2 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1251,8 +1251,52 @@ 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); +/* + * Some protocol will clear or reuse skb->dev field for other purposes. For + * example, TCP stack would reuse the pointer for out of order packet handling. + * This caused some problem for drop monitoring on kfree_skb tracepoint, since + * no other fields of an skb provides netns information. In addition, it is + * also complicated to recover receive socket information for dropped packets, + * because the socket lookup can be an sk-lookup BPF program. + * + * This can be addressed by just passing the rx socket to the tracepoint, + * because it also has valid netns binding. + */ +struct kfree_skb_cb { + enum skb_drop_reason reason; /* used only by dev_kfree_skb_irq */ + struct sock *rx_sk; +}; + +#define KFREE_SKB_CB(skb) ((struct kfree_skb_cb *)(skb)->cb) + +/* Save cb->rx_sk before calling kfree_skb/consume_skb tracepoint, and restore + * after the tracepoint. This is necessary because some skb destructor might + * rely on values in skb->cb, e.g. unix_destruct_scm. + */ +#define _call_trace_kfree_skb(action, skb, sk, ...) do { \ + if (trace_##action##_skb_enabled()) { \ + struct kfree_skb_cb saved; \ + saved.rx_sk = KFREE_SKB_CB(skb)->rx_sk; \ + KFREE_SKB_CB(skb)->rx_sk = sk; \ + trace_##action##_skb((skb), ## __VA_ARGS__); \ + KFREE_SKB_CB(skb)->rx_sk = saved.rx_sk; \ + } \ +} while (0) + +#define call_trace_kfree_skb(skb, sk, ...) \ + _call_trace_kfree_skb(kfree, skb, sk, ## __VA_ARGS__) + +#define call_trace_consume_skb(skb, sk, ...) \ + _call_trace_kfree_skb(consume, skb, sk, ## __VA_ARGS__) + +void __fix_address kfree_skb_for_sk(struct sk_buff *skb, struct sock *rx_sk, + enum skb_drop_reason reason); + +static inline void +kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +{ + kfree_skb_for_sk(skb, NULL, reason); +} /** * kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason diff --git a/net/core/dev.c b/net/core/dev.c index 85fe8138f3e4..17516f26be92 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3135,15 +3135,6 @@ void __netif_schedule(struct Qdisc *q) } EXPORT_SYMBOL(__netif_schedule); -struct dev_kfree_skb_cb { - enum skb_drop_reason reason; -}; - -static struct dev_kfree_skb_cb *get_kfree_skb_cb(const struct sk_buff *skb) -{ - return (struct dev_kfree_skb_cb *)skb->cb; -} - void netif_schedule_queue(struct netdev_queue *txq) { rcu_read_lock(); @@ -3182,7 +3173,11 @@ void dev_kfree_skb_irq_reason(struct sk_buff *skb, enum skb_drop_reason reason) } else if (likely(!refcount_dec_and_test(&skb->users))) { return; } - get_kfree_skb_cb(skb)->reason = reason; + + /* There is no need to save the old cb since we are the only user. */ + KFREE_SKB_CB(skb)->reason = reason; + KFREE_SKB_CB(skb)->rx_sk = NULL; + local_irq_save(flags); skb->next = __this_cpu_read(softnet_data.completion_queue); __this_cpu_write(softnet_data.completion_queue, skb); @@ -5229,17 +5224,17 @@ static __latent_entropy void net_tx_action(struct softirq_action *h) clist = clist->next; WARN_ON(refcount_read(&skb->users)); - if (likely(get_kfree_skb_cb(skb)->reason == SKB_CONSUMED)) + if (likely(KFREE_SKB_CB(skb)->reason == SKB_CONSUMED)) trace_consume_skb(skb, net_tx_action); else trace_kfree_skb(skb, net_tx_action, - get_kfree_skb_cb(skb)->reason); + KFREE_SKB_CB(skb)->reason); if (skb->fclone != SKB_FCLONE_UNAVAILABLE) __kfree_skb(skb); else __napi_kfree_skb(skb, - get_kfree_skb_cb(skb)->reason); + KFREE_SKB_CB(skb)->reason); } } diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 466999a7515e..5ce6996512a1 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 __kfree_skb_reason(struct sk_buff *skb, struct sock *rx_sk, + enum skb_drop_reason reason) { if (unlikely(!skb_unref(skb))) return false; @@ -1201,28 +1202,30 @@ bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) SKB_DROP_REASON_SUBSYS_NUM); if (reason == SKB_CONSUMED) - trace_consume_skb(skb, __builtin_return_address(0)); + call_trace_consume_skb(skb, rx_sk, __builtin_return_address(0)); else - trace_kfree_skb(skb, __builtin_return_address(0), reason); + call_trace_kfree_skb(skb, rx_sk, __builtin_return_address(0), reason); + return true; } /** - * kfree_skb_reason - free an sk_buff with special reason + * kfree_skb_for_sk - free an sk_buff with special reason and receiving socket * @skb: buffer to free + * @rx_sk: the socket to receive the buffer, or NULL if not applicable * @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' + * hit zero. Meanwhile, pass the drop reason and rx socket to 'kfree_skb' * tracepoint. */ -void __fix_address -kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) +void __fix_address kfree_skb_for_sk(struct sk_buff *skb, struct sock *rx_sk, + enum skb_drop_reason reason) { - if (__kfree_skb_reason(skb, reason)) + if (__kfree_skb_reason(skb, rx_sk, reason)) __kfree_skb(skb); } -EXPORT_SYMBOL(kfree_skb_reason); +EXPORT_SYMBOL(kfree_skb_for_sk); #define KFREE_SKB_BULK_SIZE 16 @@ -1261,7 +1264,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 (__kfree_skb_reason(segs, NULL, reason)) { skb_poison_list(segs); kfree_skb_add_bulk(segs, &sa, reason); } @@ -1405,7 +1408,7 @@ void consume_skb(struct sk_buff *skb) if (!skb_unref(skb)) return; - trace_consume_skb(skb, __builtin_return_address(0)); + call_trace_consume_skb(skb, NULL, __builtin_return_address(0)); __kfree_skb(skb); } EXPORT_SYMBOL(consume_skb); @@ -1420,7 +1423,7 @@ EXPORT_SYMBOL(consume_skb); */ void __consume_stateless_skb(struct sk_buff *skb) { - trace_consume_skb(skb, __builtin_return_address(0)); + call_trace_consume_skb(skb, NULL, __builtin_return_address(0)); skb_release_data(skb, SKB_CONSUMED); kfree_skbmem(skb); } @@ -1478,7 +1481,7 @@ void napi_consume_skb(struct sk_buff *skb, int budget) return; /* if reaching here SKB is ready to free */ - trace_consume_skb(skb, __builtin_return_address(0)); + call_trace_consume_skb(skb, NULL, __builtin_return_address(0)); /* if SKB is a clone, don't handle this case */ if (skb->fclone != SKB_FCLONE_UNAVAILABLE) { From patchwork Thu May 30 21:46:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680868 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (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 611DA186286 for ; Thu, 30 May 2024 21:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105624; cv=none; b=Gz4L/qa7geX4cJO9NopWfrmI0kzDQRnnnctbsVkvIDZRbHGr4JYtqRu0Oz0ppRZE7pWcfv+npzjRYbmI7L09b4WZvknxq93OUkOQ1nKJ/lrtxw/XhPVM3DZESkBjHjcsvN245NEpzFIFdL1APsa+YE6Krum+isn5QhPAgh3QnRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105624; c=relaxed/simple; bh=SUfnamc/6k/sjO/J1uJ3QJC2mTjrFfkQhfB+xutr5gk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NHUJbOt6apcJdHO9Dk0moK02GgKeiE4+eaeWQSLJm/M/OFjlBO/Vca160rAo61oUzQpJvWr0CP4xEdaOK6KGRSO7ynnu7Eb1Jj7D5ZR5YjiA1lvL90ZU8VHEkbciqtG63x2NzqvcDlz4S3F/5xv0jqcn0sMJX7b8Pp4Bl7BGwV8= 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=fe0U3Gwo; arc=none smtp.client-ip=209.85.219.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="fe0U3Gwo" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-6ada6a476c2so6773636d6.2 for ; Thu, 30 May 2024 14:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105621; x=1717710421; 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=MK2P6q1XiYjTWQIaOe4RIEfd3S5ujqhwLQADP0nXD8w=; b=fe0U3GwolInkcTr2/bNiARHo8zrLPyQktZfVQ4oJTP6EHWyxXfkXBW/xczlF2QM4db sqRI1kQgwXoXTcdckgZH3lY0sCtAIp9JDviuZXNt1S8pyBdPQNWaVwr0pGTW8njm4Q+K pBQWLhnIVA0eo4PDk6MruCFTfJnTXNmd3qWdhjNyRcuwWjBvscdrQY/ka9mV09DvJRQl SZrLNnYHMDeBNp8iawal4n/3dGPjNonPwAQSA8NQptd01WJpn7jzIBt7XouKL8Xmzs5L jTOOx7JIDT0xZX7Kt7/F2JBhwY2we58r98Fchhq3z+vmnxzC9BIOv0kawdf9vISswtHB /5FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105621; x=1717710421; 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=MK2P6q1XiYjTWQIaOe4RIEfd3S5ujqhwLQADP0nXD8w=; b=WMvuUh1qRj0BRjSCBN5zxEx1GzrNIBCYVG0iGM6SOxYUbLLmQvKXyVUg4QG5NTb+tJ GQ6xjjzlZhp4bFf/gQAMzwXeFDVIZqWuSFEAxqwZs49BsHtDjj64JNr0JYP8/FJWtDmc zn1h4iAMWxSjUW6FJWDMA5iO0JHHu26UwK9TbByU2NaeB0kBwNe0mJDdmH91bMFvlmuO vA+Epeo0VC4vJnRNnV+scymh1dHAQX5RlopGMbtkrALwNjZ57YjYYeUAU5/t4EEG0tB5 wmeVuRSGKDfhYLz+CAWX70hlwqEBWsv3wwIXauzqASx70gjd8y4/9xhkTt5nEX46sCJ/ jz5g== X-Gm-Message-State: AOJu0YzYW/CUbMhJio6rmlpA4O006JFeYn+/cE6Ols5PYI8aXAyOXzEr cAXgJ9+rl/Q7nw/dUHvHbhnEXuVVBiN59asYi+wrUPpLs8sf0Ld4Wxg//usjk4jTtiOa1z87xlo 3F/c= X-Google-Smtp-Source: AGHT+IEm8CT3YJuc+qq9i8YbFNAZnmfEhM4lFa1VZEFA2/RthzAoH5D/o+zx+iB7B1JdGyD6bB3+PQ== X-Received: by 2002:a05:6214:5d11:b0:6ad:6209:ca76 with SMTP id 6a1803df08f44-6aecd56ee4bmr1597006d6.3.1717105621480; Thu, 30 May 2024 14:47:01 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4b406622sm1887586d6.78.2024.05.30.14.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:47:00 -0700 (PDT) Date: Thu, 30 May 2024 14:46:59 -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 Subject: [RFC net-next 2/6] ping: pass rx socket on rcv drops Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use kfree_skb_for_sk call to pass on the rx socket Signed-off-by: Yan Zhai --- net/ipv4/ping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 823306487a82..e2f9866f67c7 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -946,7 +946,7 @@ static enum skb_drop_reason __ping_queue_rcv_skb(struct sock *sk, pr_debug("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n", inet_sk(sk), inet_sk(sk)->inet_num, skb); if (sock_queue_rcv_skb_reason(sk, skb, &reason) < 0) { - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); pr_debug("ping_queue_rcv_skb -> failed\n"); return reason; } From patchwork Thu May 30 21:47:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680869 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 4C6B3182D3C for ; Thu, 30 May 2024 21:47:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105627; cv=none; b=BYSLdMzBFXYzUHpuaHJQxpIR/WslTcu4PKbLxe763lXd4SF1KXynlsIHz4mHOR5pwURmIr0K3+OFd623svD/cP2hJ5GIQj9JLWOumO+9FrlTpAmGnJ7GjP7ZL1ML8HscFyPlsK+qJVqEAC/GQ0+KkAGF3Cyjb9iZ/42zlsiWnjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105627; c=relaxed/simple; bh=y3+eQROhctQnk3LEiLSPrdQt64pO69knN7si0Z3L3mU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WfXL0QetNSmXy1oYuLPUXifMwrb3gS/sS7nBcXyZKRrSc/uzJt/u/aQ8ZIR/6EdkXDDxa6KNLizTGHO+/o/rKXRIaBmXPpzMCVqdVHVpUu0MBs5VnapF1Ljcv8tsJnHNsdyMiKe5Qghj3BuCS2BSZhWq4e9yZYxXMh7tzjvCgNI= 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=JvyjSpIa; arc=none smtp.client-ip=209.85.222.179 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="JvyjSpIa" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-794cbdca425so100346285a.0 for ; Thu, 30 May 2024 14:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105624; x=1717710424; 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=SRNW+MUSsgkJBT+7REaMI9265axxAr+6yEAep7NXTwE=; b=JvyjSpIa/ikelX5qwDU8A4rGizYHJh5lFSz/5IHIjsTF7ozc1Uadns0qlV6s2G3KSv CY2BLKQVGquwKRuUwdgOAtPWk7DvOl82WLwOB/f65Q9dWgwLnf8MrqhD5QJWaqXrEkcu IgnRSroauLWV8KuEBTYEbkrSqdff9F5chJCe0PlR5haCJaDJntNbo5Jso4HHLvpFCmKT yg+KjpGPE8/SgeTKW+PZsgZ5oaydi1+PZglWmKpFC/N1/L+Ly0C1nCJC1gGiOYCwADaD MCPG/f2wmDYcz2mfiKnQNA1t8N+9YE1VkYpQ/9I+WFZyW2cV9naCiKhRUpefLZ4bQPhJ ml8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105624; x=1717710424; 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=SRNW+MUSsgkJBT+7REaMI9265axxAr+6yEAep7NXTwE=; b=tamnIkaxJr0upUpxV/PcHKb3hM6ShpW/5NMk7iK/QBiZ5ZWg2ptgZ6eap2yQFHkVZ7 AwHDxeEBx00IEHQPm4BVWzJu1uJKqgIzPplxOqRRQREI6YpIOZxWTOgf2zWmBisaa7bn qxyufK4jz+LHUVN7BQsaybPi9Q72kgxFl3YIETQ/GD0KNBZdsVohF4vSJmAjf321ThwA i/gZsieKYjuQ+jp6TaVZ9sJrCnJYgU15ljVOLHpfwkGKP/H9IxSAhzypqOy+IzOwZLtJ mYoL4yAxcxdGaJCDTPqjTLhscjcUrVQJOWz39npht+ZYYD69Hm1FpqNCi54Vj7HHNQTc Hs3A== X-Gm-Message-State: AOJu0YzsSaiJmPYgOJK+Xd2K2zdmw47mFlOTAwlvy+rsz2QhsNr26/KO WWUFdijvPeoWV2pV8wFhxtmwQBa+ztcaXm1u6bSnmaEnGpG+Rs5zIau2FwuAIcQXYTuRg11VOCO fiOM= X-Google-Smtp-Source: AGHT+IEzs95+FCSCrSeu5I6ebwijeLwG58rCifGbKQk6mzGpuAgio+YB1VxEby878mMBqMulFOPD7w== X-Received: by 2002:a05:620a:6126:b0:792:bfb8:848b with SMTP id af79cd13be357-794e9daaaf8mr406252585a.27.1717105624315; Thu, 30 May 2024 14:47:04 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794f306332bsm14237385a.76.2024.05.30.14.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:47:03 -0700 (PDT) Date: Thu, 30 May 2024 14:47:01 -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 Subject: [RFC net-next 3/6] net: raw: pass rx socket on rcv drops Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use kfree_skb_for_sk call to pass on the rx socket Signed-off-by: Yan Zhai --- net/ipv4/raw.c | 4 ++-- net/ipv6/raw.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 1a0953650356..429498420eb3 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -301,7 +301,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb) ipv4_pktinfo_prepare(sk, skb, true); if (sock_queue_rcv_skb_reason(sk, skb, &reason) < 0) { - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return NET_RX_DROP; } @@ -312,7 +312,7 @@ int raw_rcv(struct sock *sk, struct sk_buff *skb) { if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) { atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, SKB_DROP_REASON_XFRM_POLICY); + kfree_skb_for_sk(skb, sk, SKB_DROP_REASON_XFRM_POLICY); return NET_RX_DROP; } nf_reset_ct(skb); diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index f838366e8256..c927075f013f 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -362,14 +362,14 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb) if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) && skb_checksum_complete(skb)) { atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, SKB_DROP_REASON_SKB_CSUM); + kfree_skb_for_sk(skb, sk, SKB_DROP_REASON_SKB_CSUM); return NET_RX_DROP; } /* Charge it to the socket. */ skb_dst_drop(skb); if (sock_queue_rcv_skb_reason(sk, skb, &reason) < 0) { - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return NET_RX_DROP; } @@ -390,7 +390,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb) if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) { atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, SKB_DROP_REASON_XFRM_POLICY); + kfree_skb_for_sk(skb, sk, SKB_DROP_REASON_XFRM_POLICY); return NET_RX_DROP; } nf_reset_ct(skb); @@ -415,7 +415,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb) if (inet_test_bit(HDRINCL, sk)) { if (skb_checksum_complete(skb)) { atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, SKB_DROP_REASON_SKB_CSUM); + kfree_skb_for_sk(skb, sk, SKB_DROP_REASON_SKB_CSUM); return NET_RX_DROP; } } From patchwork Thu May 30 21:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680870 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (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 28BE818735B for ; Thu, 30 May 2024 21:47:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105631; cv=none; b=dO6RSgJ0+hPV8LT+qTnw2+h5oRWID6Flw85oMVMeQCTwc2x9B0wz0CvmnfJxRdrk/ZznqXxzq/U9PMjRmiYdNtIxJ6ybz1vihJ1sErDOps+WKe1TPoBKuigjrImh8FXSfDDdAPJOl+6ugYZ1kZayjxZTuSiHTjraRGPvZcd2zlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105631; c=relaxed/simple; bh=vPCt4wAtO1HnG/ewxxcEuNhbOK4WI09M32LaeYKYdac=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d2kcsL3llYon7pgbVszlqIC0LTX3BRu32FVXuh6jGgMRfTTRKjcKP4DW+14xiOWlSc3KAawpJc2jYztCo6v4aib+ub/OXkOx1VuAdRPpQ/FGVJaW0TYgKqJOOBKon+qTktB5+9C1uxTKWgC6O2qEuUSP5zm8kNoAwxTKt+s2lO0= 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=B+TVWrV7; arc=none smtp.client-ip=209.85.167.178 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="B+TVWrV7" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3d1bb1c3b74so824464b6e.2 for ; Thu, 30 May 2024 14:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105627; x=1717710427; 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=EgOT6ysidbDZUdOMVUdTAX9+IvxmNFHfY7koismnltE=; b=B+TVWrV7DoBOVh0/pNl43jXb/mu8Zl4ACR1cwegfBEWhI9OMROjQgxCKQIgsfHZHlm JX+4brnMEOml97/OJcDlSmdwkV+iVgVyXRyy6E2Zt3ow/5n1DUc990JygAUc0wa8LmK4 1YWwoZEQ36ZEncyVo7z3Uq/8BKN8x+rRD699+mJdw3+Nme4/oj1FgQmcMAYCv9ifrj/e tOJtEkDf2bXM39Qy6XvfRcopxFqJeBo/xzt7EH47el0MMLTJKxdReR6ldPy9e7OTUwgQ /Nl4/muW7oTwAvHkReuSPCUfaGvSyVm22gxMA2Np+Ue0XpXBb/9m3EKfAE9ik+1JaFFy T5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105627; x=1717710427; 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=EgOT6ysidbDZUdOMVUdTAX9+IvxmNFHfY7koismnltE=; b=rRmNxQjcErsZGU5kfLgkYnH5jusrpTAZsVsPOfYG/BLXNo3ylo/e983JX0jerDbMzp vjwB2Fr7WwlMXJaqZexMlCqHnD4z46UEykNgJcEqQ8+5ivofAwsyPy80Ni9Jt60CPoSa SbL35dmMAo3A9KmUwIdADtT8MVNbVt50/VINdnoGR09CGOJzomwcU2EsGPJu5Sh9EMn9 XyQ3SCx9rnCQ3MUd/PjhkZHfd1aLuH7qpJ+OwhuKKTmEmABpfEXQpaczPz0J8AAfoGYK zhgdFEy8VLoRYC4BHda4HovTMlAreecpn8zgSMjff5gGxgYflCmPSxrSD384zE6FX0mm WnOQ== X-Gm-Message-State: AOJu0Yzi7zVxyvEKRVglrCXwX8mVE8/xYSGiQnTPpgE1EkTxMx0fLZZJ 5mQZ0xkNWQQ6TwRJrMh5GfNIEFWAWePshZVOf1aOau+//A2MwYx44e7HFEhDCcp6xXolqcqx3WD wI8o= X-Google-Smtp-Source: AGHT+IEYtelnJyVi+cGFfRgSrc10AA9izjzGiI3lDu+ulwo+lb8cwJNtiaOv8DUtTMKtfa7cDYp9xg== X-Received: by 2002:a05:6808:11d0:b0:3c9:708d:ca69 with SMTP id 5614622812f47-3d1e35cd6efmr10513b6e.56.1717105627129; Thu, 30 May 2024 14:47:07 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4a746691sm1919416d6.38.2024.05.30.14.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:47:06 -0700 (PDT) Date: Thu, 30 May 2024 14:47:04 -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 Subject: [RFC net-next 4/6] tcp: pass rx socket on rcv drops Message-ID: <48392b4d422dd64cb8e76822737928c189b2b4d2.1717105215.git.yan@cloudflare.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use kfree_skb_for_sk call to pass on the rx socket Signed-off-by: Yan Zhai --- net/ipv4/syncookies.c | 2 +- net/ipv4/tcp_input.c | 2 +- net/ipv4/tcp_ipv4.c | 4 ++-- net/ipv6/syncookies.c | 2 +- net/ipv6/tcp_ipv6.c | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index b61d36810fe3..fd0ccf0a0439 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -496,6 +496,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) out_free: reqsk_free(req); out_drop: - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return NULL; } diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 9c04a9c8be9d..6c5f6fe7d9fa 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4849,7 +4849,7 @@ static void tcp_drop_reason(struct sock *sk, struct sk_buff *skb, enum skb_drop_reason reason) { sk_drops_add(sk, skb); - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); } /* This one checks to see if we can put data from the diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 8f70b8d1d1e5..cff9e0c7daec 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1944,7 +1944,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) reset: tcp_v4_send_reset(rsk, skb, sk_rst_convert_drop_reason(reason)); discard: - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); /* Be careful here. If this function gets more complicated and * gcc suffers from register pressure on the x86, sk (in %ebx) * might be destroyed here. This current version compiles correctly, @@ -2381,7 +2381,7 @@ int tcp_v4_rcv(struct sk_buff *skb) discard_it: SKB_DR_OR(drop_reason, NOT_SPECIFIED); /* Discard frame. */ - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return 0; discard_and_relse: diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index bfad1e89b6a6..d09fec4bb0c0 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -275,6 +275,6 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) out_free: reqsk_free(req); out_drop: - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return NULL; } diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 750aa681779c..c7a7f339ca74 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1682,7 +1682,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) discard: if (opt_skb) __kfree_skb(opt_skb); - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return 0; csum_err: reason = SKB_DROP_REASON_TCP_CSUM; @@ -1948,7 +1948,7 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb) discard_it: SKB_DR_OR(drop_reason, NOT_SPECIFIED); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return 0; discard_and_relse: From patchwork Thu May 30 21:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680871 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (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 BF39519067D for ; Thu, 30 May 2024 21:47:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105633; cv=none; b=bFVV9842y+xM5XP0rWRyUVQWRLMYtKSEhCplprMvtW1qPlqp/mxDBBSzinroVPpZZsZ8b01Urf6fxB51QXpW0u3mFlSC5qo7hB7uDI1bGTq5H9pRuD/gsJHioVyfoZ93KlqayPsq0jsf7KsfHy47Y9zh86zhtW+FlRlhWtPN9Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105633; c=relaxed/simple; bh=6dowC/Uwf26NiZaIg168nDsdSN0aKz+6tZkvOLAwGnQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uSz7qz/4Vr0+ZDGkVCHkUy3S/XdiwYbWCZtES85yWhiyJyIGSANGdRHJmrGI8tSGHDwIpqYQwUxn0wytQuv42qzjzPLclyJUaOW27CnV+zWrIHeYSJ/H9ROMg4BDdAGrqBVJXnB3CIgDFV1YEOMTyyv1tFV35BSRiPGKvw353+g= 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=KFMlbyfE; arc=none smtp.client-ip=209.85.210.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="KFMlbyfE" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6f12eb91ec7so794586a34.3 for ; Thu, 30 May 2024 14:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105630; x=1717710430; 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=27TjARiWthXWjefcQW0222UB7xMw3bcD7v/H3qDKiuE=; b=KFMlbyfELd+IMDBFEv5TVqpkYAIFrnadoOkHZntt+LWWH5Lyvbt/DCUuIzSgcEJyw1 jThW9oHKYeY+NY4aOwCCj9kYiDcpRCLRQOR3w4wV7rq8auNss+wFYeHVovWx9wWPbDub LW5C8L8KXNXc8KXUmI8a/rQMFRQ+YvkhMD+DfJr+ezRo9xkkYGs6V7wy+DOapKKeFHAJ fQ4IvRgfrNgqTzSOmi+j/oy0AddmU7pH3ja8xlu0soA40jA9MzxdOz8GFxoLLP2Mc88I jDuPxmj5VH1Pf/JETPXZ62xAmTMkYRzi2UNFSrI7V1mMYdhMSjuMdWN7ZEppnUlupffu Jq3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105630; x=1717710430; 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=27TjARiWthXWjefcQW0222UB7xMw3bcD7v/H3qDKiuE=; b=f1if3l0wmUGwOmTR92zn5H8DtvwuQmHGkkmR7QrvEctQlsX7bmO4F6OBoe8IeB0epM +ph11fcShzNPUffZx8pwY+lsUTcdTToSgOAkPgnz9i2s/WEwM70Qv6aBv0Q2kqZyAAeW ZB/ISJiBhhHA9dCWSfFPIJcb/Si/1zCxGXicLB6+Foe6SzMC8NBM3nzrKxvYIteqBmuX joqFbyKfBTjYuQYdk1R/j9x66/xcoMF9pNeKXtyR2uH+/jzILaEZOh1yksermEAc2Eov /TGX1IfJ0F4gY1q27uvFZDYk/ULawwF5SQPnCVhgAn8RMkxGUivGtUhFx6jVJ7rgs9NA 8ipw== X-Gm-Message-State: AOJu0Yzt1bNB9GkyccBpJ170gPw8NEPUoKQpkfCs9guJNSgwd3Zq2L2r QJf1zHmojGuuPkAgTTIpXYzoFNeusg/Qg1eK+gtE3Tn32RKVBs24oPBPi5Ddj2+q3ZIp/0SK7kp UMw0= X-Google-Smtp-Source: AGHT+IHZeVl7ouGz/puxd9+5HcfYhWbufP8hbtU6k28G151wktaPRdVbkT1nW53EUrW/uRp7+N61ew== X-Received: by 2002:a05:6830:1e15:b0:6ef:9ec1:2bf8 with SMTP id 46e09a7af769-6f911f9fc2bmr93153a34.23.1717105629904; Thu, 30 May 2024 14:47:09 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-43ff23a42bcsm2009991cf.16.2024.05.30.14.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:47:09 -0700 (PDT) Date: Thu, 30 May 2024 14:47:07 -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 Subject: [RFC net-next 5/6] udp: pass rx socket on rcv drops Message-ID: <64c8339aa96232b5d36738162e7bf58412bf6682.1717105215.git.yan@cloudflare.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use kfree_skb_for_sk call to pass on the rx socket Signed-off-by: Yan Zhai --- net/ipv4/udp.c | 6 +++--- net/ipv6/udp.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 189c9113fe9a..e5dbd1cbad50 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -2074,7 +2074,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) } UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); trace_udp_fail_queue_rcv_skb(rc, sk, skb); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return -1; } @@ -2196,7 +2196,7 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) drop: __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return -1; } @@ -2485,7 +2485,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); drop: __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return 0; } diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index c81a07ac0463..97a327c759b8 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c @@ -673,7 +673,7 @@ static int __udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) } UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); trace_udp_fail_queue_rcv_skb(rc, sk, skb); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return -1; } @@ -776,7 +776,7 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) drop: __UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); atomic_inc(&sk->sk_drops); - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return -1; } @@ -1054,7 +1054,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, __UDP6_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); discard: __UDP6_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); - kfree_skb_reason(skb, reason); + kfree_skb_for_sk(skb, sk, reason); return 0; } From patchwork Thu May 30 21:47:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhai X-Patchwork-Id: 13680872 X-Patchwork-Delegate: kuba@kernel.org 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 EE2DE194C89 for ; Thu, 30 May 2024 21:47:14 +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=1717105636; cv=none; b=Zd5hSz60fdToZFKbWthUgoE10VBjBNDSEM/fA8NK4pVVHn9x1hhhmfDu7aFwnK8slO3WZQcalIH3W65NtcQ1HQcvRgoimFuQJU+c45ep7AZwBkM7iiQvT9caWKh60iuP+bmaSb81XZ2j1zl/7ogIadoJ5UkxQvqlquglAQS/SN0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717105636; c=relaxed/simple; bh=zBPfgKOCZ7FGTb7LtwnzoLHAcib59MLufF+CqN5TSP0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=St9gi+8JW8fPg6hADpNCsUUEiU0Tf/K47OyuPNAiZsrs4IVoDr/QBjGaKrFj4+tsPUHcA6nR1BSaowUx/NK7rJKW+/oqcb3RtqHXRkAQeZ3kZNP5DAxE529VkqlhgoxNSjjh+ZnuOXj+BAQrSBfd17/Qf/6IRbfpADE1VWjFeZo= 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=RIqk3s5l; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="RIqk3s5l" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6ae0bf069f3so6871106d6.3 for ; Thu, 30 May 2024 14:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1717105633; x=1717710433; 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=hK/RV3ZAvRKcX5XY/+KVfGOngLsfuJvHovUEHHeWptM=; b=RIqk3s5lhEwhRYw2FJe+5RyMoRbsOM8vHvqrYMHGPlB89vYoQ/PqZ7HbJZtaDYZUWa C4JTfmtEFVTY6rSLh1NYvVTpzyhPWLBgdF66rNKCmdn9ac90gzM3GvhWEYUwj4HVfVoW NK97NcO/BRerw9aXN0sm1A/l2CIHmsIWZ1O6zkzt9XrDCpxVatMWZMqVnIXbG+Tk5KBm opLgza+MZ9UTbMGVwxGJCPLu7jpqvYlrA4mDcBrBRHmJgg+5g56VQ177iT5/x5L9tmij o4mNTmuUpveL82Ywmx556WyuJV6C3HpY7Z61XYmiXJhENLJLWnOssgh+KUNMe77nPjO3 p3lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717105633; x=1717710433; 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=hK/RV3ZAvRKcX5XY/+KVfGOngLsfuJvHovUEHHeWptM=; b=uJWFRjzbxIzc3b0T4WP4UShP8CYfCx/9ChLcGSMTv/65DaW9gQvSW1iwrACM+UVfws c4fL1i+rMFbJr6mLCWAXQ8OFKMwwicnE4Obm3+CB0FYztk3apqOFl/dwtUnzacr1j+Lo Nr32xfE17HjnpexU4Xav4q3ZjVedEQpM9oqagMC3GNz5NjKsZ+/QJpV22UUzHUiurN6x iBkYniDNuWPzMTGMcfv/Qr8KcLiIBMOc4VFtx0h5Wn80M6s11LC/uKSBu9yTHG9NK2Kz vH8f3Xv0NLEHHQEqEsXUltCuILY8KXLPg5zT639k+1ME0+OTUBjnU+PNSARiFQ3+PCD+ R9Pw== X-Gm-Message-State: AOJu0YwWIocZ4fP3s0JwGPygo5uu5nSHwTosuvMYLo3ahQn1y3T5FPGz /Z4hKUh/eM+lesU4xPaCDPKMpPy3L4cHJuSNlO5gs56XzE8euPd/a8k6/Gp57hm7aeFCNPHWLp2 quI0= X-Google-Smtp-Source: AGHT+IHbqI93EibzSyAta5LKCbpan2p512WiBaSen+5LGFNq3txKFmbJqCRt3fWHnZRqPqSQpd153A== X-Received: by 2002:a05:6214:33ca:b0:6ae:19e2:39d3 with SMTP id 6a1803df08f44-6aecd6ef732mr1410496d6.45.1717105632747; Thu, 30 May 2024 14:47:12 -0700 (PDT) Received: from debian.debian ([2a09:bac5:7a49:f9b::18e:1c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ae4b4064d2sm1877406d6.91.2024.05.30.14.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 14:47:11 -0700 (PDT) Date: Thu, 30 May 2024 14:47:10 -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 Subject: [RFC net-next 6/6] af_packet: pass rx socket on rcv drops Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use kfree_skb_for_sk call to pass on the rx socket Signed-off-by: Yan Zhai --- net/packet/af_packet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index fce390887591..30a6447b4fc4 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2226,7 +2226,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, skb->len = skb_len; } drop: - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return 0; } @@ -2494,7 +2494,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, skb->len = skb_len; } drop: - kfree_skb_reason(skb, drop_reason); + kfree_skb_for_sk(skb, sk, drop_reason); return 0; drop_n_account: @@ -2503,7 +2503,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, drop_reason = SKB_DROP_REASON_PACKET_SOCK_ERROR; sk->sk_data_ready(sk); - kfree_skb_reason(copy_skb, drop_reason); + kfree_skb_for_sk(copy_skb, sk, drop_reason); goto drop_n_restore; }