All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Ira W. Snyder" <iws@ovro.caltech.edu>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] misc: add CARMA DATA-FPGA Access Driver
Date: Wed, 9 Feb 2011 16:39:35 -0800	[thread overview]
Message-ID: <20110210003935.GA6034@core.coreip.homeip.net> (raw)
In-Reply-To: <20110210001055.GB5303@ovro.caltech.edu>

On Wed, Feb 09, 2011 at 04:10:55PM -0800, Ira W. Snyder wrote:
> On Wed, Feb 09, 2011 at 03:42:31PM -0800, Dmitry Torokhov wrote:
> > On Wed, Feb 09, 2011 at 03:35:45PM -0800, Ira W. Snyder wrote:
> > > On Wed, Feb 09, 2011 at 10:27:40AM -0800, Dmitry Torokhov wrote:
> > > 
> > > [ snip stuff I've already fixed in the next version ]
> > > 
> > > > > 
> > > > > The requirement is that the device stay open during reconfiguration.
> > > > > This provides for that. Readers just block for as long as the device is
> > > > > not producing data.
> > > > 
> > > > OK, you still need to make sure you do not touch free/used buffer while
> > > > device is disabled. Also, you need to kick readers if you unbind the
> > > > driver, so maybe a new flag priv->exists should be introduced and
> > > > checked.
> > > > 
> > > 
> > > I don't understand what you mean by "kick readers if you unbind the
> > > driver". The kernel automatically increases the refcount on a module
> > > when a process is using the module. This shows up in the "Used by"
> > > column of lsmod's output.
> > > 
> > > The kernel will not let you rmmod a module with a non-zero refcount. You
> > > cannot get into the situation where you have rmmod'ed the module and a
> > > reader is still blocking in read()/poll().
> > 
> > However you can still unbind the driver from the device by writing into
> > driver's sysfs 'unbind' attribute.
> > 
> > See drivers/base/bus.c::driver_unbind().
> > 
> 
> I was completely unaware of that "feature". I hunch that many drivers
> are incapable of dealing with an unbind while they are still open.

Hmm, maybe older drivers... Anythig hotpluggable (USB, PCI, etc) should
be in a better shape because they expect to be yanked at any time.

> 
> Matter of fact, I don't see how this can EVER be safe. The driver core
> automatically calls the data_of_remove() routine while there are still
> blocked readers. This kfree()s the private data structure, which
> contains the suggested priv->exists flag. What happens if the memory
> allocator re-allocates that memory to a different driver before the
> reader process is woken up to check the priv->exists flag?
> 
> The only way to solve this is to count the number of open()s and
> close()s, and block the unbind until all users have close()d the device.
> 

Yes, you can kick readers and wait, or you can refcount that private
structure and have readers grab a reference when they open your device
and drop it in their fops->release() method. Your remove() should also
drop reference instead of doing kfree() outright.

Thanks.

-- 
Dmitry

  reply	other threads:[~2011-02-10  0:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 23:37 [PATCH RFCv5 0/2] CARMA Board Support Ira W. Snyder
2011-02-08 23:37 ` Ira W. Snyder
2011-02-08 23:37 ` [PATCH 1/2] misc: add CARMA DATA-FPGA Access Driver Ira W. Snyder
2011-02-08 23:37   ` Ira W. Snyder
2011-02-09  8:33   ` Dmitry Torokhov
2011-02-09 17:35     ` Ira W. Snyder
2011-02-09 18:27       ` Dmitry Torokhov
2011-02-09 23:35         ` Ira W. Snyder
2011-02-09 23:42           ` Dmitry Torokhov
2011-02-10  0:10             ` Ira W. Snyder
2011-02-10  0:39               ` Dmitry Torokhov [this message]
2011-02-10  9:02                 ` David Laight
2011-02-10  9:02                   ` David Laight
2011-02-08 23:37 ` [PATCH 2/2] misc: add CARMA DATA-FPGA Programmer support Ira W. Snyder
2011-02-08 23:37   ` Ira W. Snyder
  -- strict thread matches above, loose matches on Subject: below --
2011-02-07 23:23 [PATCH RFCv4 0/2] CARMA Board Support Ira W. Snyder
2011-02-07 23:23 ` [PATCH 1/2] misc: add CARMA DATA-FPGA Access Driver Ira W. Snyder
2011-02-08  7:33   ` Dmitry Torokhov
2011-02-08 17:20     ` Ira W. Snyder
2011-02-08 17:29       ` Dave Jones
2011-02-08 17:50       ` Dmitry Torokhov
2011-02-08 19:11         ` Ira W. Snyder
2011-02-08 19:33           ` Dmitry Torokhov
2011-02-09 16:30   ` David Laight
2011-02-09 16:30     ` David Laight
2011-02-09 17:03     ` Ira W. Snyder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110210003935.GA6034@core.coreip.homeip.net \
    --to=dmitry.torokhov@gmail.com \
    --cc=iws@ovro.caltech.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.