From: jgunthorpe@obsidianresearch.com (Jason Gunthorpe)
Subject: [PATCH v5 0/4] New Microsemi PCI Switch Management Driver
Date: Wed, 1 Mar 2017 16:58:54 -0700 [thread overview]
Message-ID: <20170301235854.GF2820@obsidianresearch.com> (raw)
In-Reply-To: <b34d6872-35de-da6d-2d7f-8842642d3f21@deltatee.com>
On Wed, Mar 01, 2017@03:49:04PM -0700, Logan Gunthorpe wrote:
> Seems to me like an elegant solution would be to implement a 'cdev_kill'
> function which could kill all the processes using a cdev. Thus, during
> an unbind, a driver could call it and be sure that there are no users
> left and it can safely allow the devres unwind to continue. Then no
> difficult and racy 'alive' flags would be necessary and it would be much
> easier on drivers.
That could help, but this would mean cdev would have to insert a shim
to grab locks around the various file ops.
> > 3) A couple of drivers drivers/char/tpm doesn't seem to have any
> > protection at all and appears like they would continue to use io
> > operations even after the they may get unmapped because the char device
> > persists.
AFAIK TPM is correct and has been robustly tested now. We have a 'vtpm'
driver that agressively uses hot-unplug.
Firstly, TPM correctly tracks krefs on the 'chip', so the pointer is
always valid.
Next, anytime someone has a 'chip' pointer and wants to execute a TPM
operation they have to call tpm_try_get_ops and hold that lock for the
duration of their usage. Internally it does this:
down_read(&chip->ops_sem);
if (!chip->ops)
goto out_lock; // FAILURE
In the cdev fops case this will cause the fop to return EPIPE if it
fails. cdev holds this read side lock while it is running TPM commands
inside the driver.
This meshes with this code called by tpm_chip_unregister():
down_write(&chip->ops_sem);
chip->ops = NULL;
up_write(&chip->ops_sem);
tpm_chip_unregister uses this to provide a strong fence guarentee to
the driver. After tpm_chip_unregister return:
- Nothing is running in a TPM ops callback currently
- Nothing will ever call a TPM ops callback in future
This allows the TPM drivers to be trivial: call tpm_chip_unregister(),
kill the IRQ, and unmap the io resource, unload the module code.
TPM drivers cannot associate HW resources to the 'chip' struct device,
as it is unwound and devm triggered *during* tpm_chip_unregister and
does not enjoy the strong fence guarantee.
infiniband has a similar 'strong fence' unregister function. I think
it is best-practice for subsystem design to provide that because
drivers will never get it right on their own :(
Both infiniband and TPM have the 'detach' flavour of unplug where the
user is not forced to close their open cdevs. For simpler cases you
can just wait for all cdevs to close with a simple rwsem, much like
sysfs does already during device_del.
Jason
next prev parent reply other threads:[~2017-03-01 23:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-26 6:53 [PATCH v5 0/4] New Microsemi PCI Switch Management Driver Logan Gunthorpe
2017-02-26 6:53 ` [PATCH v5 1/4] MicroSemi Switchtec management interface driver Logan Gunthorpe
2017-02-26 6:53 ` [PATCH v5 2/4] switchtec: Add user interface documentation Logan Gunthorpe
2017-02-26 6:53 ` [PATCH v5 3/4] switchtec: Add sysfs attributes to the Switchtec driver Logan Gunthorpe
2017-02-26 6:53 ` [PATCH v5 4/4] switchtec: Add IOCTLs " Logan Gunthorpe
2017-02-28 15:09 ` [PATCH v5 0/4] New Microsemi PCI Switch Management Driver Bjorn Helgaas
2017-02-28 17:11 ` Logan Gunthorpe
2017-02-28 17:20 ` Greg Kroah-Hartman
2017-03-02 0:32 ` Bjorn Helgaas
2017-03-02 0:39 ` Logan Gunthorpe
2017-03-01 21:41 ` Bjorn Helgaas
2017-03-01 22:24 ` Logan Gunthorpe
2017-03-01 22:49 ` Logan Gunthorpe
2017-03-01 23:58 ` Jason Gunthorpe [this message]
2017-03-02 0:23 ` Logan Gunthorpe
2017-03-02 0:29 ` Logan Gunthorpe
2017-03-02 0:50 ` Jason Gunthorpe
2017-03-01 22:26 ` Keith Busch
2017-03-01 22:37 ` Logan Gunthorpe
2017-03-01 22:59 ` Keith Busch
2017-03-01 22:53 ` Logan Gunthorpe
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=20170301235854.GF2820@obsidianresearch.com \
--to=jgunthorpe@obsidianresearch.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox