mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sander Eikelenboom <linux@eikelenboom.it>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: David Vrabel <david.vrabel@citrix.com>,
	gregkh@linuxfoundation.org, <boris.ostrovsky@oracle.com>,
	<linux-kernel@vger.kernel.org>, <xen-devel@lists.xenproject.org>
Subject: Re: [Xen-devel] [PATCH v5] Fixes to Xen pciback for 3.17.
Date: Mon, 25 Aug 2014 19:18:45 +0200	[thread overview]
Message-ID: <373053698.20140825191845@eikelenboom.it> (raw)
In-Reply-To: <53E34102.8030002@citrix.com>


Hi Konrad,

Just in case you forgot this one .. a subtle ping (we are just in the low RC's) :-)

--
Sander

Thursday, August 7, 2014, 11:04:02 AM, you wrote:

> On 06/08/14 20:39, Konrad Rzeszutek Wilk wrote:
>> 
>> From 00a5b6e3c9ee2c2d605879bdaebc627fa640b024 Mon Sep 17 00:00:00 2001
>> From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
>> Date: Wed, 6 Aug 2014 16:21:32 -0400
>> Subject: [PATCH] xen/pciback: Restore configuration space when detaching from
>>  a guest.
>> 
>> The commit 9eea3f7695226f9af9992cebf8e98ac0ad78b277
>> "xen/pciback: Don't deadlock when unbinding." was using
>> the version of pci_reset_function which would lock the device lock.
>> That is no good as we can dead-lock. As such we swapped to using
>> the lock-less version and requiring that the callers
>> of 'pcistub_put_pci_dev' take the device lock. And as such
>> this bug got exposed.
>> 
>> Using the lock-less version is  OK, except that we tried to
>> use 'pci_restore_state' after the lock-less version of
>> __pci_reset_function_locked - which won't work as 'state_saved'
>> is set to false. Said 'state_saved' is a toggle boolean that
>> is to be used by the sequence of a) pci_save_state/pci_restore_state
>> or b) pci_load_and_free_saved_state/pci_restore_state. We don't
>> want to use a) as the guest might have messed up the PCI
>> configuration space and we want it to revert to the state
>> when the PCI device was binded to us. Therefore we pick
>> b) to restore the configuration space.
>> 
>> To still retain the PCI configuration space, we save it once
>> more and store it on our private copy to be restored when:
>>  - Device is unbinded from pciback
>>  - Device is detached from a guest.

> This should be folded into the original patch.

> [...]
>> --- a/drivers/xen/xen-pciback/pci_stub.c
>> +++ b/drivers/xen/xen-pciback/pci_stub.c
>> @@ -105,7 +105,7 @@ static void pcistub_device_release(struct kref *kref)
>>        */
>>       __pci_reset_function_locked(dev);
>>       if (pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state))

> I dislike testing for errors like this as it looks like it's testing for
> a boolean success.  Use

>    ret = pci_load_and_free_saved_state(...);
>    if (ret < 0)
>       ...

> And similarly, below.

>> -             dev_dbg(&dev->dev, "Could not reload PCI state\n");
>> +             dev_info(&dev->dev, "Could not reload PCI state\n");

> This should be dev_warn().

> pci_load_and_free_saved_state() won't fail because we know the state is
> valid (since we saved it from the device originally).  Warning and
> skipping the restore is fine here (and below).

