From: Pablo Neira <pablo@eurodev.net>
To: Roberto Jung Drebes <drebes@inf.ufrgs.br>
Cc: netfilter-devel@lists.netfilter.org
Subject: Re: GFP_ATOMIC vs GFP_KERNEL in netfilter module
Date: Fri, 03 Dec 2004 00:33:59 +0100 [thread overview]
Message-ID: <41AFA667.4030004@eurodev.net> (raw)
In-Reply-To: <92A26C52-44B7-11D9-A62F-000A957B2B6C@inf.ufrgs.br>
You are in interrupt context, so GFP_KERNEL is illegal since it can sleep.
--
Pablo
Roberto Jung Drebes wrote:
> Hello there,
>
> I am testing a simple netfilter module which delays every 5th IP
> packet received. I am having problems allocating the timer structure.
> Here is the netfilter hook I register:
>
> static unsigned int
> comfirm_rx_hook(unsigned int hook,
> struct sk_buff **pskb,
> const struct net_device *in,
> const struct net_device *out,
> int (*okfn) (struct sk_buff *))
> {
> static int counter;
> struct timer_list *tl;
> struct cf_delay_parms *dp;
>
> if ((*pskb)->nfmark != CF_MAGIC) {
> counter++;
>
> if (!(counter % 5)) {
> dp = kmalloc(sizeof(struct cf_delay_parms), GFP_KERNEL);
> tl = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
> dp->timer = tl;
> (*pskb)->nfmark = CF_MAGIC;
> dp->skb = *pskb;
> tl->data = (unsigned long) dp;
> tl->function = (void *) cf_delay_rx;
> tl->expires = jiffies + 100;
> init_timer(tl);
> add_timer(tl);
> printk("packet delayed\n");
> return NF_STOLEN;
> } else
> return NF_ACCEPT;
> } else
> return NF_ACCEPT;
> }
>
> void cf_delay_rx(struct cf_delay_parms *parms)
> {
> ip_rcv(parms->skb, parms->skb->dev, NULL);
> kfree(parms->timer);
> kfree(parms);
> }
>
> If I use GFP_KERNEL with the kmallocs, I get errors like
>
> Debug: sleeping function called from invalid context at mm/slab.c:2000
> in_atomic():1[expected: 0], irqs_disabled():0
> [<0211b765>] __might_sleep+0x82/0x8c
> [<02146dbc>] kmem_cache_alloc+0x1d/0x4c
> [<2204b047>] comfirm_rx_hook+0x47/0xd8 [mymodule]
> [<022a68eb>] nf_iterate+0x40/0x89
> [<022b5d63>] ip_rcv_finish+0x0/0x1d9
> [<022a6bac>] nf_hook_slow+0x47/0xb1
> [<022b5d63>] ip_rcv_finish+0x0/0x1d9
> [<022b5be7>] ip_rcv+0x36d/0x3a1
> [<022b5d63>] ip_rcv_finish+0x0/0x1d9
> [<0229eef3>] netif_receive_skb+0x1b0/0x1dd
> [<0229ef8c>] process_backlog+0x6c/0xd9
> [<0229f056>] net_rx_action+0x5d/0xcd
> [<02122fa1>] __do_softirq+0x35/0x73
> [<02108a7b>] do_softirq+0x46/0x4d
> =======================
> [<02107e67>] do_IRQ+0x2f7/0x303
> [<021fc4c1>] acpi_processor_idle+0xd3/0x1c5
> [<0210408c>] cpu_idle+0x1f/0x34
> [<0239b6ae>] start_kernel+0x221/0x224
>
> If I use GFP_ATOMIC, I don't get the error, but I think timers are not
> being called after the delay. I have a similar code for transmition,
> which works OK with GFP_KERNEL (delays messages) but with GFP_ATOMIC
> it does also not delay.
>
> I test delay with ping, and I am running kernel 2.6.8-1.521 from
> Fedora Core 2.
>
> What am I doing wrong?
>
> TIA,
>
> ps: Please CC me any reply from the linux-kernel mailing list.
>
next prev parent reply other threads:[~2004-12-02 23:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-02 23:12 GFP_ATOMIC vs GFP_KERNEL in netfilter module Roberto Jung Drebes
2004-12-02 23:33 ` Pablo Neira [this message]
2004-12-03 0:31 ` Robert Love
2004-12-06 13:10 ` Roberto Jung Drebes
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=41AFA667.4030004@eurodev.net \
--to=pablo@eurodev.net \
--cc=drebes@inf.ufrgs.br \
--cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.