All of lore.kernel.org
 help / color / mirror / Atom feed
* execution context in netfilter hooks.
@ 2005-12-11 20:39 Giacomo
  2005-12-12 20:43 ` Harald Welte
  0 siblings, 1 reply; 5+ messages in thread
From: Giacomo @ 2005-12-11 20:39 UTC (permalink / raw)
  To: netfilter-devel

Good morning, i would like to know exactly the context of execution
of code registered with netfilter hooks.
 As far as  I understood, the context is that of a softirq, inside a
bottom half. Correct me if i'm wrong..

But is it concerned with tasklets?

Is execution serialized? In other words, if packet A fr instance is
received from the net, and then packet
B immediately, is packet A processed entirely before packet B? Or code
can be executed in parallel
for packet A and B?

Moreover: interrupts are enabled in such context, aren't they? And that
means that also a
software timer can interrupt a routine being executed in bottom half.

But software timers run with sw interrupts disabled, so a timeout
handler for instance cannot
be interrupted by a routine managing reception of a packet arrived on
the wire.

It is not clear to me the concurrency to which structures are subject,
also in an uniprocessor system:
in_irq(), in_softirq(), in_interrupt() functions return different values
also if positioned at the same place in the code... is there a mean
(function) to know if sofware/hw interrupts are enabled in a portion of
code?

Thanks a lot for any suggestion or any indication to understand how
things are really.

Giacomo.

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: execution context in netfilter hooks.
@ 2005-12-13  8:06 Giacomo
  0 siblings, 0 replies; 5+ messages in thread
From: Giacomo @ 2005-12-13  8:06 UTC (permalink / raw)
  To: Harald Welte, netfilter devel

Thank you very much for the answer.
The thing that confused me was that i had some
functions that registered with netfilter hooks.
I thought that processing was serialized, as you said
'in a queue'...
One of those functions was consulting a linked list, each
entry in such list had a timer attached. When timer expired, the entry
was freed.
After millions of packets processed by my function, a
crash happened. I solved the problem putting
'read_lock/unlock_bh' around linked list search and around timer
expiry handler function.
I thought it was not possible that my function was interrupted, while
instead things revealed that probably
i was unsafely freeing an entry in list which still had been
used by another function.

read_locks during list_for_each while consulting list, together with
write_locks around timeout handlers and
list_add solved.

So i'm trying to understand the reason why this happened, and if i am
right to use read/write locks (_bh)
or if i would better use spin_locks (_bh) or spin locks together with
_rcu version of lists.

When i said 'is it concerned with tasklets' i meant: after
hardirq when receiving a packet, is the packet processing (and
netfilter hook functions) registered as a tasklet to run later?

As to software timers, i thought  they were interrupting the other
routine scanning the linked list, as it resulted in the crash. But
probably this was due to 'kernel on behalf of process' context in
local output packets, as you said. (->does this mean no softirq
context -> routine interruptible?)

I read a lot of documents, but they talk a lot about
bottom halves, softirqs and tasklets, but perhaps some
things have changed in 2.6.x, and then i thought that new kernel
preemption would have made processing resemble SMP processing also un
UP systems.

Excuse my many questions, but i would like to clarify those important issues...

Thanks a lot!

Giacomo
--

Giacomo S.
http://www.giacomos.it

- - - - - - - - - - - - - - - - - - - - - -

Running `IPFIRE-wall` on debian GNU/Linux
http://www.giacomos.it/ipfire
http://www.debian.org

mailto:
delleceste@gmail.com
giacomo.strangolino@elettra.trieste.it
jacum@libero.it

- - - - - - - - - - - - - - - - - - - - - -

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-12-13 10:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-11 20:39 execution context in netfilter hooks Giacomo
2005-12-12 20:43 ` Harald Welte
2005-12-13  8:04   ` Giacomo
2005-12-13 10:30     ` Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2005-12-13  8:06 Giacomo

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.