public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
@ 2011-10-05 11:34 Ajaykumar Hotchandani
  2011-10-05 19:41 ` Rafael J. Wysocki
  2011-10-06 10:39 ` Stefano Stabellini
  0 siblings, 2 replies; 14+ messages in thread
From: Ajaykumar Hotchandani @ 2011-10-05 11:34 UTC (permalink / raw)
  To: Jesse Barnes, linux-pci, linux-kernel

During test of one IB card with guest VM, found that, msi is not initialized properly.

It turns out __write_msi_msg will do nothing if device current_state is not PCI_D0.
And, that pci device does not have pm_cap in guest VM.

There is an error in setting of power state to PCI_D0 in pci_enable_device(), but error is not returned for this.
Following is code flow:
pci_enable_device() -->  __pci_enable_device_flags() -->  do_pci_enable_device() -->  pci_set_power_state() -->  __pci_start_power_transition()
We have following condition inside __pci_start_power_transition():
         if (platform_pci_power_manageable(dev)) {
                 error = platform_pci_set_power_state(dev, state);
                 if (!error)
                         pci_update_current_state(dev, state);
         } else {
                 error = -ENODEV;
                 /* Fall back to PCI_D0 if native PM is not supported */
                 if (!dev->pm_cap)
                         dev->current_state = PCI_D0;
         }

Here, from platform_pci_set_power_state(), acpi_pci_set_power_state() is getting called and that is failing with ENODEV because of following condition:
         if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0",&tmp)))
                 return -ENODEV;

Because of that, pci_update_current_state() is not getting called.

With this patch, if device power state can not be set via platform_pci_set_power_state and that device does not have native pm support, then PCI device power state will be set to PCI_D0.

Signed-off-by: Ajaykumar Hotchandani<ajaykumar.hotchandani@oracle.com>
Signed-off-by: Yinghai Lu<yinghai.lu@oracle.com>
---
  drivers/pci/pci.c |    3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e9651f0..ca8c82d 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -664,6 +664,9 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
                 error = platform_pci_set_power_state(dev, state);
                 if (!error)
                         pci_update_current_state(dev, state);
