From: Greg KH <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, "Eric Dumazet" <eric.dumazet@gmail.com>,
"David S. Miller" <davem@davemloft.net>, 单卫 <shanwei88@gmail.com>
Subject: [21/21] net: sock_queue_err_skb() dont mess with sk_forward_alloc
Date: Fri, 10 Feb 2012 14:48:00 -0800 [thread overview]
Message-ID: <20120210224852.669918853@clark.kroah.org> (raw)
In-Reply-To: <20120210224858.GA30752@kroah.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3833 bytes --]
2.6.32-longterm review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <eric.dumazet@gmail.com>
commit b1faf5666438090a4dc4fceac8502edc7788b7e3 upstream.
Correct sk_forward_alloc handling for error_queue would need to use a
backlog of frames that softirq handler could not deliver because socket
is owned by user thread. Or extend backlog processing to be able to
process normal and error packets.
Another possibility is to not use mem charge for error queue, this is
what I implemented in this patch.
Note: this reverts commit 29030374
(net: fix sk_forward_alloc corruptions), since we dont need to lock
socket anymore.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Cc: 单卫 <shanwei88@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/net/sock.h | 15 +--------------
net/core/skbuff.c | 30 ++++++++++++++++++++++++++++--
net/ipv4/udp.c | 6 ++----
net/ipv6/udp.c | 6 ++----
4 files changed, 33 insertions(+), 24 deletions(-)
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1354,20 +1354,7 @@ extern void sk_stop_timer(struct sock *s
extern int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
-static inline int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
-{
- /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
- number of warnings when compiling with -W --ANK
- */
- if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
- (unsigned)sk->sk_rcvbuf)
- return -ENOMEM;
- skb_set_owner_r(skb, sk);
- skb_queue_tail(&sk->sk_error_queue, skb);
- if (!sock_flag(sk, SOCK_DEAD))
- sk->sk_data_ready(sk, skb->len);
- return 0;
-}
+extern int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb);
/*
* Recover an error report and clear atomically
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2977,6 +2977,34 @@ int skb_cow_data(struct sk_buff *skb, in
}
EXPORT_SYMBOL_GPL(skb_cow_data);
+static void sock_rmem_free(struct sk_buff *skb)
+{
+ struct sock *sk = skb->sk;
+
+ atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
+}
+
+/*
+ * Note: We dont mem charge error packets (no sk_forward_alloc changes)
+ */
+int sock_queue_err_skb(struct sock *sk, struct sk_buff *skb)
+{
+ if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >=
+ (unsigned)sk->sk_rcvbuf)
+ return -ENOMEM;
+
+ skb_orphan(skb);
+ skb->sk = sk;
+ skb->destructor = sock_rmem_free;
+ atomic_add(skb->truesize, &sk->sk_rmem_alloc);
+
+ skb_queue_tail(&sk->sk_error_queue, skb);
+ if (!sock_flag(sk, SOCK_DEAD))
+ sk->sk_data_ready(sk, skb->len);
+ return 0;
+}
+EXPORT_SYMBOL(sock_queue_err_skb);
+
void skb_tstamp_tx(struct sk_buff *orig_skb,
struct skb_shared_hwtstamps *hwtstamps)
{
@@ -3009,9 +3037,7 @@ void skb_tstamp_tx(struct sk_buff *orig_
serr->ee.ee_errno = ENOMSG;
serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
- bh_lock_sock(sk);
err = sock_queue_err_skb(sk, skb);
- bh_unlock_sock(sk);
if (err)
kfree_skb(skb);
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -440,11 +440,9 @@ void __udp4_lib_err(struct sk_buff *skb,
if (!inet->recverr) {
if (!harderr || sk->sk_state != TCP_ESTABLISHED)
goto out;
- } else {
- bh_lock_sock(sk);
+ } else
ip_icmp_error(sk, skb, err, uh->dest, info, (u8 *)(uh+1));
- bh_unlock_sock(sk);
- }
+
sk->sk_err = err;
sk->sk_error_report(sk);
out:
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -337,11 +337,9 @@ void __udp6_lib_err(struct sk_buff *skb,
if (sk->sk_state != TCP_ESTABLISHED && !np->recverr)
goto out;
- if (np->recverr) {
- bh_lock_sock(sk);
+ if (np->recverr)
ipv6_icmp_error(sk, skb, err, uh->dest, ntohl(info), (u8 *)(uh+1));
- bh_unlock_sock(sk);
- }
+
sk->sk_err = err;
sk->sk_error_report(sk);
out:
prev parent reply other threads:[~2012-02-10 22:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-10 22:48 [00/21] 2.6.32.57-longterm review Greg KH
2012-02-10 22:47 ` [01/21] IB/mlx4: pass SMP vendor-specific attribute MADs to firmware Greg KH
2012-02-10 22:47 ` [02/21] mm/filemap_xip.c: fix race condition in xip_file_fault() Greg KH
2012-02-10 22:47 ` [03/21] NFSv4: Fix up the callers of nfs4_state_end_reclaim_reboot Greg KH
2012-02-10 22:47 ` [04/21] NFSv4: The state manager shouldnt exit on errors that were handled Greg KH
2012-02-10 22:47 ` [05/21] NFSv4: Ensure the state manager handles NFS4ERR_NO_GRACE correctly Greg KH
2012-02-10 22:47 ` [06/21] NFSv4: Handle NFS4ERR_GRACE when recovering an expired lease Greg KH
2012-02-10 22:47 ` [07/21] NFSv4: Fix open recovery Greg KH
2012-02-10 22:47 ` [08/21] rpc client can not deal with ENOSOCK, so translate it into ENOCONN Greg KH
2012-02-10 22:47 ` [09/21] udf: Mark LVID buffer as uptodate before marking it dirty Greg KH
2012-02-10 22:47 ` [10/21] drm/i915: Fix TV Out refresh rate Greg KH
2012-02-10 22:47 ` [11/21] eCryptfs: Infinite loop due to overflow in ecryptfs_write() Greg KH
2012-02-10 22:47 ` [12/21] atmel_lcdfb: fix usage of CONTRAST_CTR in suspend/resume Greg KH
2012-02-10 22:47 ` [13/21] Staging: asus_oled: fix image processing Greg KH
2012-02-10 22:47 ` [14/21] Staging: android: binder: Dont call dump_stack in binder_vma_open Greg KH
2012-02-10 22:47 ` [15/21] Staging: android: binder: Fix crashes when sharing a binder file between processes Greg KH
2012-02-10 22:47 ` [16/21] usb: gadget: zero: fix bug in loopback autoresume handling Greg KH
2012-02-10 22:47 ` [17/21] usb: Skip PCI USB quirk handling for Netlogic XLP Greg KH
2012-02-10 22:47 ` [18/21] USB: usbserial: add new PID number (0xa951) to the ftdi driver Greg KH
2012-02-10 22:47 ` [19/21] mmc: cb710 core: Add missing spin_lock_init for irq_lock of struct cb710_chip Greg KH
2012-02-10 22:47 ` [20/21] net: fix sk_forward_alloc corruptions Greg KH
2012-02-10 22:48 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120210224852.669918853@clark.kroah.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shanwei88@gmail.com \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox