Re: [PATCH] UML - Correctly handle skb allocation failures

From: Andrew Morton
Date: Thu Sep 27 2007 - 19:54:15 EST


On Thu, 27 Sep 2007 13:01:26 -0400
Jeff Dike <jdike@xxxxxxxxxxx> wrote:

> +static int update_drop_skb(int max)
> +{
> + struct sk_buff *new;
> + int err = 0;
> +
> + spin_lock(&drop_lock);
> +
> + if (max <= drop_max)
> + goto out;
> +
> + err = -ENOMEM;
> + new = dev_alloc_skb(max);
> + if (new == NULL)
> + goto out;
> +
> + skb_put(new, max);
> +
> + kfree_skb(drop_skb);
> + drop_skb = new;
> + drop_max = max;
> + err = 0;
> +out:
> + spin_unlock(&drop_lock);
> +
> + return err;
> +}
> +
> static int uml_net_rx(struct net_device *dev)
> {
> struct uml_net_private *lp = dev->priv;
> @@ -43,6 +82,9 @@ static int uml_net_rx(struct net_device
> /* If we can't allocate memory, try again next round. */
> skb = dev_alloc_skb(lp->max_packet);
> if (skb == NULL) {
> + drop_skb->dev = dev;
> + /* Read a packet into drop_skb and don't do anything with it. */
> + (*lp->read)(lp->fd, drop_skb, lp);
> lp->stats.rx_dropped++;
> return 0;

Still wanna know why it is safe for uml_net_rx to be playing with
drop_skb when update_drop_skb() could be concurrently reallocating
and freeing it.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/