Linux-PCI Archive on lore.kernel.org
 help / color / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
Cc: linux-pci@vger.kernel.org, linux@yadro.com
Subject: Re: [PATCH] PCI: pciehp: Fix re-enabling the slot marked for safe removal
Date: Tue, 5 Mar 2019 12:01:34 +0100
Message-ID: <20190305110134.drw4hb7h2eruewkp@wunner.de> (raw)
In-Reply-To: <20190301161251.26774-1-s.miroshnichenko@yadro.com>

On Fri, Mar 01, 2019 at 07:12:51PM +0300, Sergey Miroshnichenko wrote:
> During the safe removal procedure, a Data Link Layer State Changed event
> may occur after pciehp_power_off_slot(), and it is handled when the slot is
> already set to OFF_STATE. This results in re-enabling the device and makes
> it impossible to actually safely remove it.
> 
> Add a check for a Presence Detect Changed bit to filter out this interrupt.
> 
> It is still possible to re-enable the device if it remains in the slot
> after pressing the Attention Button by pressing it again.
> 
> Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
> Cc: Lukas Wunner <lukas@wunner.de>
> ---
>  drivers/pci/hotplug/pciehp_ctrl.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
> index 3f3df4c29f6e..941f77b71df4 100644
> --- a/drivers/pci/hotplug/pciehp_ctrl.c
> +++ b/drivers/pci/hotplug/pciehp_ctrl.c
> @@ -251,6 +251,14 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
>  		return;
>  	}
>  
> +	/* Handle the DLLSC from the slot which just has been turned off */
> +	if ((events & PCI_EXP_SLTSTA_DLLSC) &&
> +	    !(events & PCI_EXP_SLTSTA_PDC) &&
> +	    present && !link_active) {
> +		mutex_unlock(&ctrl->state_lock);
> +		return;
> +	}
> +
>  	switch (ctrl->state) {
>  	case BLINKINGON_STATE:
>  		cancel_delayed_work(&ctrl->button_work);

Hm, I'd instead prefer amending remove_board() like this:

 	if (POWER_CTRL(ctrl)) {
 		pciehp_power_off_slot(ctrl);
 
 		/*
 		 * After turning power off, we must wait for at least 1 second
 		 * before taking any action that relies on power having been
 		 * removed from the slot/adapter.
 		 */
 		msleep(1000);
 
+		/* ignore link or presence changes caused by power off */
+		atomic_and(~(PCI_EXP_SLTSTA_DLLSC | PCI_EXP_SLTSTA_PDC),
+			   &ctrl->pending_events);
 	}

Would this work for you?

Thanks,

Lukas

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01 16:12 Sergey Miroshnichenko
2019-03-05 11:01 ` Lukas Wunner [this message]
2019-03-12 12:03   ` Sergey Miroshnichenko

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=20190305110134.drw4hb7h2eruewkp@wunner.de \
    --to=lukas@wunner.de \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@yadro.com \
    --cc=s.miroshnichenko@yadro.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

Linux-PCI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pci/0 linux-pci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pci linux-pci/ https://lore.kernel.org/linux-pci \
		linux-pci@vger.kernel.org
	public-inbox-index linux-pci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git