net: correct off-by-one write allocations reports
authorEric Dumazet <eric.dumazet@gmail.com>
Thu, 18 Jun 2009 02:05:41 +0000 (19:05 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 18 Jun 2009 07:29:12 +0000 (00:29 -0700)
commit 2b85a34e911bf483c27cfdd124aeb1605145dc80
(net: No more expensive sock_hold()/sock_put() on each tx)
changed initial sk_wmem_alloc value.

We need to take into account this offset when reporting
sk_wmem_alloc to user, in PROC_FS files or various
ioctls (SIOCOUTQ/TIOCOUTQ)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
25 files changed:
net/appletalk/atalk_proc.c
net/appletalk/ddp.c
net/ax25/af_ax25.c
net/bluetooth/af_bluetooth.c
net/decnet/af_decnet.c
net/ieee802154/dgram.c
net/ipv4/inet_diag.c
net/ipv4/raw.c
net/ipv4/udp.c
net/ipv6/raw.c
net/ipv6/udp.c
net/ipx/af_ipx.c
net/ipx/ipx_proc.c
net/irda/af_irda.c
net/key/af_key.c
net/llc/llc_proc.c
net/netlink/af_netlink.c
net/netrom/af_netrom.c
net/packet/af_packet.c
net/rose/af_rose.c
net/sched/em_meta.c
net/sctp/socket.c
net/unix/af_unix.c
net/x25/af_x25.c
net/x25/x25_proc.c

index fd8e0847b25473ac9318aa22769af66500dbb073..80caad1a31a5feb60e2f626aaaf57aae2455fd96 100644 (file)
@@ -204,8 +204,8 @@ static int atalk_seq_socket_show(struct seq_file *seq, void *v)
                        "%02X %d\n",
                   s->sk_type, ntohs(at->src_net), at->src_node, at->src_port,
                   ntohs(at->dest_net), at->dest_node, at->dest_port,
-                  atomic_read(&s->sk_wmem_alloc),
-                  atomic_read(&s->sk_rmem_alloc),
+                  sk_wmem_alloc_get(s),
+                  sk_rmem_alloc_get(s),
                   s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
 out:
        return 0;
index f7a53b219ef07937ec3e42a183d2d51d87b5fbf2..590b8396362237e62b82965b2f6e95fb1c167591 100644 (file)
@@ -1748,8 +1748,7 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        switch (cmd) {
                /* Protocol layer */
                case TIOCOUTQ: {
-                       long amount = sk->sk_sndbuf -
-                                     atomic_read(&sk->sk_wmem_alloc);
+                       long amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
 
                        if (amount < 0)
                                amount = 0;
index 61b35b955490f6729a66fd5b073058e3b056b4fc..da0f64f82b5771f65ada62e157b042119ade99b8 100644 (file)
@@ -1690,7 +1690,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case TIOCOUTQ: {
                long amount;
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                res = put_user(amount, (int __user *)argp);
@@ -1780,8 +1781,8 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                ax25_info.idletimer = ax25_display_timer(&ax25->idletimer) / (60 * HZ);
                ax25_info.n2count   = ax25->n2count;
                ax25_info.state     = ax25->state;
-               ax25_info.rcv_q     = atomic_read(&sk->sk_rmem_alloc);
-               ax25_info.snd_q     = atomic_read(&sk->sk_wmem_alloc);
+               ax25_info.rcv_q     = sk_wmem_alloc_get(sk);
+               ax25_info.snd_q     = sk_rmem_alloc_get(sk);
                ax25_info.vs        = ax25->vs;
                ax25_info.vr        = ax25->vr;
                ax25_info.va        = ax25->va;
@@ -1921,8 +1922,8 @@ static int ax25_info_show(struct seq_file *seq, void *v)
 
        if (ax25->sk != NULL) {
                seq_printf(seq, " %d %d %lu\n",
-                          atomic_read(&ax25->sk->sk_wmem_alloc),
-                          atomic_read(&ax25->sk->sk_rmem_alloc),
+                          sk_wmem_alloc_get(ax25->sk),
+                          sk_rmem_alloc_get(ax25->sk),
                           sock_i_ino(ax25->sk));
        } else {
                seq_puts(seq, " * * *\n");
index 02b9baa1930b86e641447e1247b6214616c59906..0250e0600150a464c8b3a1ecf8f56f7cff41f867 100644 (file)
@@ -337,7 +337,7 @@ int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                if (sk->sk_state == BT_LISTEN)
                        return -EINVAL;
 
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                err = put_user(amount, (int __user *) arg);
index a5e3a593e47224e8bd4a1a85ddd949141143816c..d351b8db0df5ceac6f6c566bb82cb9a700d78d2a 100644 (file)
@@ -1240,7 +1240,7 @@ static int dn_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                return val;
 
        case TIOCOUTQ:
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                err = put_user(amount, (int __user *)arg);
index 1779677aed46f16ecae9d0e8c880a7052391c18a..14d39840dd62e736e9dfb96efc011c5b41dd92ab 100644 (file)
@@ -126,7 +126,8 @@ static int dgram_ioctl(struct sock *sk, int cmd, unsigned long arg)
        switch (cmd) {
        case SIOCOUTQ:
        {
-               int amount = atomic_read(&sk->sk_wmem_alloc);
+               int amount = sk_wmem_alloc_get(sk);
+
                return put_user(amount, (int __user *)arg);
        }
 
index b0b273503e2ad4fb58085430ed506d30e1bfd6f7..a706a47f4dbb75aa35e7423781e38491032242b0 100644 (file)
@@ -156,10 +156,10 @@ static int inet_csk_diag_fill(struct sock *sk,
        r->idiag_inode = sock_i_ino(sk);
 
        if (minfo) {
-               minfo->idiag_rmem = atomic_read(&sk->sk_rmem_alloc);
+               minfo->idiag_rmem = sk_rmem_alloc_get(sk);
                minfo->idiag_wmem = sk->sk_wmem_queued;
                minfo->idiag_fmem = sk->sk_forward_alloc;
-               minfo->idiag_tmem = atomic_read(&sk->sk_wmem_alloc);
+               minfo->idiag_tmem = sk_wmem_alloc_get(sk);
        }
 
        handler->idiag_get_info(sk, r, info);
index 3dc9171a272f61e5a174b571a7fcc4213336344e..2979f14bb188844965a59bc0e5013f7d1d374eb2 100644 (file)
@@ -799,7 +799,8 @@ static int raw_ioctl(struct sock *sk, int cmd, unsigned long arg)
 {
        switch (cmd) {
                case SIOCOUTQ: {
-                       int amount = atomic_read(&sk->sk_wmem_alloc);
+                       int amount = sk_wmem_alloc_get(sk);
+
                        return put_user(amount, (int __user *)arg);
                }
                case SIOCINQ: {
@@ -935,8 +936,8 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
        seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
                i, src, srcp, dest, destp, sp->sk_state,
-               atomic_read(&sp->sk_wmem_alloc),
-               atomic_read(&sp->sk_rmem_alloc),
+               sk_wmem_alloc_get(sp),
+               sk_rmem_alloc_get(sp),
                0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
                atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
 }
index 8f4158d7c9a65ffcc02cf28a0abf3c10cc20cc07..80e3812837ad57752af3a22075102c0ed81ce19e 100644 (file)
@@ -840,7 +840,8 @@ int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
        switch (cmd) {
        case SIOCOUTQ:
        {
-               int amount = atomic_read(&sk->sk_wmem_alloc);
+               int amount = sk_wmem_alloc_get(sk);
+
                return put_user(amount, (int __user *)arg);
        }
 
@@ -1721,8 +1722,8 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
        seq_printf(f, "%4d: %08X:%04X %08X:%04X"
                " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
                bucket, src, srcp, dest, destp, sp->sk_state,
-               atomic_read(&sp->sk_wmem_alloc),
-               atomic_read(&sp->sk_rmem_alloc),
+               sk_wmem_alloc_get(sp),
+               sk_rmem_alloc_get(sp),
                0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
                atomic_read(&sp->sk_refcnt), sp,
                atomic_read(&sp->sk_drops), len);
index 36a090d87a3d1c8497426b0bfb6d15b5330b80bf..8b0b6f948063607d8d60ec18bde103a36369bc2a 100644 (file)
@@ -1130,7 +1130,8 @@ static int rawv6_ioctl(struct sock *sk, int cmd, unsigned long arg)
        switch(cmd) {
                case SIOCOUTQ:
                {
-                       int amount = atomic_read(&sk->sk_wmem_alloc);
+                       int amount = sk_wmem_alloc_get(sk);
+
                        return put_user(amount, (int __user *)arg);
                }
                case SIOCINQ:
@@ -1236,8 +1237,8 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
                   dest->s6_addr32[0], dest->s6_addr32[1],
                   dest->s6_addr32[2], dest->s6_addr32[3], destp,
                   sp->sk_state,
-                  atomic_read(&sp->sk_wmem_alloc),
-                  atomic_read(&sp->sk_rmem_alloc),
+                  sk_wmem_alloc_get(sp),
+                  sk_rmem_alloc_get(sp),
                   0, 0L, 0,
                   sock_i_uid(sp), 0,
                   sock_i_ino(sp),
index fc333d854728ee875e9068029d0ee44a4456d6c2..023beda6b22445f52f75e13fc3e0000b78d42342 100644 (file)
@@ -1061,8 +1061,8 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
                   dest->s6_addr32[0], dest->s6_addr32[1],
                   dest->s6_addr32[2], dest->s6_addr32[3], destp,
                   sp->sk_state,
-                  atomic_read(&sp->sk_wmem_alloc),
-                  atomic_read(&sp->sk_rmem_alloc),
+                  sk_wmem_alloc_get(sp),
+                  sk_rmem_alloc_get(sp),
                   0, 0L, 0,
                   sock_i_uid(sp), 0,
                   sock_i_ino(sp),
index 1627050e29fd76b44438c086aa69fcc7c8f93d6b..417b0e30949551de04cc6e1f8087ca9a7809da08 100644 (file)
@@ -1835,7 +1835,7 @@ static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 
        switch (cmd) {
        case TIOCOUTQ:
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                rc = put_user(amount, (int __user *)argp);
index 5ed97ad0e2e33e438cf482324b9b06d806a6d5fb..576178482f893fadf6b4280251b5206dcc24368a 100644 (file)
@@ -280,8 +280,8 @@ static int ipx_seq_socket_show(struct seq_file *seq, void *v)
        }
 
        seq_printf(seq, "%08X  %08X  %02X     %03d\n",
-                  atomic_read(&s->sk_wmem_alloc),
-                  atomic_read(&s->sk_rmem_alloc),
+                  sk_wmem_alloc_get(s),
+                  sk_rmem_alloc_get(s),
                   s->sk_state, SOCK_INODE(s->sk_socket)->i_uid);
 out:
        return 0;
index 3eb5bcc75f99083eb971b93eddbb967d704ad81a..5922febe25c42dc9a602378a600db8d8da674f85 100644 (file)
@@ -1762,7 +1762,8 @@ static int irda_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case TIOCOUTQ: {
                long amount;
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                if (put_user(amount, (unsigned int __user *)arg))
index 643c1be2d02e85c4622d87830db0b90942cdb2e3..dba9abd27f90d42cb240c08d6a08e7529a5e6797 100644 (file)
@@ -3662,8 +3662,8 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
                seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
                               s,
                               atomic_read(&s->sk_refcnt),
-                              atomic_read(&s->sk_rmem_alloc),
-                              atomic_read(&s->sk_wmem_alloc),
+                              sk_rmem_alloc_get(s),
+                              sk_wmem_alloc_get(s),
                               sock_i_uid(s),
                               sock_i_ino(s)
                               );
index d208b3396d94e417546a143c4c7a1d09f9e95f3b..f97be471fe2edc38a7e180cdb74b80489aac2bdc 100644 (file)
@@ -134,8 +134,8 @@ static int llc_seq_socket_show(struct seq_file *seq, void *v)
        seq_printf(seq, "@%02X ", llc->sap->laddr.lsap);
        llc_ui_format_mac(seq, llc->daddr.mac);
        seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
-                  atomic_read(&sk->sk_wmem_alloc),
-                  atomic_read(&sk->sk_rmem_alloc) - llc->copied_seq,
+                  sk_wmem_alloc_get(sk),
+                  sk_rmem_alloc_get(sk) - llc->copied_seq,
                   sk->sk_state,
                   sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
                   llc->link);
index 8b6bbb3032b0ca1718037ff0b3139e883c3d813a..2936fa3b6dc8f460177033bdbda1e95416cec7f4 100644 (file)
@@ -1914,8 +1914,8 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
                           s->sk_protocol,
                           nlk->pid,
                           nlk->groups ? (u32)nlk->groups[0] : 0,
-                          atomic_read(&s->sk_rmem_alloc),
-                          atomic_read(&s->sk_wmem_alloc),
+                          sk_rmem_alloc_get(s),
+                          sk_wmem_alloc_get(s),
                           nlk->cb,
                           atomic_read(&s->sk_refcnt),
                           atomic_read(&s->sk_drops)
index cd911904cbe1f7e044b4ea57ac58fd2f276f8e32..ce51ce012cdab48e4c0bbfd99c3053a0bfcaa636 100644 (file)
@@ -1205,7 +1205,7 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                long amount;
 
                lock_sock(sk);
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                release_sock(sk);
@@ -1341,8 +1341,8 @@ static int nr_info_show(struct seq_file *seq, void *v)
                        nr->n2count,
                        nr->n2,
                        nr->window,
-                       atomic_read(&s->sk_wmem_alloc),
-                       atomic_read(&s->sk_rmem_alloc),
+                       sk_wmem_alloc_get(s),
+                       sk_rmem_alloc_get(s),
                        s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
 
                bh_unlock_sock(s);
index 4f76e5552d8e94dff5e43fd4d1861a8dede91751..ebe5718baa319bc004cea0231a9038ce84e1c55f 100644 (file)
@@ -1987,7 +1987,8 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
        switch (cmd) {
                case SIOCOUTQ:
                {
-                       int amount = atomic_read(&sk->sk_wmem_alloc);
+                       int amount = sk_wmem_alloc_get(sk);
+
                        return put_user(amount, (int __user *)arg);
                }
                case SIOCINQ:
index 4dd9a7d18945142a1b2c065370a9c215e6f7f92b..6bd8e93869eda9d6d5732bcf502ba32d7ca041db 100644 (file)
@@ -1309,7 +1309,8 @@ static int rose_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
        switch (cmd) {
        case TIOCOUTQ: {
                long amount;
-               amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+
+               amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
                if (amount < 0)
                        amount = 0;
                return put_user(amount, (unsigned int __user *) argp);
@@ -1480,8 +1481,8 @@ static int rose_info_show(struct seq_file *seq, void *v)
                        rose->hb / HZ,
                        ax25_display_timer(&rose->idletimer) / (60 * HZ),
                        rose->idle / (60 * HZ),
-                       atomic_read(&s->sk_wmem_alloc),
-                       atomic_read(&s->sk_rmem_alloc),
+                       sk_wmem_alloc_get(s),
+                       sk_rmem_alloc_get(s),
                        s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
        }
 
index 266151ae85a308444c5912ee974088a2fded41c3..18d85d2591047d6a9d38960fb172b59b6b85c4e4 100644 (file)
@@ -349,13 +349,13 @@ META_COLLECTOR(int_sk_type)
 META_COLLECTOR(int_sk_rmem_alloc)
 {
        SKIP_NONLOCAL(skb);
-       dst->value = atomic_read(&skb->sk->sk_rmem_alloc);
+       dst->value = sk_rmem_alloc_get(skb->sk);
 }
 
 META_COLLECTOR(int_sk_wmem_alloc)
 {
        SKIP_NONLOCAL(skb);
-       dst->value = atomic_read(&skb->sk->sk_wmem_alloc);
+       dst->value = sk_wmem_alloc_get(skb->sk);
 }
 
 META_COLLECTOR(int_sk_omem_alloc)
index 0f01e5d8a24f914e77292785bdd727244488fa65..35ba035970a2ace360d9e5498a35e02a7f8a68e6 100644 (file)
@@ -130,7 +130,7 @@ static inline int sctp_wspace(struct sctp_association *asoc)
        if (asoc->ep->sndbuf_policy)
                amt = asoc->sndbuf_used;
        else
-               amt = atomic_read(&asoc->base.sk->sk_wmem_alloc);
+               amt = sk_wmem_alloc_get(asoc->base.sk);
 
        if (amt >= asoc->base.sk->sk_sndbuf) {
                if (asoc->base.sk->sk_userlocks & SOCK_SNDBUF_LOCK)
@@ -6523,7 +6523,7 @@ static int sctp_writeable(struct sock *sk)
 {
        int amt = 0;
 
-       amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
+       amt = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
        if (amt < 0)
                amt = 0;
        return amt;
index 9dcc6e7f96ec2126039ce6b57768b7274bf5f19e..36d4e44d62334275ffbfaa8e3b837e95bcdace5f 100644 (file)
@@ -1946,7 +1946,7 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 
        switch (cmd) {
        case SIOCOUTQ:
-               amount = atomic_read(&sk->sk_wmem_alloc);
+               amount = sk_wmem_alloc_get(sk);
                err = put_user(amount, (int __user *)arg);
                break;
        case SIOCINQ:
index 8cd2390b0d45ef1410a038bc183f5962573a4291..21cdc872004edbb4acba70070eadaa0ad8102e27 100644 (file)
@@ -1271,8 +1271,8 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 
        switch (cmd) {
                case TIOCOUTQ: {
-                       int amount = sk->sk_sndbuf -
-                                    atomic_read(&sk->sk_wmem_alloc);
+                       int amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
+
                        if (amount < 0)
                                amount = 0;
                        rc = put_user(amount, (unsigned int __user *)argp);
index 1afa44d25beb8825e41ac5d263e826352b19a03e..0a04e62e0e187c454199e184c94c198fd37c53c9 100644 (file)
@@ -163,8 +163,8 @@ static int x25_seq_socket_show(struct seq_file *seq, void *v)
                   devname, x25->lci & 0x0FFF, x25->state, x25->vs, x25->vr,
                   x25->va, x25_display_timer(s) / HZ, x25->t2  / HZ,
                   x25->t21 / HZ, x25->t22 / HZ, x25->t23 / HZ,
-                  atomic_read(&s->sk_wmem_alloc),
-                  atomic_read(&s->sk_rmem_alloc),
+                  sk_wmem_alloc_get(s),
+                  sk_rmem_alloc_get(s),
                   s->sk_socket ? SOCK_INODE(s->sk_socket)->i_ino : 0L);
 out:
        return 0;