문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top