From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Ashok Raj <ashok.raj@intel.com>,
Keith Busch <keith.busch@intel.com>,
Yinghai Lu <yinghai@kernel.org>, Sinan Kaya <okaya@kernel.org>,
linux-pci@vger.kernel.org
Subject: Re: [PATCH 17/32] PCI: pciehp: Enable/disable exclusively from IRQ thread
Date: Thu, 21 Jun 2018 14:58:19 +0300 [thread overview]
Message-ID: <20180621115819.GX2558@lahna.fi.intel.com> (raw)
In-Reply-To: <ad8ef05242c00ce95aae64ca983cb3152cc8eb70.1529173804.git.lukas@wunner.de>
On Sat, Jun 16, 2018 at 09:25:00PM +0200, Lukas Wunner wrote:
> @@ -240,13 +240,19 @@ static int pciehp_probe(struct pcie_device *dev)
> }
>
> /* Check if slot is occupied */
> + mutex_lock(&slot->lock);
> pciehp_get_adapter_status(slot, &occupied);
> pciehp_get_power_status(slot, &poweron);
> - if (occupied && pciehp_force)
> - pciehp_enable_slot(slot);
> + if (pciehp_force &&
> + ((occupied && (slot->state == OFF_STATE ||
> + slot->state == BLINKINGON_STATE)) ||
> + (!occupied && (slot->state == ON_STATE ||
> + slot->state == BLINKINGOFF_STATE))))
> + pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
This...
> /* If empty slot's power status is on, turn power off */
> if (!occupied && poweron && POWER_CTRL(ctrl))
> pciehp_power_off_slot(slot);
> + mutex_unlock(&slot->lock);
>
> return 0;
>
> @@ -290,10 +296,14 @@ static int pciehp_resume(struct pcie_device *dev)
>
> /* Check if slot is occupied */
> pciehp_get_adapter_status(slot, &status);
> - if (status)
> - pciehp_enable_slot(slot);
> - else
> - pciehp_disable_slot(slot);
> + mutex_lock(&slot->lock);
> + if ((status && (slot->state == OFF_STATE ||
> + slot->state == BLINKINGON_STATE)) ||
> + (!status && (slot->state == ON_STATE ||
> + slot->state == BLINKINGOFF_STATE)))
> + pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
... and this look the same (I think there are other places as well).
Perhaps you could factor this to a helper function?
> + mutex_unlock(&slot->lock);
> +
> return 0;
> }
> #endif /* PM */
> diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
> index 627e846df802..70bad847a450 100644
> --- a/drivers/pci/hotplug/pciehp_ctrl.c
> +++ b/drivers/pci/hotplug/pciehp_ctrl.c
> @@ -122,22 +122,26 @@ static void remove_board(struct slot *p_slot)
> pciehp_green_led_off(p_slot);
> }
>
> +void pciehp_request(struct controller *ctrl, int action)
> +{
> + atomic_or(action, &ctrl->pending_events);
> + if (!pciehp_poll_mode)
> + irq_wake_thread(ctrl->pcie->irq, ctrl);
> +}
> +
> void pciehp_queue_pushbutton_work(struct work_struct *work)
> {
> struct slot *p_slot = container_of(work, struct slot, work.work);
> + struct controller *ctrl = p_slot->ctrl;
>
> mutex_lock(&p_slot->lock);
> switch (p_slot->state) {
> case BLINKINGOFF_STATE:
> - p_slot->state = POWEROFF_STATE;
> - mutex_unlock(&p_slot->lock);
> - pciehp_disable_slot(p_slot);
> - return;
> + pciehp_request(ctrl, DISABLE_SLOT);
> + break;
> case BLINKINGON_STATE:
> - p_slot->state = POWERON_STATE;
> - mutex_unlock(&p_slot->lock);
> - pciehp_enable_slot(p_slot);
> - return;
> + pciehp_request(ctrl, PCI_EXP_SLTSTA_PDC);
> + break;
> default:
> break;
> }
> @@ -186,16 +190,6 @@ void pciehp_handle_button_press(struct slot *p_slot)
> ctrl_info(ctrl, "Slot(%s): Action canceled due to button press\n",
> slot_name(p_slot));
> break;
> - case POWEROFF_STATE:
> - case POWERON_STATE:
> - /*
> - * Ignore if the slot is on power-on or power-off state;
> - * this means that the previous attention button action
> - * to hot-add or hot-remove is undergoing
> - */
> - ctrl_info(ctrl, "Slot(%s): Button ignored\n",
> - slot_name(p_slot));
> - break;
> default:
> ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n",
> slot_name(p_slot), p_slot->state);
> @@ -204,6 +198,22 @@ void pciehp_handle_button_press(struct slot *p_slot)
> mutex_unlock(&p_slot->lock);
> }
>
> +void pciehp_handle_disable_request(struct slot *slot)
> +{
> + struct controller *ctrl = slot->ctrl;
> +
> + mutex_lock(&slot->lock);
> + switch (slot->state) {
> + case BLINKINGON_STATE:
> + case BLINKINGOFF_STATE:
> + cancel_delayed_work(&slot->work);
Missing break here (even though it does nothing) but if someone extends
this in future it may cause problems.
> + }
> + slot->state = POWEROFF_STATE;
> + mutex_unlock(&slot->lock);
> +
> + ctrl->request_result = pciehp_disable_slot(slot);
> +}
> +
> void pciehp_handle_link_change(struct slot *p_slot)
> {
> struct controller *ctrl = p_slot->ctrl;
> @@ -232,32 +242,6 @@ void pciehp_handle_link_change(struct slot *p_slot)
> }
> return;
> break;
> - case POWERON_STATE:
> - if (link_active) {
> - ctrl_info(ctrl, "Slot(%s): Link Up event ignored; already powering on\n",
> - slot_name(p_slot));
> - } else {
> - p_slot->state = POWEROFF_STATE;
> - mutex_unlock(&p_slot->lock);
> - ctrl_info(ctrl, "Slot(%s): Link Down event queued; currently getting powered on\n",
> - slot_name(p_slot));
> - pciehp_disable_slot(p_slot);
> - return;
> - }
> - break;
> - case POWEROFF_STATE:
> - if (link_active) {
> - p_slot->state = POWERON_STATE;
> - mutex_unlock(&p_slot->lock);
> - ctrl_info(ctrl, "Slot(%s): Link Up event queued; currently getting powered off\n",
> - slot_name(p_slot));
> - pciehp_enable_slot(p_slot);
> - return;
> - } else {
> - ctrl_info(ctrl, "Slot(%s): Link Down event ignored; already powering off\n",
> - slot_name(p_slot));
> - }
> - break;
> default:
> ctrl_err(ctrl, "Slot(%s): Ignoring invalid state %#x\n",
> slot_name(p_slot), p_slot->state);
> @@ -272,6 +256,12 @@ void pciehp_handle_presence_change(struct slot *slot)
> u8 present;
>
> mutex_lock(&slot->lock);
> + switch (slot->state) {
> + case BLINKINGON_STATE:
> + case BLINKINGOFF_STATE:
> + cancel_delayed_work(&slot->work);
Ditto.
next prev parent reply other threads:[~2018-06-21 11:58 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-16 19:25 [PATCH 00/32] Rework pciehp event handling & add runtime PM Lukas Wunner
2018-06-16 19:25 ` [PATCH 25/32] PCI: pciehp: Clear spurious events earlier on resume Lukas Wunner
2018-06-16 19:25 ` [PATCH 16/32] PCI: pciehp: Track enable/disable status Lukas Wunner
2018-06-16 19:25 ` [PATCH 01/32] PCI: hotplug: Don't leak pci_slot on registration failure Lukas Wunner
2018-06-16 19:25 ` [PATCH 03/32] PCI: pciehp: Fix deadlock on unplug Lukas Wunner
2018-09-06 16:01 ` Mika Westerberg
2018-09-06 16:26 ` Lukas Wunner
2018-09-06 18:08 ` Mika Westerberg
2018-06-16 19:25 ` [PATCH 28/32] PCI: pciehp: Resume to D0 on enable/disable Lukas Wunner
2018-06-16 19:25 ` [PATCH 24/32] PCI: portdrv: Deduplicate PM callback iterator Lukas Wunner
2018-06-16 19:25 ` [PATCH 08/32] genirq: Synchronize only with single thread on free_irq() Lukas Wunner
2018-07-12 22:21 ` Bjorn Helgaas
2018-07-13 7:21 ` Lukas Wunner
2018-07-13 11:44 ` Bjorn Helgaas
2018-07-16 12:37 ` Bjorn Helgaas
2018-07-16 13:37 ` Lukas Wunner
2018-06-16 19:25 ` [PATCH 19/32] PCI: pciehp: Declare pciehp_enable/disable_slot() static Lukas Wunner
2018-06-16 19:25 ` [PATCH 05/32] PCI: pciehp: Drop unnecessary NULL pointer check Lukas Wunner
2018-06-16 19:25 ` [PATCH 22/32] PCI: pciehp: Always enable occupied slot on probe Lukas Wunner
2018-06-16 19:25 ` [PATCH 20/32] PCI: pciehp: Tolerate initially unstable link Lukas Wunner
2018-06-16 19:25 ` [PATCH 18/32] PCI: pciehp: Drop enable/disable lock Lukas Wunner
2018-06-16 19:25 ` [PATCH 10/32] PCI: pciehp: Convert to threaded polling Lukas Wunner
2018-06-16 19:25 ` [PATCH 23/32] PCI: pciehp: Avoid slot access during reset Lukas Wunner
2018-06-21 12:06 ` Mika Westerberg
2018-06-22 9:23 ` Lukas Wunner
2018-06-25 13:10 ` Mika Westerberg
2018-06-16 19:25 ` [PATCH 11/32] PCI: pciehp: Stop blinking on slot enable failure Lukas Wunner
2018-06-16 19:25 ` [PATCH 27/32] PCI: pciehp: Support interrupts sent from D3hot Lukas Wunner
2018-07-12 23:03 ` Bjorn Helgaas
2018-06-16 19:25 ` [PATCH 15/32] PCI: pciehp: Publish to user space last on probe Lukas Wunner
2018-06-16 19:25 ` [PATCH 13/32] PCI: pciehp: Drop slot workqueue Lukas Wunner
2018-06-16 19:25 ` [PATCH 32/32] PCI: Whitelist Thunderbolt ports for runtime D3 Lukas Wunner
2018-06-21 11:13 ` Mika Westerberg
2018-07-18 19:30 ` Lukas Wunner
2018-07-20 15:23 ` Mika Westerberg
2018-07-20 16:00 ` Mika Westerberg
2018-07-20 20:33 ` Bjorn Helgaas
2018-06-16 19:25 ` [PATCH 12/32] PCI: pciehp: Handle events synchronously Lukas Wunner
2018-06-16 19:25 ` [PATCH 14/32] PCI: hotplug: Demidlayer registration with the core Lukas Wunner
2018-06-17 16:44 ` Andy Shevchenko
2018-07-16 12:46 ` Bjorn Helgaas
2018-07-16 14:14 ` Andy Shevchenko
2018-06-16 19:25 ` [PATCH 17/32] PCI: pciehp: Enable/disable exclusively from IRQ thread Lukas Wunner
2018-06-21 11:58 ` Mika Westerberg [this message]
2018-06-16 19:25 ` [PATCH 29/32] PCI: pciehp: Resume parent to D0 on config space access Lukas Wunner
2018-06-16 19:25 ` [PATCH 02/32] PCI: pciehp: Fix UAF on unplug Lukas Wunner
2018-06-16 19:25 ` [PATCH 26/32] PCI: pciehp: Obey compulsory command delay after resume Lukas Wunner
2018-06-16 19:25 ` [PATCH 07/32] PCI: pciehp: Document struct slot and struct controller Lukas Wunner
2018-06-16 19:25 ` [PATCH 21/32] PCI: pciehp: Become resilient to missed events Lukas Wunner
2018-06-16 19:25 ` [PATCH 31/32] PCI: Whitelist native hotplug ports for runtime D3 Lukas Wunner
2018-06-16 19:25 ` [PATCH 04/32] PCI: pciehp: Fix unprotected list iteration in IRQ handler Lukas Wunner
2018-06-16 19:25 ` [PATCH 09/32] PCI: pciehp: Convert to threaded IRQ Lukas Wunner
2018-06-19 23:16 ` Keith Busch
2018-06-20 11:01 ` Lukas Wunner
2018-06-16 19:25 ` [PATCH 06/32] PCI: pciehp: Declare pciehp_unconfigure_device() void Lukas Wunner
2018-06-16 19:25 ` [PATCH 30/32] PCI: sysfs: Resume to D0 on function reset Lukas Wunner
2018-06-21 12:19 ` [PATCH 00/32] Rework pciehp event handling & add runtime PM Mika Westerberg
2018-06-27 13:35 ` Patel, Mayurkumar
2018-07-12 22:28 ` Bjorn Helgaas
2018-07-13 7:54 ` Lukas Wunner
2018-07-13 11:43 ` Bjorn Helgaas
2018-07-16 14:20 ` Bjorn Helgaas
2018-07-19 9:43 ` Lukas Wunner
2018-07-19 19:05 ` Bjorn Helgaas
2018-07-19 22:50 ` Bjorn Helgaas
2018-07-28 5:44 ` 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=20180621115819.GX2558@lahna.fi.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=ashok.raj@intel.com \
--cc=bhelgaas@google.com \
--cc=keith.busch@intel.com \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=okaya@kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=yinghai@kernel.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 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.