kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] Inform users about busy device assignment attempt
Date: Wed, 9 Dec 2009 19:40:30 +0000	[thread overview]
Message-ID: <20091209194030.GD13487@redhat.com> (raw)
In-Reply-To: <4B1FF7FD.5080407@suse.de>

On Wed, Dec 09, 2009 at 08:18:21PM +0100, Alexander Graf wrote:
> Daniel P. Berrange wrote:
> >
> > Unconditionally telling people to run rmmod is a pretty dangerous thing
> > todo. If they typod and gave the PCI addr of their disk controller instead
> > of the NIC, they'll be less than happy at the results of our recommended
> > command to "fix" the error. Likewise if they have multiple devices using
> > the same driver & just want to assign one of them. I think it is safer to
> > just have the first bit of your proposed error message
> >
> >   "The device 04:00.0 is in use by the kernel driver 'igb'."
> >
> >
> > NB 'rmmod' is not the ideal approach for PCI assignment. It is better
> > to explicitly re-bind the device to 'pcistub' because that ensures that
> > no other driver will ever be able to reclaim the device.
> >   
> 
> Oh - mind to get into detail there? It'd be great if we could tell users
> an even better way to unbind their device from the driver than rmmod :)

The direct low level sysfs way involves the following steps

  // Tell pci-stub to accept a particular vendor+product ID binding
  # echo "8086 27cb" > /sys/bus/pci/drivers/pci-stub/new_id

  // Remove device from existing PCI driver
  # echo "00:1d.3" > /sys/bus/pci/drivers/e1000/unbind

  // Add device to pci-stub PCI driver
  # echo "00:1d.3" > /sys/bus/pci/drivers/pci-stub/bind

  // Tell pci-stub to stop accepting a vendor+product ID binding
  # echo "8086 27cb" > /sys/bus/pci/drivers/pci-stub/remove_id

The reason for  that last step is that if you have multiple devices of
the same vendor+product, you don't want a later hotplug event to bind
the new device to pci-stub too !


At a higher level this is also possible with libvirt's nodedev-XXX commands

   // Find the name of device you want to detach
   # virsh nodedev-list --tree
    computer
     |
     +- net_computer_loopback
     +- pci_8086_2448
     |   |
     |   +- pci_104c_ac56
     |     
     +- pci_8086_27a0
     +- pci_8086_27a1
     |   |
     ...snip rest of info...

   // Check it really is the device you want to detach
   # virsh nodedev-dumpxml pci_8086_27a1
   <device>
     <name>pci_8086_27a1</name>
     <parent>computer</parent>
     <driver>
       <name>pcieport-driver</name>
     </driver>
     <capability type='pci'>
       <domain>0</domain>
       <bus>0</bus>
       <slot>1</slot>
       <function>0</function>
       <product id='0x27a1'>Mobile 945GM/PM/GMS, 943/940GML and 945GT Express PCI Express Root Port</product>
       <vendor id='0x8086'>Intel Corporation</vendor>
     </capability>
   </device>

   // Detach it from your host OS 
   # virsh nodedev-dettach pci_8086_27a1
   Device pci_8086_27a1 dettached

That nodedev-dettach command, does all 4 of the sysfs commands in one
go. Those nodedev-XXX commands are all usable, even if you're not using
libvirt for actually running guests. If you are using libvirt for running
the guests, then you don't even need those steps. Simply set the attribute
'managed=yes' for the <hostdev> in the guest config, and libvirt does the
device detach automatically & reattachs when shutting down the guest

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

  reply	other threads:[~2009-12-09 19:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09 18:04 [PATCH] Inform users about busy device assignment attempt Alexander Graf
2009-12-09 18:19 ` Daniel P. Berrange
2009-12-09 19:18   ` Alexander Graf
2009-12-09 19:40     ` Daniel P. Berrange [this message]
2009-12-09 19:44       ` Alexander Graf
2009-12-09 20:14         ` Daniel P. Berrange
2009-12-09 20:15           ` Alexander Graf
  -- strict thread matches above, loose matches on Subject: below --
2009-12-09 20:13 Alexander Graf
2009-12-10 23:06 [PATCH] Enable non page boundary BAR device assignment Alexander Graf
2009-12-10 23:06 ` [PATCH] Inform users about busy device assignment attempt Alexander Graf
2009-12-11 11:38   ` Michael S. Tsirkin
2009-12-15 15:18     ` Alexander Graf
2009-12-15 15:18       ` Michael S. Tsirkin

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=20091209194030.GD13487@redhat.com \
    --to=berrange@redhat.com \
    --cc=agraf@suse.de \
    --cc=kvm@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).