>>       else
>>               pci_restore_state(dev);
>>  
>> @@ -257,6 +257,7 @@ void pcistub_put_pci_dev(struct pci_dev *dev)
>>  {
>>       struct pcistub_device *psdev, *found_psdev = NULL;
>>       unsigned long flags;
>> +     struct xen_pcibk_dev_data *dev_data;
>>  
>>       spin_lock_irqsave(&pcistub_devices_lock, flags);
>>  
>> @@ -279,9 +280,25 @@ void pcistub_put_pci_dev(struct pci_dev *dev)
>>        * (so it's ready for the next domain)
>>        */
>>       device_lock_assert(&dev->dev);
>> -     __pci_reset_function_locked(dev);
>> -     pci_restore_state(dev);
>> -
>> +     dev_data = pci_get_drvdata(dev);
>> +     if (pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state))

> This should be pci_load_saved_state() and then you can avoid the
> pci_save_state() below.

>> +             dev_info(&dev->dev, "Could not reload PCI state\n");

> dev_warn() also.

>> +     else {
>> +             __pci_reset_function_locked(dev);
>> +             /*
>> +              * The usual sequence is pci_save_state & pci_restore_state
>> +              * but the guest might have messed the configuration space up.
>> +              * Use the initial version (when device was binded to us).

> s/binded/bound/

>> +             pci_restore_state(dev);
>> +             /*
>> +              * The next steps are to reload the configuration for the
>> +              * next time we bind & unbind to a guest - or unload from
>> +              * pciback.
>> +              */
>> +             pci_save_state(dev);
>> +             dev_data->pci_saved_state = pci_store_saved_state(dev);

> You don't need this if you don't free the original state above.

>> +     }
>>       /* This disables the device. */
>>       xen_pcibk_reset_device(dev);

> David



  reply	other threads:[~2014-08-25 17:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-14 16:18 Konrad Rzeszutek Wilk
2014-07-14 16:18 ` [PATCH v5 1/6] xen-pciback: Document the various parameters and attributes in SysFS Konrad Rzeszutek Wilk
2014-07-28 13:04   ` David Vrabel
2014-07-28 14:56     ` Greg KH
2014-08-01 14:59       ` [Xen-devel] " David Vrabel
2014-07-14 16:18 ` [PATCH v5 2/6] xen/pciback: Don't deadlock when unbinding Konrad Rzeszutek Wilk
2014-07-28 13:06   ` David Vrabel
2014-08-04 18:42     ` Konrad Rzeszutek Wilk
2014-08-05  9:27       ` [Xen-devel] " David Vrabel
2014-07-14 16:18 ` [PATCH v5 3/6] driver core: Provide an wrapper around the mutex to do lockdep warnings Konrad Rzeszutek Wilk
2014-07-14 17:39   ` Greg KH
2014-07-14 16:18 ` [PATCH v5 4/6] xen/pciback: Include the domain id if removing the device whilst still in use Konrad Rzeszutek Wilk
2014-07-14 16:18 ` [PATCH v5 5/6] xen/pciback: Print out the domain owning the device Konrad Rzeszutek Wilk
2014-07-14 16:18 ` [PATCH v5 6/6] xen/pciback: Remove tons of dereferences Konrad Rzeszutek Wilk
2014-07-14 17:40 ` [PATCH v5] Fixes to Xen pciback for 3.17 Greg KH
2014-07-14 17:39   ` Konrad Rzeszutek Wilk
2014-08-01 15:30 ` David Vrabel
2014-08-04 18:43   ` Konrad Rzeszutek Wilk
2014-08-05  8:44     ` [Xen-devel] " Sander Eikelenboom
2014-08-05  9:31       ` David Vrabel
2014-08-05  9:44         ` Sander Eikelenboom
2014-08-05 13:49           ` Konrad Rzeszutek Wilk
2014-08-05 14:04             ` Sander Eikelenboom
2014-08-06 18:59               ` Sander Eikelenboom
2014-08-06 19:18                 ` Konrad Rzeszutek Wilk
2014-08-06 19:25                   ` Sander Eikelenboom
2014-08-06 19:39                     ` Konrad Rzeszutek Wilk
2014-08-06 19:47                       ` Sander Eikelenboom
2014-08-06 20:09                         ` Konrad Rzeszutek Wilk
2014-08-06 20:17                           ` Sander Eikelenboom
2014-08-06 22:08                             ` Sander Eikelenboom
2014-08-07  9:04                       ` David Vrabel
2014-08-25 17:18                         ` Sander Eikelenboom [this message]
2014-08-05 14:33             ` Sander Eikelenboom

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=373053698.20140825191845@eikelenboom.it \
    --to=linux@eikelenboom.it \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xenproject.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

all inboxes | Powered by JetHome®