All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -v2] PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0
@ 2013-10-10 12:41 Yijing Wang
  2013-10-10 12:45 ` Ben Hutchings
  0 siblings, 1 reply; 3+ messages in thread
From: Yijing Wang @ 2013-10-10 12:41 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Ben Hutchings, Yijing Wang, Hanjun Guo

Currently, if device power state != PCI_D0, we still initialize
device MSI/MSIX, but we won't write the MSI message to device
MSI/MSIX registers. It's weird, we don't configure MSI/MSIX
registers properly, but pci_enable_msi() or pci_enable_msix()
return success, and even these registers will never be updated later.
So I think it should return error if device power state != PCI_D0.

---

v1->v2: keep __write_msi_msg() function device power state statement,
	    because Ben Hutchings point out this function may be called
		during device in D3 state to set irq affinity. We should not
		touch that.

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
---
 drivers/pci/msi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index d5f90d6..604265c 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -831,7 +831,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
 	int status, maxvec;
 	u16 msgctl;
 
-	if (!dev->msi_cap)
+	if (!dev->msi_cap || dev->current_state != PCI_D0)
 		return -EINVAL;
 
 	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
@@ -862,7 +862,7 @@ int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
 	int ret, nvec;
 	u16 msgctl;
 
-	if (!dev->msi_cap)
+	if (!dev->msi_cap || dev->current_state != PCI_D0)
 		return -EINVAL;
 
 	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
@@ -955,7 +955,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
 	int status, nr_entries;
 	int i, j;
 
-	if (!entries || !dev->msix_cap)
+	if (!entries || !dev->msix_cap || dev->current_state != PCI_D0)
 		return -EINVAL;
 
 	status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
-- 
1.7.1



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

* Re: [PATCH -v2] PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0
  2013-10-10 12:41 [PATCH -v2] PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0 Yijing Wang
@ 2013-10-10 12:45 ` Ben Hutchings
  2013-10-10 12:53   ` Yijing Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Ben Hutchings @ 2013-10-10 12:45 UTC (permalink / raw)
  To: Yijing Wang; +Cc: Bjorn Helgaas, linux-pci, Hanjun Guo

[-- Attachment #1: Type: text/plain, Size: 2222 bytes --]

On Thu, 2013-10-10 at 20:41 +0800, Yijing Wang wrote:
> Currently, if device power state != PCI_D0, we still initialize
> device MSI/MSIX, but we won't write the MSI message to device
> MSI/MSIX registers. It's weird, we don't configure MSI/MSIX
> registers properly, but pci_enable_msi() or pci_enable_msix()
> return success, and even these registers will never be updated later.
> So I think it should return error if device power state != PCI_D0.
> 
> ---
> 
> v1->v2: keep __write_msi_msg() function device power state statement,
> 	    because Ben Hutchings point out this function may be called
> 		during device in D3 state to set irq affinity. We should not
> 		touch that.
> 
> Signed-off-by: Yijing Wang <wangyijing@huawei.com>

S-o-b needs to be above the first '---' but perhaps Bjorn can fix that
up before applying.

Acked-by: Ben Hutchings <bhutchings@solarflare.com>

> ---
>  drivers/pci/msi.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
> index d5f90d6..604265c 100644
> --- a/drivers/pci/msi.c
> +++ b/drivers/pci/msi.c
> @@ -831,7 +831,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
>  	int status, maxvec;
>  	u16 msgctl;
>  
> -	if (!dev->msi_cap)
> +	if (!dev->msi_cap || dev->current_state != PCI_D0)
>  		return -EINVAL;
>  
>  	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
> @@ -862,7 +862,7 @@ int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
>  	int ret, nvec;
>  	u16 msgctl;
>  
> -	if (!dev->msi_cap)
> +	if (!dev->msi_cap || dev->current_state != PCI_D0)
>  		return -EINVAL;
>  
>  	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
> @@ -955,7 +955,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
>  	int status, nr_entries;
>  	int i, j;
>  
> -	if (!entries || !dev->msix_cap)
> +	if (!entries || !dev->msix_cap || dev->current_state != PCI_D0)
>  		return -EINVAL;
>  
>  	status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);

-- 
Ben Hutchings
A free society is one where it is safe to be unpopular. - Adlai Stevenson

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

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

* Re: [PATCH -v2] PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0
  2013-10-10 12:45 ` Ben Hutchings
@ 2013-10-10 12:53   ` Yijing Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Yijing Wang @ 2013-10-10 12:53 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: Bjorn Helgaas, linux-pci, Hanjun Guo

On 2013/10/10 20:45, Ben Hutchings wrote:
> On Thu, 2013-10-10 at 20:41 +0800, Yijing Wang wrote:
>> Currently, if device power state != PCI_D0, we still initialize
>> device MSI/MSIX, but we won't write the MSI message to device
>> MSI/MSIX registers. It's weird, we don't configure MSI/MSIX
>> registers properly, but pci_enable_msi() or pci_enable_msix()
>> return success, and even these registers will never be updated later.
>> So I think it should return error if device power state != PCI_D0.
>>
>> ---
>>
>> v1->v2: keep __write_msi_msg() function device power state statement,
>> 	    because Ben Hutchings point out this function may be called
>> 		during device in D3 state to set irq affinity. We should not
>> 		touch that.
>>
>> Signed-off-by: Yijing Wang <wangyijing@huawei.com>
> 
> S-o-b needs to be above the first '---' but perhaps Bjorn can fix that
> up before applying.
> 
> Acked-by: Ben Hutchings <bhutchings@solarflare.com>


Thanks very much, I will update it, so Bjorn can apply it easily.

> 
>> ---
>>  drivers/pci/msi.c |    6 +++---
>>  1 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
>> index d5f90d6..604265c 100644
>> --- a/drivers/pci/msi.c
>> +++ b/drivers/pci/msi.c
>> @@ -831,7 +831,7 @@ int pci_enable_msi_block(struct pci_dev *dev, unsigned int nvec)
>>  	int status, maxvec;
>>  	u16 msgctl;
>>  
>> -	if (!dev->msi_cap)
>> +	if (!dev->msi_cap || dev->current_state != PCI_D0)
>>  		return -EINVAL;
>>  
>>  	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
>> @@ -862,7 +862,7 @@ int pci_enable_msi_block_auto(struct pci_dev *dev, unsigned int *maxvec)
>>  	int ret, nvec;
>>  	u16 msgctl;
>>  
>> -	if (!dev->msi_cap)
>> +	if (!dev->msi_cap || dev->current_state != PCI_D0)
>>  		return -EINVAL;
>>  
>>  	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &msgctl);
>> @@ -955,7 +955,7 @@ int pci_enable_msix(struct pci_dev *dev, struct msix_entry *entries, int nvec)
>>  	int status, nr_entries;
>>  	int i, j;
>>  
>> -	if (!entries || !dev->msix_cap)
>> +	if (!entries || !dev->msix_cap || dev->current_state != PCI_D0)
>>  		return -EINVAL;
>>  
>>  	status = pci_msi_check_device(dev, nvec, PCI_CAP_ID_MSIX);
> 


-- 
Thanks!
Yijing


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

end of thread, other threads:[~2013-10-10 12:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-10 12:41 [PATCH -v2] PCI: Avoid initialize MSI/MSIX if device power state != PCI_D0 Yijing Wang
2013-10-10 12:45 ` Ben Hutchings
2013-10-10 12:53   ` Yijing Wang

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.