NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/50296: gpio driver is marked MPSAFE but is not

>Number:         50296
>Category:       kern
>Synopsis:       gpio driver is marked MPSAFE but is not
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 03 22:10:08 +0000 2015
>Originator:     Andrew Doran
>Release:        Any you like after 2011
The NetBSD Project
NetBSD fab-500.blowback 7.0_RC3 NetBSD 7.0_RC3 (GENERIC.201508110747Z) amd64

The gpio driver has the D_MPSAFE flag, but there's very little in the
way of concurrency control.  Multiple threads in the driver at the same
time can be made to cause havoc.

Code inspection.
For now remove the D_MPSAFE flag.  Later, fix it properly.  At a guess:

The existing mutex at IPL_VM, seems inappropriate since (1) GPIO often
implies lots of waiting (DELAY) especially if there is a line protocol
to be followed (2) GPIO probably doesn't deal with interrupts.

I suggest loosely following the approach used for locking the audio 

The hardware driver can have multiple attachments, for example multiple
GPIO busses.  The gpio framework doesn't know about that.  So arrange
to have the hardware driver provide an IPL_NONE lock back to the gpio

gpio probably doesn't need to deal with hardware interrupts.  Exclusion 
of interrupts would be peculiar to the hardware device driver, so keep
that there.

If necessary introduce a longer term lock based on condition variables
if there is some need for it, for example memory allocation.  See for
example audio_enter() and audio_exit().

Home | Main Index | Thread Index | Old Index