+               /* Fall back to PCI_D0 if native PM is not supported */
+               else if (!dev->pm_cap)
+                       dev->current_state = PCI_D0;
         } else {
                 error = -ENODEV;
                 /* Fall back to PCI_D0 if native PM is not supported */
-- 
1.7.5.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-05 11:34 [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support Ajaykumar Hotchandani
@ 2011-10-05 19:41 ` Rafael J. Wysocki
  2011-10-06 16:10   ` Yinghai Lu
  2011-10-06 10:39 ` Stefano Stabellini
  1 sibling, 1 reply; 14+ messages in thread
From: Rafael J. Wysocki @ 2011-10-05 19:41 UTC (permalink / raw)
  To: Ajaykumar Hotchandani; +Cc: Jesse Barnes, linux-pci, linux-kernel

Hi,

On Wednesday, October 05, 2011, Ajaykumar Hotchandani wrote:
> During test of one IB card with guest VM, found that, msi is not initialized properly.
> 
> It turns out __write_msi_msg will do nothing if device current_state is not PCI_D0.
> And, that pci device does not have pm_cap in guest VM.
> 
> There is an error in setting of power state to PCI_D0 in pci_enable_device(), but error is not returned for this.
> Following is code flow:
> pci_enable_device() -->  __pci_enable_device_flags() -->  do_pci_enable_device() -->  pci_set_power_state() -->  __pci_start_power_transition()
> We have following condition inside __pci_start_power_transition():
>          if (platform_pci_power_manageable(dev)) {
>                  error = platform_pci_set_power_state(dev, state);
>                  if (!error)
>                          pci_update_current_state(dev, state);
>          } else {
>                  error = -ENODEV;
>                  /* Fall back to PCI_D0 if native PM is not supported */
>                  if (!dev->pm_cap)
>                          dev->current_state = PCI_D0;
>          }
> 
> Here, from platform_pci_set_power_state(), acpi_pci_set_power_state() is getting called and that is failing with ENODEV because of following condition:
>          if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0",&tmp)))
>                  return -ENODEV;
> 
> Because of that, pci_update_current_state() is not getting called.
> 
> With this patch, if device power state can not be set via platform_pci_set_power_state and that device does not have native pm support, then PCI device power state will be set to PCI_D0.
> 
> Signed-off-by: Ajaykumar Hotchandani<ajaykumar.hotchandani@oracle.com>
> Signed-off-by: Yinghai Lu<yinghai.lu@oracle.com>
> ---
>   drivers/pci/pci.c |    3 +++
>   1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index e9651f0..ca8c82d 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -664,6 +664,9 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
>                  error = platform_pci_set_power_state(dev, state);
>                  if (!error)
>                          pci_update_current_state(dev, state);
> +               /* Fall back to PCI_D0 if native PM is not supported */
> +               else if (!dev->pm_cap)
> +                       dev->current_state = PCI_D0;
>          } else {
>                  error = -ENODEV;
>                  /* Fall back to PCI_D0 if native PM is not supported */
> 

I have some vague memories that we tried that and it broke something.

How thoroughly has it been tested?

Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-05 11:34 [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support Ajaykumar Hotchandani
  2011-10-05 19:41 ` Rafael J. Wysocki
@ 2011-10-06 10:39 ` Stefano Stabellini
  2011-10-06 16:05   ` Yinghai Lu
  1 sibling, 1 reply; 14+ messages in thread
From: Stefano Stabellini @ 2011-10-06 10:39 UTC (permalink / raw)
  To: Ajaykumar Hotchandani
  Cc: Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org

On Wed, 5 Oct 2011, Ajaykumar Hotchandani wrote:
> During test of one IB card with guest VM, found that, msi is not initialized properly.
> 
> It turns out __write_msi_msg will do nothing if device current_state is not PCI_D0.
> And, that pci device does not have pm_cap in guest VM.
> 
> There is an error in setting of power state to PCI_D0 in pci_enable_device(), but error is not returned for this.
> Following is code flow:
> pci_enable_device() -->  __pci_enable_device_flags() -->  do_pci_enable_device() -->  pci_set_power_state() -->  __pci_start_power_transition()
> We have following condition inside __pci_start_power_transition():
>          if (platform_pci_power_manageable(dev)) {
>                  error = platform_pci_set_power_state(dev, state);
>                  if (!error)
>                          pci_update_current_state(dev, state);
>          } else {
>                  error = -ENODEV;
>                  /* Fall back to PCI_D0 if native PM is not supported */
>                  if (!dev->pm_cap)
>                          dev->current_state = PCI_D0;
>          }
> 
> Here, from platform_pci_set_power_state(), acpi_pci_set_power_state() is getting called and that is failing with ENODEV because of following condition:
>          if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0",&tmp)))
>                  return -ENODEV;
> 
> Because of that, pci_update_current_state() is not getting called.
> 
> With this patch, if device power state can not be set via platform_pci_set_power_state and that device does not have native pm support, then PCI device power state will be set to PCI_D0.
> 
> Signed-off-by: Ajaykumar Hotchandani<ajaykumar.hotchandani@oracle.com>
> Signed-off-by: Yinghai Lu<yinghai.lu@oracle.com>

I had the same issue and sent a patch a while ago to fix it, adding

current_state = PCI_D0 in acpiphp_glue.c:register_slot

it is strange that this does not work for you:

http://marc.info/?l=linux-kernel&m=129891002722845&w=2

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-06 10:39 ` Stefano Stabellini
@ 2011-10-06 16:05   ` Yinghai Lu
  2011-10-06 16:17     ` Stefano Stabellini
  0 siblings, 1 reply; 14+ messages in thread
From: Yinghai Lu @ 2011-10-06 16:05 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Ajaykumar Hotchandani, Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org

On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
<stefano.stabellini@eu.citrix.com> wrote:
>
> I had the same issue and sent a patch a while ago to fix it, adding
>
> current_state = PCI_D0 in acpiphp_glue.c:register_slot
>
> it is strange that this does not work for you:
>
> http://marc.info/?l=linux-kernel&m=129891002722845&w=2

So guest os has to load acpiphp instead of pciehp?

Yinghai

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-05 19:41 ` Rafael J. Wysocki
@ 2011-10-06 16:10   ` Yinghai Lu
  2011-10-06 17:20     ` Rafael J. Wysocki
  0 siblings, 1 reply; 14+ messages in thread
From: Yinghai Lu @ 2011-10-06 16:10 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ajaykumar Hotchandani, Jesse Barnes, linux-pci, linux-kernel

On Wed, Oct 5, 2011 at 12:41 PM, Rafael J. Wysocki <rjw@sisk.pl> wrote:
> Hi,
>>   drivers/pci/pci.c |    3 +++
>>   1 files changed, 3 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
>> index e9651f0..ca8c82d 100644
>> --- a/drivers/pci/pci.c
>> +++ b/drivers/pci/pci.c
>> @@ -664,6 +664,9 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
>>                  error = platform_pci_set_power_state(dev, state);
>>                  if (!error)
>>                          pci_update_current_state(dev, state);
>> +               /* Fall back to PCI_D0 if native PM is not supported */
>> +               else if (!dev->pm_cap)
>> +                       dev->current_state = PCI_D0;
>>          } else {
>>                  error = -ENODEV;
>>                  /* Fall back to PCI_D0 if native PM is not supported */
>>
>
> I have some vague memories that we tried that and it broke something.

Do have any hint for us to dig out the configuration for failing?

>
> How thoroughly has it been tested?

tested in setups with intel cpus from Nehalem.

Yinghai

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-06 16:05   ` Yinghai Lu
@ 2011-10-06 16:17     ` Stefano Stabellini
  2011-10-10 12:02       ` Ajaykumar Hotchandani
  0 siblings, 1 reply; 14+ messages in thread
From: Stefano Stabellini @ 2011-10-06 16:17 UTC (permalink / raw)
  To: Yinghai Lu
  Cc: Stefano Stabellini, Ajaykumar Hotchandani, Jesse Barnes,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

On Thu, 6 Oct 2011, Yinghai Lu wrote:
> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
> <stefano.stabellini@eu.citrix.com> wrote:
> >
> > I had the same issue and sent a patch a while ago to fix it, adding
> >
> > current_state = PCI_D0 in acpiphp_glue.c:register_slot
> >
> > it is strange that this does not work for you:
> >
> > http://marc.info/?l=linux-kernel&m=129891002722845&w=2
> 
> So guest os has to load acpiphp instead of pciehp?
 
maybe pciehp needs to make sure that current_state = D0 in
pciehp_enable_slot, like acpiphp does

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-06 16:10   ` Yinghai Lu
@ 2011-10-06 17:20     ` Rafael J. Wysocki
  0 siblings, 0 replies; 14+ messages in thread
From: Rafael J. Wysocki @ 2011-10-06 17:20 UTC (permalink / raw)
  To: Yinghai Lu; +Cc: Ajaykumar Hotchandani, Jesse Barnes, linux-pci, linux-kernel

On Thursday, October 06, 2011, Yinghai Lu wrote:
> On Wed, Oct 5, 2011 at 12:41 PM, Rafael J. Wysocki <rjw@sisk.pl> wrote:
> > Hi,
> >>   drivers/pci/pci.c |    3 +++
> >>   1 files changed, 3 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> >> index e9651f0..ca8c82d 100644
> >> --- a/drivers/pci/pci.c
> >> +++ b/drivers/pci/pci.c
> >> @@ -664,6 +664,9 @@ static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
> >>                  error = platform_pci_set_power_state(dev, state);
> >>                  if (!error)
> >>                          pci_update_current_state(dev, state);
> >> +               /* Fall back to PCI_D0 if native PM is not supported */
> >> +               else if (!dev->pm_cap)
> >> +                       dev->current_state = PCI_D0;
> >>          } else {
> >>                  error = -ENODEV;
> >>                  /* Fall back to PCI_D0 if native PM is not supported */
> >>
> >
> > I have some vague memories that we tried that and it broke something.
> 
> Do have any hint for us to dig out the configuration for failing?
> 
> >
> > How thoroughly has it been tested?
> 
> tested in setups with intel cpus from Nehalem.

Can you test it on older hardware too, please?

Rafael

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-06 16:17     ` Stefano Stabellini
@ 2011-10-10 12:02       ` Ajaykumar Hotchandani
  2011-10-13 14:30         ` Stefano Stabellini
  0 siblings, 1 reply; 14+ messages in thread
From: Ajaykumar Hotchandani @ 2011-10-10 12:02 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Yinghai Lu, Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org


On 10/06/2011 09:47 PM, Stefano Stabellini wrote:
> On Thu, 6 Oct 2011, Yinghai Lu wrote:
>> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
>> <stefano.stabellini@eu.citrix.com>  wrote:
>>> I had the same issue and sent a patch a while ago to fix it, adding
>>>
>>> current_state = PCI_D0 in acpiphp_glue.c:register_slot
>>>
>>> it is strange that this does not work for you:
>>>
>>> http://marc.info/?l=linux-kernel&m=129891002722845&w=2
>> So guest os has to load acpiphp instead of pciehp?
>
> maybe pciehp needs to make sure that current_state = D0 in
> pciehp_enable_slot, like acpiphp does
Here, acpi hotplugging is involved.
With your change in register_slot(), device will have proper power state when module is being loaded for the first time after booting.
However, while unload of pci module; following is in pci_device_remove():
         if (pci_dev->current_state == PCI_D0)
                 pci_dev->current_state = PCI_UNKNOWN;

So, device power state state will remain PCI_UNKNOWN while module is loaded again. Subsequently, MSI write will do nothing.

Thanks,
Ajay



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-10 12:02       ` Ajaykumar Hotchandani
@ 2011-10-13 14:30         ` Stefano Stabellini
  2011-10-18 13:52           ` Ajaykumar Hotchandani
  0 siblings, 1 reply; 14+ messages in thread
From: Stefano Stabellini @ 2011-10-13 14:30 UTC (permalink / raw)
  To: Ajaykumar Hotchandani
  Cc: Stefano Stabellini, Yinghai Lu, Jesse Barnes,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

On Mon, 10 Oct 2011, Ajaykumar Hotchandani wrote:
> On 10/06/2011 09:47 PM, Stefano Stabellini wrote:
> > On Thu, 6 Oct 2011, Yinghai Lu wrote:
> >> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
> >> <stefano.stabellini@eu.citrix.com>  wrote:
> >>> I had the same issue and sent a patch a while ago to fix it, adding
> >>>
> >>> current_state = PCI_D0 in acpiphp_glue.c:register_slot
> >>>
> >>> it is strange that this does not work for you:
> >>>
> >>> http://marc.info/?l=linux-kernel&m=129891002722845&w=2
> >> So guest os has to load acpiphp instead of pciehp?
> >
> > maybe pciehp needs to make sure that current_state = D0 in
> > pciehp_enable_slot, like acpiphp does
> Here, acpi hotplugging is involved.
> With your change in register_slot(), device will have proper power state when module is being loaded for the first time after booting.
> However, while unload of pci module; following is in pci_device_remove():
>          if (pci_dev->current_state == PCI_D0)
>                  pci_dev->current_state = PCI_UNKNOWN;
> 
> So, device power state state will remain PCI_UNKNOWN while module is loaded again. Subsequently, MSI write will do nothing.

Does this mean that this bug would actually trigger even with devices that
do support _EJ0 and power management?
Because acpi_pci_set_power_state won't set current_state to PCI_D0
because the "hotplug driver will take care of _PSx" (see
10b3dcae0f275e2546e55303d64ddbb58cec7599) but the hotplug driver is not
actually invoked when loading again a driver module of an existing pci
device (the example you mention above)?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-13 14:30         ` Stefano Stabellini
@ 2011-10-18 13:52           ` Ajaykumar Hotchandani
  2011-10-27 13:14             ` Stefano Stabellini
  0 siblings, 1 reply; 14+ messages in thread
From: Ajaykumar Hotchandani @ 2011-10-18 13:52 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Yinghai Lu, Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org



On 10/13/2011 08:00 PM, Stefano Stabellini wrote:
> On Mon, 10 Oct 2011, Ajaykumar Hotchandani wrote:
>> On 10/06/2011 09:47 PM, Stefano Stabellini wrote:
>>> On Thu, 6 Oct 2011, Yinghai Lu wrote:
>>>> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
>>>> <stefano.stabellini@eu.citrix.com>   wrote:
>>>>> I had the same issue and sent a patch a while ago to fix it, adding
>>>>>
>>>>> current_state = PCI_D0 in acpiphp_glue.c:register_slot
>>>>>
>>>>> it is strange that this does not work for you:
>>>>>
>>>>> http://marc.info/?l=linux-kernel&m=129891002722845&w=2
>>>> So guest os has to load acpiphp instead of pciehp?
>>> maybe pciehp needs to make sure that current_state = D0 in
>>> pciehp_enable_slot, like acpiphp does
>> Here, acpi hotplugging is involved.
>> With your change in register_slot(), device will have proper power state when module is being loaded for the first time after booting.
>> However, while unload of pci module; following is in pci_device_remove():
>>           if (pci_dev->current_state == PCI_D0)
>>                   pci_dev->current_state = PCI_UNKNOWN;
>>
>> So, device power state state will remain PCI_UNKNOWN while module is loaded again. Subsequently, MSI write will do nothing.
> Does this mean that this bug would actually trigger even with devices that
> do support _EJ0 and power management?
Nope. I don't have system to verify. But, for the scenario you mentioned 
(device is hot pluggable, acpi bus power manageable and device with 
pm_cap supported; if I understand it correctly), following is what I 
think should happen:
- Inside pci_platform_power_transition(), 
platform_pci_power_manageable() will be successful. However, 
platform_pci_set_power_state() will fail (as device supports EJ0) and 
subsequently pci_update_current_state() will not get called.
- So, current power state of device will not be read and power state of 
device will remain PCI_UNKNOWN.
- Now, pci_raw_set_power_state() will get called. Here, as current power 
state is PCI_UNKNOWN, pci_write_config_word() will be called with pmcsr 
value as 0. As, last two bits of pmcsr is 0, written power state of 
device will be PCI_D0 now. And subsequently, dev->current_state will be 
assigned as PCI_D0 (by using pci_read_config_word() ).
> Because acpi_pci_set_power_state won't set current_state to PCI_D0
> because the "hotplug driver will take care of _PSx" (see
> 10b3dcae0f275e2546e55303d64ddbb58cec7599) but the hotplug driver is not
> actually invoked when loading again a driver module of an existing pci
> device (the example you mention above)?
Can you please elaborate more on this?
acpi_bus_set_power() will update state of acpi_dev (ACPI_STATE_XX) and 
not pci_dev (PCI_XX).
And here, issue lies with current_state of pci_dev.

Thanks,
Ajay


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-18 13:52           ` Ajaykumar Hotchandani
@ 2011-10-27 13:14             ` Stefano Stabellini
  2011-10-27 14:34               ` Ajaykumar Hotchandani
  0 siblings, 1 reply; 14+ messages in thread
From: Stefano Stabellini @ 2011-10-27 13:14 UTC (permalink / raw)
  To: Ajaykumar Hotchandani
  Cc: Stefano Stabellini, Yinghai Lu, Jesse Barnes,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

On Tue, 18 Oct 2011, Ajaykumar Hotchandani wrote:
> On 10/13/2011 08:00 PM, Stefano Stabellini wrote:
> > On Mon, 10 Oct 2011, Ajaykumar Hotchandani wrote:
> >> On 10/06/2011 09:47 PM, Stefano Stabellini wrote:
> >>> On Thu, 6 Oct 2011, Yinghai Lu wrote:
> >>>> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
> >>>> <stefano.stabellini@eu.citrix.com>   wrote:
> >>>>> I had the same issue and sent a patch a while ago to fix it, adding
> >>>>>
> >>>>> current_state = PCI_D0 in acpiphp_glue.c:register_slot
> >>>>>
> >>>>> it is strange that this does not work for you:
> >>>>>
> >>>>> http://marc.info/?l=linux-kernel&m=129891002722845&w=2
> >>>> So guest os has to load acpiphp instead of pciehp?
> >>> maybe pciehp needs to make sure that current_state = D0 in
> >>> pciehp_enable_slot, like acpiphp does
> >> Here, acpi hotplugging is involved.
> >> With your change in register_slot(), device will have proper power state when module is being loaded for the first time after booting.
> >> However, while unload of pci module; following is in pci_device_remove():
> >>           if (pci_dev->current_state == PCI_D0)
> >>                   pci_dev->current_state = PCI_UNKNOWN;
> >>
> >> So, device power state state will remain PCI_UNKNOWN while module is loaded again. Subsequently, MSI write will do nothing.
> > Does this mean that this bug would actually trigger even with devices that
> > do support _EJ0 and power management?
> Nope. I don't have system to verify. But, for the scenario you mentioned 
> (device is hot pluggable, acpi bus power manageable and device with 
> pm_cap supported; if I understand it correctly), following is what I 
> think should happen:
> - Inside pci_platform_power_transition(), 
> platform_pci_power_manageable() will be successful. However, 
> platform_pci_set_power_state() will fail (as device supports EJ0) and 
> subsequently pci_update_current_state() will not get called.
> - So, current power state of device will not be read and power state of 
> device will remain PCI_UNKNOWN.
> - Now, pci_raw_set_power_state() will get called. Here, as current power 
> state is PCI_UNKNOWN, pci_write_config_word() will be called with pmcsr 
> value as 0. As, last two bits of pmcsr is 0, written power state of 
> device will be PCI_D0 now. And subsequently, dev->current_state will be 
> assigned as PCI_D0 (by using pci_read_config_word() ).

OK, I understand.


> > Because acpi_pci_set_power_state won't set current_state to PCI_D0
> > because the "hotplug driver will take care of _PSx" (see
> > 10b3dcae0f275e2546e55303d64ddbb58cec7599) but the hotplug driver is not
> > actually invoked when loading again a driver module of an existing pci
> > device (the example you mention above)?
> Can you please elaborate more on this?
> acpi_bus_set_power() will update state of acpi_dev (ACPI_STATE_XX) and 
> not pci_dev (PCI_XX).
> And here, issue lies with current_state of pci_dev.

I agree, I was merely stating again what the problem is.

BTW I am OK with your patch.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-27 13:14             ` Stefano Stabellini
@ 2011-10-27 14:34               ` Ajaykumar Hotchandani
  2011-10-27 15:01                 ` Stefano Stabellini
  0 siblings, 1 reply; 14+ messages in thread
From: Ajaykumar Hotchandani @ 2011-10-27 14:34 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Yinghai Lu, Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org



On 10/27/2011 06:44 PM, Stefano Stabellini wrote:
> On Tue, 18 Oct 2011, Ajaykumar Hotchandani wrote:
>> On 10/13/2011 08:00 PM, Stefano Stabellini wrote:
>>> On Mon, 10 Oct 2011, Ajaykumar Hotchandani wrote:
>>>> On 10/06/2011 09:47 PM, Stefano Stabellini wrote:
>>>>> On Thu, 6 Oct 2011, Yinghai Lu wrote:
>>>>>> On Thu, Oct 6, 2011 at 3:39 AM, Stefano Stabellini
>>>>>> <stefano.stabellini@eu.citrix.com>    wrote:
>>>>>>> I had the same issue and sent a patch a while ago to fix it, adding
>>>>>>>
>>>>>>> current_state = PCI_D0 in acpiphp_glue.c:register_slot
>>>>>>>
>>>>>>> it is strange that this does not work for you:
>>>>>>>
>>>>>>> http://marc.info/?l=linux-kernel&m=129891002722845&w=2
>>>>>> So guest os has to load acpiphp instead of pciehp?
>>>>> maybe pciehp needs to make sure that current_state = D0 in
>>>>> pciehp_enable_slot, like acpiphp does
>>>> Here, acpi hotplugging is involved.
>>>> With your change in register_slot(), device will have proper power state when module is being loaded for the first time after booting.
>>>> However, while unload of pci module; following is in pci_device_remove():
>>>>            if (pci_dev->current_state == PCI_D0)
>>>>                    pci_dev->current_state = PCI_UNKNOWN;
>>>>
>>>> So, device power state state will remain PCI_UNKNOWN while module is loaded again. Subsequently, MSI write will do nothing.
>>> Does this mean that this bug would actually trigger even with devices that
>>> do support _EJ0 and power management?
>> Nope. I don't have system to verify. But, for the scenario you mentioned
>> (device is hot pluggable, acpi bus power manageable and device with
>> pm_cap supported; if I understand it correctly), following is what I
>> think should happen:
>> - Inside pci_platform_power_transition(),
>> platform_pci_power_manageable() will be successful. However,
>> platform_pci_set_power_state() will fail (as device supports EJ0) and
>> subsequently pci_update_current_state() will not get called.
>> - So, current power state of device will not be read and power state of
>> device will remain PCI_UNKNOWN.
>> - Now, pci_raw_set_power_state() will get called. Here, as current power
>> state is PCI_UNKNOWN, pci_write_config_word() will be called with pmcsr
>> value as 0. As, last two bits of pmcsr is 0, written power state of
>> device will be PCI_D0 now. And subsequently, dev->current_state will be
>> assigned as PCI_D0 (by using pci_read_config_word() ).
> OK, I understand.
>
>
>>> Because acpi_pci_set_power_state won't set current_state to PCI_D0
>>> because the "hotplug driver will take care of _PSx" (see
>>> 10b3dcae0f275e2546e55303d64ddbb58cec7599) but the hotplug driver is not
>>> actually invoked when loading again a driver module of an existing pci
>>> device (the example you mention above)?
>> Can you please elaborate more on this?
>> acpi_bus_set_power() will update state of acpi_dev (ACPI_STATE_XX) and
>> not pci_dev (PCI_XX).
>> And here, issue lies with current_state of pci_dev.
> I agree, I was merely stating again what the problem is.
>
> BTW I am OK with your patch.

Should we revert 47e9037ac16637cd7f12b8790ea7ce6680e42168 (your changes 
in register_slot() )
I think, after this change, it's not needed. Or, am I missing some scenario?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-27 14:34               ` Ajaykumar Hotchandani
@ 2011-10-27 15:01                 ` Stefano Stabellini
  2011-10-28 12:06                   ` Ajaykumar Hotchandani
  0 siblings, 1 reply; 14+ messages in thread
From: Stefano Stabellini @ 2011-10-27 15:01 UTC (permalink / raw)
  To: Ajaykumar Hotchandani
  Cc: Stefano Stabellini, Yinghai Lu, Jesse Barnes,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org

On Thu, 27 Oct 2011, Ajaykumar Hotchandani wrote:
> > BTW I am OK with your patch.
> 
> Should we revert 47e9037ac16637cd7f12b8790ea7ce6680e42168 (your changes 
> in register_slot() )
> I think, after this change, it's not needed. Or, am I missing some scenario?
> 

I think you are right, 47e9037ac16637cd7f12b8790ea7ce6680e42168 is not
needed anymore, so I am OK with reverting it.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support
  2011-10-27 15:01                 ` Stefano Stabellini
@ 2011-10-28 12:06                   ` Ajaykumar Hotchandani
  0 siblings, 0 replies; 14+ messages in thread
From: Ajaykumar Hotchandani @ 2011-10-28 12:06 UTC (permalink / raw)
  To: Jesse Barnes, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
  Cc: Stefano Stabellini, Yinghai Lu



On 10/27/2011 08:31 PM, Stefano Stabellini wrote:
> On Thu, 27 Oct 2011, Ajaykumar Hotchandani wrote:
>>> BTW I am OK with your patch.
>> Should we revert 47e9037ac16637cd7f12b8790ea7ce6680e42168 (your changes
>> in register_slot() )
>> I think, after this change, it's not needed. Or, am I missing some scenario?
>>
> I think you are right, 47e9037ac16637cd7f12b8790ea7ce6680e42168 is not
> needed anymore, so I am OK with reverting it.

Thanks, following is updated patch.

[PATCH -v2] PCI: Set device power state to PCI_D0 for device without 
native PM support

During test of one IB card with guest VM, found that, msi is not 
initialized properly.

It turns out __write_msi_msg will do nothing if device current_state is 
not PCI_D0.
And, that pci device does not have pm_cap in guest VM.

There is an error in setting of power state to PCI_D0 in 
pci_enable_device(), but error is not returned for this.
Following is code flow:
pci_enable_device() -->  __pci_enable_device_flags() -->  
do_pci_enable_device() -->  pci_set_power_state() -->  
__pci_start_power_transition()
We have following condition inside __pci_start_power_transition():
         if (platform_pci_power_manageable(dev)) {
                 error = platform_pci_set_power_state(dev, state);
                 if (!error)
                         pci_update_current_state(dev, state);
         } else {
                 error = -ENODEV;
                 /* Fall back to PCI_D0 if native PM is not supported */
                 if (!dev->pm_cap)
                         dev->current_state = PCI_D0;
         }

Here, from platform_pci_set_power_state(), acpi_pci_set_power_state() is 
getting called and that is failing with ENODEV because of following 
condition:
         if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0",&tmp)))
                 return -ENODEV;

Because of that, pci_update_current_state() is not getting called.

With this patch, if device power state can not be set via 
platform_pci_set_power_state and that device does not have native pm 
support, then PCI device power state will be set to PCI_D0.

-v2: This also reverts 47e9037ac16637cd7f12b8790ea7ce6680e42168, as it's 
not needed after this change.

Signed-off-by: Ajaykumar Hotchandani <ajaykumar.hotchandani@oracle.com>
Signed-off-by: Yinghai Lu <yinghai.lu@oracle.com>
---
  drivers/pci/hotplug/acpiphp_glue.c |    1 -
  drivers/pci/pci.c                  |    3 +++
  2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_glue.c 
b/drivers/pci/hotplug/acpiphp_glue.c
index 2202857..11431c1 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -212,7 +212,6 @@ register_slot(acpi_handle handle, u32 lvl, void 
*context, void **rv)

         pdev = pci_get_slot(pbus, PCI_DEVFN(device, function));
         if (pdev) {
-               pdev->current_state = PCI_D0;
                 slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
                 pci_dev_put(pdev);
         }
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e9651f0..6866937 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -664,6 +664,9 @@ static int pci_platform_power_transition(struct 
pci_dev *dev, pci_power_t state)
                 error = platform_pci_set_power_state(dev, state);
                 if (!error)
                         pci_update_current_state(dev, state);
+               /* Fall back to PCI_D0 if native PM is not supported */
+               if (!dev->pm_cap)
+                       dev->current_state = PCI_D0;
         } else {
                 error = -ENODEV;
                 /* Fall back to PCI_D0 if native PM is not supported */
-- 
1.7.5.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-10-28 12:07 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-05 11:34 [PATCH] PCI: Set device power state to PCI_D0 for device without native PM support Ajaykumar Hotchandani
2011-10-05 19:41 ` Rafael J. Wysocki
2011-10-06 16:10   ` Yinghai Lu
2011-10-06 17:20     ` Rafael J. Wysocki
2011-10-06 10:39 ` Stefano Stabellini
2011-10-06 16:05   ` Yinghai Lu
2011-10-06 16:17     ` Stefano Stabellini
2011-10-10 12:02       ` Ajaykumar Hotchandani
2011-10-13 14:30         ` Stefano Stabellini
2011-10-18 13:52           ` Ajaykumar Hotchandani
2011-10-27 13:14             ` Stefano Stabellini
2011-10-27 14:34               ` Ajaykumar Hotchandani
2011-10-27 15:01                 ` Stefano Stabellini
2011-10-28 12:06                   ` Ajaykumar Hotchandani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox