public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Kernel deferring driver 'close' call: workaround?
@ 2011-01-26 12:48 Evan Lavelle
  2011-01-26 13:17 ` Alan Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Evan Lavelle @ 2011-01-26 12:48 UTC (permalink / raw)
  To: LKML

I've written a PCIe driver for a specialist card, which can only have a 
single user ('open' returns EBUSY if the board is already open). A user 
has complained that they can't do this with the card:

1 - open()    // Ok
2 - close()
3 - open()    // fails

'strace' shows that the 'close' succeeds, but the driver debug output 
shows that the driver close/release (step 2) is not called before the 
next open (step 3), so the open fails.

I appreciate that the kernel may want to defer the driver 'close', even 
though the open count is only 1. However, I'm surprised that the kernel 
calls the driver open code at step (3) without first calling the 
deferred close from step (2).

Is this expected behaviour? If so, can anyone suggest a work-around, at 
either driver or user level?

Thanks.

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

* Re: Kernel deferring driver 'close' call: workaround?
  2011-01-26 12:48 Kernel deferring driver 'close' call: workaround? Evan Lavelle
@ 2011-01-26 13:17 ` Alan Cox
  2011-01-26 14:29   ` Evan Lavelle
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Cox @ 2011-01-26 13:17 UTC (permalink / raw)
  To: Evan Lavelle; +Cc: LKML

> 'strace' shows that the 'close' succeeds, but the driver debug output 
> shows that the driver close/release (step 2) is not called before the 
> next open (step 3), so the open fails.

I imagine the user has a bug in their app. The close method is called on
the final close of the handle. That means if for example you do something
like fork off a child process and forget to close the handle then it
won't actually close down until the final user closes it.

Alan

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

* Re: Kernel deferring driver 'close' call: workaround?
  2011-01-26 13:17 ` Alan Cox
@ 2011-01-26 14:29   ` Evan Lavelle
  2011-01-26 14:38     ` Alan Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Evan Lavelle @ 2011-01-26 14:29 UTC (permalink / raw)
  To: Alan Cox; +Cc: LKML

On 26/01/2011 13:17, Alan Cox wrote:

> I imagine the user has a bug in their app. The close method is called on
> the final close of the handle. That means if for example you do something
> like fork off a child process and forget to close the handle then it
> won't actually close down until the final user closes it.

That was my first reaction, but the strace output only shows an open and 
close of two shared libs, open and close for this board, some mmaps from 
the driver, and the basic brk/fstat/etc stuff. Unfortunately, I haven't 
got the app source, or even the board... :(

-Evan


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

* Re: Kernel deferring driver 'close' call: workaround?
  2011-01-26 14:29   ` Evan Lavelle
@ 2011-01-26 14:38     ` Alan Cox
  2011-01-26 15:29       ` Evan Lavelle
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Cox @ 2011-01-26 14:38 UTC (permalink / raw)
  To: Evan Lavelle; +Cc: LKML

On Wed, 26 Jan 2011 14:29:50 +0000
Evan Lavelle <sa212+lkml@cyconix.com> wrote:

> On 26/01/2011 13:17, Alan Cox wrote:
> 
> > I imagine the user has a bug in their app. The close method is called on
> > the final close of the handle. That means if for example you do something
> > like fork off a child process and forget to close the handle then it
> > won't actually close down until the final user closes it.
> 
> That was my first reaction, but the strace output only shows an open and 
> close of two shared libs, open and close for this board, some mmaps from 
> the driver, and the basic brk/fstat/etc stuff. Unfortunately, I haven't 
> got the app source, or even the board... :(

An mmap reference counts as an open .... it won't be released until the
mmaps are gone

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

* Re: Kernel deferring driver 'close' call: workaround?
  2011-01-26 14:38     ` Alan Cox
@ 2011-01-26 15:29       ` Evan Lavelle
  0 siblings, 0 replies; 5+ messages in thread
From: Evan Lavelle @ 2011-01-26 15:29 UTC (permalink / raw)
  To: Alan Cox; +Cc: LKML

On 26/01/2011 14:38, Alan Cox wrote:
> On Wed, 26 Jan 2011 14:29:50 +0000
> Evan Lavelle<sa212+lkml@cyconix.com>  wrote:
>
>> On 26/01/2011 13:17, Alan Cox wrote:
>>
>>> I imagine the user has a bug in their app. The close method is called on
>>> the final close of the handle. That means if for example you do something
>>> like fork off a child process and forget to close the handle then it
>>> won't actually close down until the final user closes it.
>>
>> That was my first reaction, but the strace output only shows an open and
>> close of two shared libs, open and close for this board, some mmaps from
>> the driver, and the basic brk/fstat/etc stuff. Unfortunately, I haven't
>> got the app source, or even the board... :(
>
> An mmap reference counts as an open .... it won't be released until the
> mmaps are gone

Excellent! Fixed - well done.

-Evan

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

end of thread, other threads:[~2011-01-26 15:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-26 12:48 Kernel deferring driver 'close' call: workaround? Evan Lavelle
2011-01-26 13:17 ` Alan Cox
2011-01-26 14:29   ` Evan Lavelle
2011-01-26 14:38     ` Alan Cox
2011-01-26 15:29       ` Evan Lavelle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox