5

I am developing a kernel module that shares data structures between a softirq (netfilter pre-routing hook) and a user context (within an ioctl call).

After reading this link, I know I need to disable the software interrupts in the user context when modifying the data (using either spin_lock_bh or spin_lock_irqsave) and re-enable them once the operations on the share data are completed.

However, I am un-sure whether I need to grab the lock in the softirq handler function. Do I need to grab the lock here as well (with spin_lock) ?

It is my understanding that I only need to use a spin lock in a softirq handler if sharing data with another softirq or hardirq. Is my understanding correct?

1 Answer 1

4

You must obtain a lock if you sharing data with any code, which can be executed on the same time. Kernel might execute both your softirq and your ioctl handler, so you must obtain a lock.

When you disable interrupts with either spin_lock_bh or spin_lock_irqsave, interrupts are disabled on current processor only. So, it's OK to handle interrupts on another one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.