smp_rmb() in consume_skb

2 messages, 2 authors, 2012-10-11 · open the first message on its own page

smp_rmb() in consume_skb

From: Kshemendra KP <hidden>
Date: 2012-10-11 12:20:40

Hi,

    When I was looking into consume_skb() routine (net/core/skbuff.c),
there is smp_rmb() read barrier is present.
    It is not clear why this is needed here.  Basically this routine frees
sk_buff if only one user reference is theere

     void consume_skb(struct sk_buff * skb)
     {
         if (unlikely(!skb))
              return;
         if (likley (atomic_read (&skb->users) == 1))
              smp_rmb()
 --------------------------------------------------------> need for this
barrier

            ......
          __kfree_skb();
     }


Regards

Kshemendra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20121011/2511c77c/attachment.html 

smp_rmb() in consume_skb

From: Mulyadi Santosa <hidden>
Date: 2012-10-11 16:09:32

Hi :)

On Thu, Oct 11, 2012 at 7:20 PM, Kshemendra KP [off-list ref] wrote:
     void consume_skb(struct sk_buff * skb)
     {
         if (unlikely(!skb))
              return;
         if (likley (atomic_read (&skb->users) == 1))
              smp_rmb()
--------------------------------------------------------> need for this
barrier

            ......
          __kfree_skb();
     }
In most cases, read barrier is needed to make sure all
cores/processors see the latest data updates

Specificly, in this case, i think it is done to prevent memory free
race. Which..if not well prevented, could lead to double free. And
that's bad.

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help