* [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
@ 2023-08-22 11:55 Feiyang Chen
2023-08-22 13:06 ` Anders Roxell
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Feiyang Chen @ 2023-08-22 11:55 UTC (permalink / raw)
To: bhelgaas, rafael.j.wysocki
Cc: Feiyang Chen, mika.westerberg, helgaas, anders.roxell, linux-pci,
linux-pm, guyinggang, siyanteng, chenhuacai, loongson-kernel,
chris.chenfeiyang
When the current state is already PCI_D0, pci_power_up() will return
0 even though dev->pm_cap is not set. In that case, we should not
read the PCI_PM_CTRL register in pci_set_full_power_state().
Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
---
drivers/pci/pci.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 60230da957e0..7e90ab7b47a1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev)
else
dev->current_state = state;
- if (state == PCI_D0)
- return 0;
-
return -EIO;
}
@@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev)
int ret;
ret = pci_power_up(dev);
- if (ret < 0)
+ if (ret < 0) {
+ if (dev->current_state == PCI_D0)
+ return 0;
+
return ret;
+ }
pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
--
2.39.3
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 11:55 [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available Feiyang Chen
@ 2023-08-22 13:06 ` Anders Roxell
2023-08-22 13:17 ` Ilpo Järvinen
2023-08-22 13:24 ` Ilpo Järvinen
2023-08-22 18:54 ` Rafael J. Wysocki
2 siblings, 1 reply; 10+ messages in thread
From: Anders Roxell @ 2023-08-22 13:06 UTC (permalink / raw)
To: Feiyang Chen
Cc: bhelgaas, rafael.j.wysocki, mika.westerberg, helgaas, linux-pci,
linux-pm, guyinggang, siyanteng, chenhuacai, loongson-kernel,
chris.chenfeiyang
On Tue, 22 Aug 2023 at 13:55, Feiyang Chen <chenfeiyang@loongson.cn> wrote:
>
> When the current state is already PCI_D0, pci_power_up() will return
> 0 even though dev->pm_cap is not set. In that case, we should not
> read the PCI_PM_CTRL register in pci_set_full_power_state().
>
> Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
> Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
> ---
> drivers/pci/pci.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 60230da957e0..7e90ab7b47a1 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev)
> else
> dev->current_state = state;
>
> - if (state == PCI_D0)
> - return 0;
> -
> return -EIO;
> }
>
> @@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev)
> int ret;
>
> ret = pci_power_up(dev);
> - if (ret < 0)
> + if (ret < 0) {
> + if (dev->current_state == PCI_D0)
> + return 0;
> +
> return ret;
> + }
>
> pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
In fuction pci_power_up() there's another if-statement
if (state == PCI_D0)
goto end;
That also will return 0 if need_restore isn't true.
What will happen then?
Would this work?
ret = pci_power_up(dev);
- if (ret < 0)
+ if (ret <= 0)
return ret;
Cheers,
Anders
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 13:06 ` Anders Roxell
@ 2023-08-22 13:17 ` Ilpo Järvinen
0 siblings, 0 replies; 10+ messages in thread
From: Ilpo Järvinen @ 2023-08-22 13:17 UTC (permalink / raw)
To: Anders Roxell
Cc: Feiyang Chen, bhelgaas, rafael.j.wysocki, mika.westerberg,
helgaas, linux-pci, linux-pm, guyinggang, siyanteng, chenhuacai,
loongson-kernel, chris.chenfeiyang
On Tue, 22 Aug 2023, Anders Roxell wrote:
> On Tue, 22 Aug 2023 at 13:55, Feiyang Chen <chenfeiyang@loongson.cn> wrote:
> >
> > When the current state is already PCI_D0, pci_power_up() will return
> > 0 even though dev->pm_cap is not set. In that case, we should not
> > read the PCI_PM_CTRL register in pci_set_full_power_state().
> >
> > Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
> > Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
> > ---
> > drivers/pci/pci.c | 9 +++++----
> > 1 file changed, 5 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index 60230da957e0..7e90ab7b47a1 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev)
> > else
> > dev->current_state = state;
> >
> > - if (state == PCI_D0)
> > - return 0;
> > -
> > return -EIO;
> > }
> >
> > @@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev)
> > int ret;
> >
> > ret = pci_power_up(dev);
> > - if (ret < 0)
> > + if (ret < 0) {
> > + if (dev->current_state == PCI_D0)
> > + return 0;
> > +
> > return ret;
> > + }
> >
> > pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> > dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
>
> In fuction pci_power_up() there's another if-statement
> if (state == PCI_D0)
> goto end;
>
> That also will return 0 if need_restore isn't true.
> What will happen then?
That case is only after pci_power_up() has returned because of
!dev->pm_cap. As such, it looks unrelated to the case this patch is fixing
which is the read from PCI_PM_CTRL when dev->pm_cap is not there.
> Would this work?
>
> ret = pci_power_up(dev);
> - if (ret < 0)
> + if (ret <= 0)
> return ret;
--
i.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 11:55 [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available Feiyang Chen
2023-08-22 13:06 ` Anders Roxell
@ 2023-08-22 13:24 ` Ilpo Järvinen
2023-08-22 14:24 ` Rafael J. Wysocki
2023-08-22 18:54 ` Rafael J. Wysocki
2 siblings, 1 reply; 10+ messages in thread
From: Ilpo Järvinen @ 2023-08-22 13:24 UTC (permalink / raw)
To: Feiyang Chen
Cc: bhelgaas, rafael.j.wysocki, mika.westerberg, helgaas,
anders.roxell, linux-pci, linux-pm, guyinggang, siyanteng,
chenhuacai, loongson-kernel, chris.chenfeiyang
On Tue, 22 Aug 2023, Feiyang Chen wrote:
> When the current state is already PCI_D0, pci_power_up() will return
> 0 even though dev->pm_cap is not set. In that case, we should not
> read the PCI_PM_CTRL register in pci_set_full_power_state().
IMHO, this is a bit misleading because after this patch, pci_power_up()
returns always an error if dev->pm_cap is not set.
--
i.
> Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
> Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
> ---
> drivers/pci/pci.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 60230da957e0..7e90ab7b47a1 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev)
> else
> dev->current_state = state;
>
> - if (state == PCI_D0)
> - return 0;
> -
> return -EIO;
> }
>
> @@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev)
> int ret;
>
> ret = pci_power_up(dev);
> - if (ret < 0)
> + if (ret < 0) {
> + if (dev->current_state == PCI_D0)
> + return 0;
> +
> return ret;
> + }
>
> pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 13:24 ` Ilpo Järvinen
@ 2023-08-22 14:24 ` Rafael J. Wysocki
2023-08-23 7:28 ` Ilpo Järvinen
0 siblings, 1 reply; 10+ messages in thread
From: Rafael J. Wysocki @ 2023-08-22 14:24 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Feiyang Chen, bhelgaas, rafael.j.wysocki, mika.westerberg,
helgaas, anders.roxell, linux-pci, linux-pm, guyinggang,
siyanteng, chenhuacai, loongson-kernel, chris.chenfeiyang
On Tue, Aug 22, 2023 at 3:24 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> On Tue, 22 Aug 2023, Feiyang Chen wrote:
>
> > When the current state is already PCI_D0, pci_power_up() will return
> > 0 even though dev->pm_cap is not set. In that case, we should not
> > read the PCI_PM_CTRL register in pci_set_full_power_state().
>
> IMHO, this is a bit misleading because after this patch, pci_power_up()
> returns always an error if dev->pm_cap is not set.
Yes, it does, but it has 2 callers only and the other one ignores the
return value, so this only matters here.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 11:55 [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available Feiyang Chen
2023-08-22 13:06 ` Anders Roxell
2023-08-22 13:24 ` Ilpo Järvinen
@ 2023-08-22 18:54 ` Rafael J. Wysocki
2 siblings, 0 replies; 10+ messages in thread
From: Rafael J. Wysocki @ 2023-08-22 18:54 UTC (permalink / raw)
To: Feiyang Chen
Cc: bhelgaas, rafael.j.wysocki, mika.westerberg, helgaas,
anders.roxell, linux-pci, linux-pm, guyinggang, siyanteng,
chenhuacai, loongson-kernel, chris.chenfeiyang
On Tue, Aug 22, 2023 at 1:55 PM Feiyang Chen <chenfeiyang@loongson.cn> wrote:
>
> When the current state is already PCI_D0, pci_power_up() will return
> 0 even though dev->pm_cap is not set. In that case, we should not
> read the PCI_PM_CTRL register in pci_set_full_power_state().
>
> Fixes: e200904b275c ("PCI/PM: Split pci_power_up()")
> Signed-off-by: Feiyang Chen <chenfeiyang@loongson.cn>
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
> ---
> drivers/pci/pci.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 60230da957e0..7e90ab7b47a1 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1242,9 +1242,6 @@ int pci_power_up(struct pci_dev *dev)
> else
> dev->current_state = state;
>
> - if (state == PCI_D0)
> - return 0;
> -
> return -EIO;
> }
>
> @@ -1302,8 +1299,12 @@ static int pci_set_full_power_state(struct pci_dev *dev)
> int ret;
>
> ret = pci_power_up(dev);
> - if (ret < 0)
> + if (ret < 0) {
> + if (dev->current_state == PCI_D0)
> + return 0;
> +
> return ret;
> + }
>
> pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
> dev->current_state = pmcsr & PCI_PM_CTRL_STATE_MASK;
> --
> 2.39.3
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-22 14:24 ` Rafael J. Wysocki
@ 2023-08-23 7:28 ` Ilpo Järvinen
2023-08-23 12:46 ` Rafael J. Wysocki
0 siblings, 1 reply; 10+ messages in thread
From: Ilpo Järvinen @ 2023-08-23 7:28 UTC (permalink / raw)
To: Rafael J. Wysocki, Feiyang Chen
Cc: bhelgaas, rafael.j.wysocki, Mika Westerberg, helgaas,
anders.roxell, linux-pci, linux-pm, guyinggang, siyanteng,
chenhuacai, loongson-kernel, chris.chenfeiyang
[-- Attachment #1: Type: text/plain, Size: 889 bytes --]
On Tue, 22 Aug 2023, Rafael J. Wysocki wrote:
> On Tue, Aug 22, 2023 at 3:24 PM Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> >
> > On Tue, 22 Aug 2023, Feiyang Chen wrote:
> >
> > > When the current state is already PCI_D0, pci_power_up() will return
> > > 0 even though dev->pm_cap is not set. In that case, we should not
> > > read the PCI_PM_CTRL register in pci_set_full_power_state().
> >
> > IMHO, this is a bit misleading because after this patch, pci_power_up()
> > returns always an error if dev->pm_cap is not set.
>
> Yes, it does, but it has 2 callers only and the other one ignores the
> return value, so this only matters here.
I did only mean that the changelog could be more clear how it achieves
the desired result (as currently it states opposite of what the code
does w.r.t. that return value).
I'm not against the approach taken by patch.
--
i.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-23 7:28 ` Ilpo Järvinen
@ 2023-08-23 12:46 ` Rafael J. Wysocki
2023-08-23 20:50 ` Bjorn Helgaas
0 siblings, 1 reply; 10+ messages in thread
From: Rafael J. Wysocki @ 2023-08-23 12:46 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Rafael J. Wysocki, Feiyang Chen, bhelgaas, rafael.j.wysocki,
Mika Westerberg, helgaas, anders.roxell, linux-pci, linux-pm,
guyinggang, siyanteng, chenhuacai, loongson-kernel,
chris.chenfeiyang
On Wed, Aug 23, 2023 at 9:28 AM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> On Tue, 22 Aug 2023, Rafael J. Wysocki wrote:
>
> > On Tue, Aug 22, 2023 at 3:24 PM Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > >
> > > On Tue, 22 Aug 2023, Feiyang Chen wrote:
> > >
> > > > When the current state is already PCI_D0, pci_power_up() will return
> > > > 0 even though dev->pm_cap is not set. In that case, we should not
> > > > read the PCI_PM_CTRL register in pci_set_full_power_state().
> > >
> > > IMHO, this is a bit misleading because after this patch, pci_power_up()
> > > returns always an error if dev->pm_cap is not set.
> >
> > Yes, it does, but it has 2 callers only and the other one ignores the
> > return value, so this only matters here.
>
> I did only mean that the changelog could be more clear how it achieves
> the desired result (as currently it states opposite of what the code
> does w.r.t. that return value).
Fair enough.
It looks like the changelog has not been updated since v1.
> I'm not against the approach taken by patch.
Thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-23 12:46 ` Rafael J. Wysocki
@ 2023-08-23 20:50 ` Bjorn Helgaas
2023-08-24 1:27 ` Feiyang Chen
0 siblings, 1 reply; 10+ messages in thread
From: Bjorn Helgaas @ 2023-08-23 20:50 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Ilpo Järvinen, Feiyang Chen, bhelgaas, rafael.j.wysocki,
Mika Westerberg, anders.roxell, linux-pci, linux-pm, guyinggang,
siyanteng, chenhuacai, loongson-kernel, chris.chenfeiyang
On Wed, Aug 23, 2023 at 02:46:25PM +0200, Rafael J. Wysocki wrote:
> On Wed, Aug 23, 2023 at 9:28 AM Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Tue, 22 Aug 2023, Rafael J. Wysocki wrote:
> > > On Tue, Aug 22, 2023 at 3:24 PM Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > >
> > > > On Tue, 22 Aug 2023, Feiyang Chen wrote:
> > > >
> > > > > When the current state is already PCI_D0, pci_power_up() will return
> > > > > 0 even though dev->pm_cap is not set. In that case, we should not
> > > > > read the PCI_PM_CTRL register in pci_set_full_power_state().
> > > >
> > > > IMHO, this is a bit misleading because after this patch, pci_power_up()
> > > > returns always an error if dev->pm_cap is not set.
> > >
> > > Yes, it does, but it has 2 callers only and the other one ignores the
> > > return value, so this only matters here.
> >
> > I did only mean that the changelog could be more clear how it achieves
> > the desired result (as currently it states opposite of what the code
> > does w.r.t. that return value).
>
> Fair enough.
>
> It looks like the changelog has not been updated since v1.
>
> > I'm not against the approach taken by patch.
Feiyang, would you update the commit log so it matches the code and
post it as a v3?
Bjorn
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available
2023-08-23 20:50 ` Bjorn Helgaas
@ 2023-08-24 1:27 ` Feiyang Chen
0 siblings, 0 replies; 10+ messages in thread
From: Feiyang Chen @ 2023-08-24 1:27 UTC (permalink / raw)
To: Bjorn Helgaas, Ilpo Järvinen, Rafael J. Wysocki
Cc: Feiyang Chen, bhelgaas, rafael.j.wysocki, Mika Westerberg,
anders.roxell, linux-pci, linux-pm, guyinggang, siyanteng,
chenhuacai, loongson-kernel
On Thu, Aug 24, 2023 at 4:50 AM Bjorn Helgaas <helgaas@kernel.org> wrote:
>
> On Wed, Aug 23, 2023 at 02:46:25PM +0200, Rafael J. Wysocki wrote:
> > On Wed, Aug 23, 2023 at 9:28 AM Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Tue, 22 Aug 2023, Rafael J. Wysocki wrote:
> > > > On Tue, Aug 22, 2023 at 3:24 PM Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > >
> > > > > On Tue, 22 Aug 2023, Feiyang Chen wrote:
> > > > >
> > > > > > When the current state is already PCI_D0, pci_power_up() will return
> > > > > > 0 even though dev->pm_cap is not set. In that case, we should not
> > > > > > read the PCI_PM_CTRL register in pci_set_full_power_state().
> > > > >
> > > > > IMHO, this is a bit misleading because after this patch, pci_power_up()
> > > > > returns always an error if dev->pm_cap is not set.
> > > >
> > > > Yes, it does, but it has 2 callers only and the other one ignores the
> > > > return value, so this only matters here.
> > >
> > > I did only mean that the changelog could be more clear how it achieves
> > > the desired result (as currently it states opposite of what the code
> > > does w.r.t. that return value).
> >
> > Fair enough.
> >
> > It looks like the changelog has not been updated since v1.
> >
> > > I'm not against the approach taken by patch.
>
> Feiyang, would you update the commit log so it matches the code and
> post it as a v3?
>
Sure. I will update the commit log.
Thanks,
Feiyang
> Bjorn
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-08-24 1:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22 11:55 [PATCH v2] PCI/PM: Only read PCI_PM_CTRL register when available Feiyang Chen
2023-08-22 13:06 ` Anders Roxell
2023-08-22 13:17 ` Ilpo Järvinen
2023-08-22 13:24 ` Ilpo Järvinen
2023-08-22 14:24 ` Rafael J. Wysocki
2023-08-23 7:28 ` Ilpo Järvinen
2023-08-23 12:46 ` Rafael J. Wysocki
2023-08-23 20:50 ` Bjorn Helgaas
2023-08-24 1:27 ` Feiyang Chen
2023-08-22 18:54 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox