From: Bjorn Helgaas <helgaas@kernel.org>
To: Bitao Hu <yaoma@linux.alibaba.com>
Cc: lukas@wunner.de, bhelgaas@google.com, weirongguang@kylinos.cn,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
kanie@linux.alibaba.com,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: Re: [PATCHv2] PCI: pciehp: Use appropriate conditions to check the hotplug controller status
Date: Fri, 14 Jun 2024 13:41:20 -0500 [thread overview]
Message-ID: <20240614184120.GA1121063@bhelgaas> (raw)
In-Reply-To: <20240528064200.87762-1-yaoma@linux.alibaba.com>
[+cc Ilpo]
On Tue, May 28, 2024 at 02:42:00PM +0800, Bitao Hu wrote:
> "present" and "link_active" can be 1 if the status is ready, and 0 if
> it is not. Both of them can be -ENODEV if reading the config space
> of the hotplug port failed. That's typically the case if the hotplug
> port itself was hot-removed. Therefore, this situation can occur:
> pciehp_card_present() may return 1 and pciehp_check_link_active()
> may return -ENODEV because the hotplug port was hot-removed in-between
> the two function calls. In that case we'll emit both "Card present"
> *and* "Link Up" since both 1 and -ENODEV are considered "true". This
> is not the expected behavior. Those messages should be emited when
> "present" and "link_active" are positive.
>
> Signed-off-by: Bitao Hu <yaoma@linux.alibaba.com>
> Reviewed-by: Lukas Wunner <lukas@wunner.de>
> ---
> v1 -> v2:
> 1. Explain the rationale of the code change in the commit message
> more clearly.
> 2. Add the "Reviewed-by" tag of Lukas.
> ---
> drivers/pci/hotplug/pciehp_ctrl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
> index dcdbfcf404dd..6adfdbb70150 100644
> --- a/drivers/pci/hotplug/pciehp_ctrl.c
> +++ b/drivers/pci/hotplug/pciehp_ctrl.c
> @@ -276,10 +276,10 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
> case OFF_STATE:
> ctrl->state = POWERON_STATE;
> mutex_unlock(&ctrl->state_lock);
> - if (present)
> + if (present > 0)
I completely agree that this is a problem and this patch addresses it.
But ...
It seems a little bit weird to me that we even get to this switch
statement if we got -ENODEV from either pciehp_card_present() or
pciehp_check_link_active(). If that happens, a config read failed,
but we're going to go ahead and call pciehp_enable_slot(), which is
going to do a bunch more config accesses, potentially try to power up
the slot, etc.
If a config read failed, it seems like we might want to avoid doing
some of this stuff.
> ctrl_info(ctrl, "Slot(%s): Card present\n",
> slot_name(ctrl));
> - if (link_active)
> + if (link_active > 0)
> ctrl_info(ctrl, "Slot(%s): Link Up\n",
> slot_name(ctrl));
These are cases where we misinterpreted -ENODEV as "device is present"
or "link is active".
pciehp_ignore_dpc_link_change() and pciehp_slot_reset() also call
pciehp_check_link_active(), and I think they also interpret -ENODEV as
"link is active".
Do we need similar changes there?
> ctrl->request_result = pciehp_enable_slot(ctrl);
> --
> 2.37.1 (Apple Git-137.1)
>
next prev parent reply other threads:[~2024-06-14 18:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 6:30 [PATCH] PCI: pciehp: Use appropriate conditions to check the hotplug controller status Bitao Hu
2024-05-24 7:53 ` Lukas Wunner
2024-05-26 14:45 ` yaoma
2024-05-27 8:50 ` Lukas Wunner
2024-05-27 9:43 ` yaoma
2024-05-28 6:42 ` [PATCHv2] " Bitao Hu
2024-05-28 10:54 ` Ilpo Järvinen
2024-06-14 18:41 ` Bjorn Helgaas [this message]
2024-06-14 19:36 ` Lukas Wunner
2024-06-14 22:03 ` Bjorn Helgaas
2024-06-15 10:06 ` Lukas Wunner
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=20240614184120.GA1121063@bhelgaas \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kanie@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=weirongguang@kylinos.cn \
--cc=yaoma@linux.alibaba.com \
/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