From: Hannes Reinecke <hare@suse.de>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: kvm-devel <kvm@vger.kernel.org>,
Linux Virtualization <virtualization@lists.linux-foundation.org>,
Alexander Graf <agraf@suse.de>
Subject: Re: PCI device not properly reset after VFIO
Date: Thu, 18 Oct 2012 17:06:32 +0200 [thread overview]
Message-ID: <50801AF8.7040305@suse.de> (raw)
In-Reply-To: <1350571230.2112.344.camel@bling.home>
On 10/18/2012 04:40 PM, Alex Williamson wrote:
> Hi Hannes,
>
> Thanks for testing vfio
>
> On Thu, 2012-10-18 at 08:47 +0200, Hannes Reinecke wrote:
>> Hi Alex,
>>
>> I've been playing around with VFIO and megasas (of course).
>> What I did now was switching between VFIO and 'normal' operation, ie
>> emulated access.
>>
>> megasas is happily running under VFIO, but when I do an emergency
>> stop like killing the Qemu session the PCI device is not properly reset.
>> IE when I load 'megaraid_sas' after unbinding the vfio_pci module
>> the driver cannot initialize the card and waits forever for the
>> firmware state to change.
>>
>> I need to do a proper pci reset via
>> echo 1 > /sys/bus/pci/device/XXXX/reset
>> to get it into a working state again.
>>
>> Looking at vfio_pci_disable() pci reset is called before the config
>> state and BARs are restored.
>> Seeing that vfio_pci_enable() calls pci reset right at the start,
>> too, before modifying anything I do wonder whether the pci reset is
>> at the correct location for disable.
>>
>> I would have expected to call pci reset in vfio_pci_disable()
>> _after_ we have restored the configuration, to ensure a sane state
>> after reset.
>> And, as experience show, we do need to call it there.
>>
>> So what is the rationale for the pci reset?
>> Can we move it to the end of vfio_pci_disable() or do we need to
>> call pci reset twice?
>
> I believe the rationale was that by resetting the device before we
> restore the state we stop anything that the device was doing. Restoring
> the saved state on a running device seems like it could cause problems,
> so you may be right and we actually need to do reset, load, restore,
> reset. Does adding another call to pci_reset_function in the
> pci_restore_state (as below) solve the problem? Traditional KVM device
> assignment has a nearly identical path, does it have this same bug?
It's actually the first time I've been able to test this (the
hardware is a bit tricky to setup ...), so I cannot tell (yet)
if KVM exhibited the same thing.
> Thanks,
>
> Alex
>
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 6c11994..d07a45c 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -107,9 +107,10 @@ static void vfio_pci_disable(struct vfio_pci_device *vdev)
> pci_reset_function(vdev->pdev);
>
> if (pci_load_and_free_saved_state(vdev->pdev,
> - &vdev->pci_saved_state) == 0)
> + &vdev->pci_saved_state) == 0) {
> pci_restore_state(vdev->pdev);
> - else
> + pci_reset_function(vdev->pdev);
> + } else
> pr_info("%s: Couldn't reload %s saved state\n",
> __func__, dev_name(&vdev->pdev->dev));
>
>
>
I would have called reset after unmapping the BARs; the HBA I'm
working with does need to access the BARs, so the content of them
might be relevant, too.
But then I'm not really a PCI expert.
Maybe we should ask Tony Luck or Bjorn Helgaas.
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@suse.de +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
next prev parent reply other threads:[~2012-10-18 15:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-18 6:47 PCI device not properly reset after VFIO Hannes Reinecke
2012-10-18 14:40 ` Alex Williamson
2012-10-18 14:40 ` Alex Williamson
2012-10-18 15:06 ` Hannes Reinecke [this message]
2012-10-18 20:40 ` Alex Williamson
2012-10-18 20:40 ` Alex Williamson
2012-10-18 15:06 ` Hannes Reinecke
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=50801AF8.7040305@suse.de \
--to=hare@suse.de \
--cc=agraf@suse.de \
--cc=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.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.