From: Alexander Graf <agraf@suse.de>
To: Chris Wright <chrisw@redhat.com>
Cc: kvm list <kvm@vger.kernel.org>, Gleb Natapov <gleb@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Muli Ben-Yehuda <muli@il.ibm.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Subject: Re: [PATCH 3/3] Inform users about busy device assignment attempt
Date: Tue, 15 Dec 2009 22:10:47 +0100 [thread overview]
Message-ID: <4B27FB57.2050606@suse.de> (raw)
In-Reply-To: <20091215202852.GH15084@x200.localdomain>
Chris Wright wrote:
> * Alexander Graf (agraf@suse.de) wrote:
>
>> +static void assign_failed_examine(AssignedDevice *dev)
>> +{
>> + char name[PATH_MAX], dir[PATH_MAX], driver[PATH_MAX] = {}, *ns;
>> + uint16_t vendor_id, device_id;
>> + int r;
>> +
>> + /* XXX implement multidomain */
>> + sprintf(dir, "/sys/bus/pci/devices/0000:%02x:%02x.%01x/",
>> + dev->host.bus, dev->host.dev, dev->host.func);
>> +
>> + sprintf(name, "%sdriver", dir);
>> +
>> + r = readlink(name, driver, sizeof(driver));
>> + if ((r <= 0) || !(ns = strrchr(driver, '/')) || r >= sizeof(driver)) {
>>
>
> While the symlink should never be that long, I think you want to
> check bytes stored in driver before strrchr, else you may walk off a
> non-NULL-terminated buffer.
>
Hum, yeah. I'm starting to understand why the shell was invented.
>
>> + goto fail;
>> + }
>> +
>> + ns++;
>> +
>> + if (get_real_vendor_id(dir, &vendor_id) ||
>> + get_real_device_id(dir, &device_id)) {
>> + goto fail;
>> + }
>> +
>> + fprintf(stderr, "*** The driver '%s' is occupying your device "
>> + "%02x:%02x.%x.\n",
>> + ns, dev->host.bus, dev->host.dev, dev->host.func);
>> + fprintf(stderr, "***\n");
>> + fprintf(stderr, "*** You can try the following commands to free it:\n");
>> + fprintf(stderr, "***\n");
>> + fprintf(stderr, "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub/"
>> + "new_id\n", vendor_id, device_id);
>> + fprintf(stderr, "*** $ echo \"0000:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
>> + "%s/unbind\n",
>> + dev->host.bus, dev->host.dev, dev->host.func, ns);
>> + fprintf(stderr, "*** $ echo \"0000:%02x:%02x.%x\" > /sys/bus/pci/drivers/"
>> + "pci-stub/bind\n",
>> + dev->host.bus, dev->host.dev, dev->host.func);
>> + fprintf(stderr, "*** $ echo \"%04x %04x\" > /sys/bus/pci/drivers/pci-stub"
>> + "/remove_id\n", vendor_id, device_id);
>> + fprintf(stderr, "***\n");
>> +
>> + return;
>> +
>> +fail:
>> + fprintf(stderr, "Couldn't find out why.\n");
>> +}
>> +
>> static int assign_device(AssignedDevice *dev)
>> {
>> struct kvm_assigned_pci_dev assigned_dev_data;
>> @@ -781,9 +829,12 @@ static int assign_device(AssignedDevice *dev)
>> #endif
>>
>> r = kvm_assign_pci_device(kvm_context, &assigned_dev_data);
>> - if (r < 0)
>> - fprintf(stderr, "Failed to assign device \"%s\" : %s\n",
>> + if (r < 0) {
>> + fprintf(stderr, "Failed to assign device \"%s\" : %s\n",
>> dev->dev.qdev.id, strerror(-r));
>> +
>> + assign_failed_examine(dev);
>>
>
> Only really catching the EBUSY case, maybe test for explicitly?
>
What others do we have?
next prev parent reply other threads:[~2009-12-15 21:10 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-15 18:30 [PATCH 0/3] Device Assignment fixes Alexander Graf
2009-12-15 18:30 ` [PATCH 1/3] Enable non page boundary BAR device assignment Alexander Graf
2009-12-15 18:38 ` Michael S. Tsirkin
2009-12-15 18:47 ` Alexander Graf
2009-12-15 18:50 ` Michael S. Tsirkin
2009-12-15 19:04 ` Alexander Graf
2009-12-15 19:50 ` Chris Wright
2009-12-15 21:12 ` Michael S. Tsirkin
2009-12-16 5:44 ` Chris Wright
2009-12-15 21:04 ` Michael S. Tsirkin
2009-12-15 21:11 ` Alexander Graf
2009-12-16 5:47 ` Chris Wright
2009-12-16 10:41 ` Michael S. Tsirkin
2009-12-15 18:30 ` [PATCH 2/3] Split off sysfs id retrieval Alexander Graf
2009-12-15 18:39 ` Michael S. Tsirkin
2009-12-15 18:54 ` Alexander Graf
2009-12-15 21:05 ` Michael S. Tsirkin
2009-12-15 19:57 ` Chris Wright
2009-12-15 18:30 ` [PATCH 3/3] Inform users about busy device assignment attempt Alexander Graf
2009-12-15 18:41 ` Michael S. Tsirkin
2009-12-15 20:28 ` Chris Wright
2009-12-15 21:09 ` Michael S. Tsirkin
2009-12-15 21:10 ` Alexander Graf [this message]
2009-12-15 23:13 ` Chris Wright
-- strict thread matches above, loose matches on Subject: below --
2009-12-17 15:04 [PATCH 0/3] Device Assignment fixes Alexander Graf
2009-12-17 15:04 ` [PATCH 3/3] Inform users about busy device assignment attempt Alexander Graf
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=4B27FB57.2050606@suse.de \
--to=agraf@suse.de \
--cc=berrange@redhat.com \
--cc=chrisw@redhat.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=muli@il.ibm.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