linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
@ 2020-09-13 20:29 Tiezhu Yang
  2020-09-14  4:06 ` Lukas Wunner
       [not found] ` <tencent_44F0201A70619BA613F16BA4@qq.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Tiezhu Yang @ 2020-09-13 20:29 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal, Lukas Wunner,
	oohall, rafael.j.wysocki, Xuefeng Li, Huacai Chen, Jiaxun Yang,
	linux-pci, linux-kernel

After commit 745be2e700cd ("PCIe: portdrv: call pci_disable_device
during remove") and commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe
services during shutdown"), it also calls pci_disable_device() during
shutdown, this leads to shutdown or reboot failure occasionally due to
clear PCI_COMMAND_MASTER on the device in do_pci_disable_device().

drivers/pci/pci.c
static void do_pci_disable_device(struct pci_dev *dev)
{
        u16 pci_command;

        pci_read_config_word(dev, PCI_COMMAND, &pci_command);
        if (pci_command & PCI_COMMAND_MASTER) {
                pci_command &= ~PCI_COMMAND_MASTER;
                pci_write_config_word(dev, PCI_COMMAND, pci_command);
        }

        pcibios_disable_device(dev);
}

When remove "pci_command &= ~PCI_COMMAND_MASTER;", it can work well.

As Oliver O'Halloran said, no need to call pci_disable_device() when
actually shutting down, but we should call pci_disable_device() before
handing over to the new kernel on kexec reboot, so we can do some
condition checks which are similar with pci_device_shutdown(), this is
done by commit 4fc9bbf98fd6 ("PCI: Disable Bus Master only on kexec
reboot") and commit 6e0eda3c3898 ("PCI: Don't try to disable Bus Master
on disconnected PCI devices").

drivers/pci/pci-driver.c
static void pci_device_shutdown(struct device *dev)
{
...

        /*
         * If this is a kexec reboot, turn off Bus Master bit on the
         * device to tell it to not continue to do DMA. Don't touch
         * devices in D3cold or unknown states.
         * If it is not a kexec reboot, firmware will hit the PCI
         * devices with big hammer and stop their DMA any way.
         */
        if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot))
                pci_clear_master(pci_dev);
}

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 drivers/pci/pcie/portdrv_core.c |  1 -
 drivers/pci/pcie/portdrv_pci.c  | 25 ++++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 50a9522..1991aca 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -491,7 +491,6 @@ void pcie_port_device_remove(struct pci_dev *dev)
 {
 	device_for_each_child(&dev->dev, NULL, remove_iter);
 	pci_free_irq_vectors(dev);
-	pci_disable_device(dev);
 }
 
 /**
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 3a3ce40..ce89a9e8 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/aer.h>
 #include <linux/dmi.h>
+#include <linux/kexec.h>
 
 #include "../pci.h"
 #include "portdrv.h"
@@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
 	}
 
 	pcie_port_device_remove(dev);
+	pci_disable_device(dev);
+}
+
+static void pcie_portdrv_shutdown(struct pci_dev *dev)
+{
+	if (pci_bridge_d3_possible(dev)) {
+		pm_runtime_forbid(&dev->dev);
+		pm_runtime_get_noresume(&dev->dev);
+		pm_runtime_dont_use_autosuspend(&dev->dev);
+	}
+
+	pcie_port_device_remove(dev);
+
+	/*
+	 * If this is a kexec reboot, turn off Bus Master bit on the
+	 * device to tell it to not continue to do DMA. Don't touch
+	 * devices in D3cold or unknown states.
+	 * If it is not a kexec reboot, firmware will hit the PCI
+	 * devices with big hammer and stop their DMA any way.
+	 */
+	if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
+		pci_disable_device(dev);
 }
 
 static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
@@ -211,7 +234,7 @@ static void pcie_portdrv_err_resume(struct pci_dev *dev)
 
 	.probe		= pcie_portdrv_probe,
 	.remove		= pcie_portdrv_remove,
-	.shutdown	= pcie_portdrv_remove,
+	.shutdown	= pcie_portdrv_shutdown,
 
 	.err_handler	= &pcie_portdrv_err_handler,
 
-- 
1.8.3.1


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

* Re: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
  2020-09-13 20:29 [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices Tiezhu Yang
@ 2020-09-14  4:06 ` Lukas Wunner
  2020-09-14  6:13   ` Tiezhu Yang
       [not found] ` <tencent_44F0201A70619BA613F16BA4@qq.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Lukas Wunner @ 2020-09-14  4:06 UTC (permalink / raw)
  To: Tiezhu Yang
  Cc: Bjorn Helgaas, Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal,
	oohall, rafael.j.wysocki, Xuefeng Li, Huacai Chen, Jiaxun Yang,
	linux-pci, linux-kernel

On Mon, Sep 14, 2020 at 04:29:10AM +0800, Tiezhu Yang wrote:
> --- a/drivers/pci/pcie/portdrv_pci.c
> +++ b/drivers/pci/pcie/portdrv_pci.c
> @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
>  	}
>  
>  	pcie_port_device_remove(dev);
> +	pci_disable_device(dev);
> +}
> +
> +static void pcie_portdrv_shutdown(struct pci_dev *dev)
> +{
> +	if (pci_bridge_d3_possible(dev)) {
> +		pm_runtime_forbid(&dev->dev);
> +		pm_runtime_get_noresume(&dev->dev);
> +		pm_runtime_dont_use_autosuspend(&dev->dev);
> +	}
> +
> +	pcie_port_device_remove(dev);
> +
> +	/*
> +	 * If this is a kexec reboot, turn off Bus Master bit on the
> +	 * device to tell it to not continue to do DMA. Don't touch
> +	 * devices in D3cold or unknown states.
> +	 * If it is not a kexec reboot, firmware will hit the PCI
> +	 * devices with big hammer and stop their DMA any way.
> +	 */
> +	if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
> +		pci_disable_device(dev);

The last portion of this function is already executed afterwards by
pci_device_shutdown().  You don't need to duplicate it here:

device_shutdown()
  dev->bus->shutdown() == pci_device_shutdown()
    drv->shutdown() == pcie_portdrv_shutdown()
      pci_disable_device()
    pci_disable_device()

Thanks,

Lukas

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

* Re: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
       [not found] ` <tencent_44F0201A70619BA613F16BA4@qq.com>
@ 2020-09-14  4:31   ` Huacai Chen
  2020-09-14  6:17     ` Tiezhu Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Huacai Chen @ 2020-09-14  4:31 UTC (permalink / raw)
  To: Tiezhu Yang, Bjorn Helgaas
  Cc: Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal, Lukas Wunner,
	oohall, rafael.j.wysocki, Xuefeng Li, Jiaxun Yang, linux-pci,
	linux-kernel, zhouyanjie, git

Hi, Tiezhu

> ------------------ Original ------------------
> From:  "Tiezhu Yang"<yangtiezhu@loongson.cn>;
> Date:  Mon, Sep 14, 2020 04:29 AM
> To:  "Bjorn Helgaas"<bhelgaas@google.com>;
> Cc:  "Konstantin Khlebnikov"<khlebnikov@openvz.org>; "Khalid Aziz"<khalid.aziz@oracle.com>; "Vivek Goyal"<vgoyal@redhat.com>; "Lukas Wunner"<lukas@wunner.de>; "oohall"<oohall@gmail.com>; "rafael.j.wysocki"<rafael.j.wysocki@intel.com>; "Xuefeng Li"<lixuefeng@loongson.cn>; "Huacai Chen"<chenhc@lemote.com>; "Jiaxun Yang"<jiaxun.yang@flygoat.com>; "linux-pci"<linux-pci@vger.kernel.org>; "linux-kernel"<linux-kernel@vger.kernel.org>;
> Subject:  [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
>
>
>
> After commit 745be2e700cd ("PCIe: portdrv: call pci_disable_device
> during remove") and commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe
> services during shutdown"), it also calls pci_disable_device() during
> shutdown, this leads to shutdown or reboot failure occasionally due to
> clear PCI_COMMAND_MASTER on the device in do_pci_disable_device().
>
> drivers/pci/pci.c
> static void do_pci_disable_device(struct pci_dev *dev)
> {
>         u16 pci_command;
>
>         pci_read_config_word(dev, PCI_COMMAND, &pci_command);
>         if (pci_command & PCI_COMMAND_MASTER) {
>                 pci_command &= ~PCI_COMMAND_MASTER;
>                 pci_write_config_word(dev, PCI_COMMAND, pci_command);
>         }
>
>         pcibios_disable_device(dev);
> }
>
> When remove "pci_command &= ~PCI_COMMAND_MASTER;", it can work well.
>
> As Oliver O'Halloran said, no need to call pci_disable_device() when
> actually shutting down, but we should call pci_disable_device() before
> handing over to the new kernel on kexec reboot, so we can do some
> condition checks which are similar with pci_device_shutdown(), this is
> done by commit 4fc9bbf98fd6 ("PCI: Disable Bus Master only on kexec
> reboot") and commit 6e0eda3c3898 ("PCI: Don't try to disable Bus Master
> on disconnected PCI devices").
>
> drivers/pci/pci-driver.c
> static void pci_device_shutdown(struct device *dev)
> {
> ...
>
>         /*
>          * If this is a kexec reboot, turn off Bus Master bit on the
>          * device to tell it to not continue to do DMA. Don't touch
>          * devices in D3cold or unknown states.
>          * If it is not a kexec reboot, firmware will hit the PCI
>          * devices with big hammer and stop their DMA any way.
>          */
>         if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot))
>                 pci_clear_master(pci_dev);
> }
Have you really tried kexec? Why do you think kexec can disable pci
device successfully while normal reboot/poweroff cannot?

Huacai
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  drivers/pci/pcie/portdrv_core.c |  1 -
>  drivers/pci/pcie/portdrv_pci.c  | 25 ++++++++++++++++++++++++-
>  2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
> index 50a9522..1991aca 100644
> --- a/drivers/pci/pcie/portdrv_core.c
> +++ b/drivers/pci/pcie/portdrv_core.c
> @@ -491,7 +491,6 @@ void pcie_port_device_remove(struct pci_dev *dev)
>  {
>         device_for_each_child(&dev->dev, NULL, remove_iter);
>         pci_free_irq_vectors(dev);
> -       pci_disable_device(dev);
>  }
>
>  /**
> diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
> index 3a3ce40..ce89a9e8 100644
> --- a/drivers/pci/pcie/portdrv_pci.c
> +++ b/drivers/pci/pcie/portdrv_pci.c
> @@ -15,6 +15,7 @@
>  #include <linux/init.h>
>  #include <linux/aer.h>
>  #include <linux/dmi.h>
> +#include <linux/kexec.h>
>
>  #include "../pci.h"
>  #include "portdrv.h"
> @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
>         }
>
>         pcie_port_device_remove(dev);
> +       pci_disable_device(dev);
> +}
> +
> +static void pcie_portdrv_shutdown(struct pci_dev *dev)
> +{
> +       if (pci_bridge_d3_possible(dev)) {
> +               pm_runtime_forbid(&dev->dev);
> +               pm_runtime_get_noresume(&dev->dev);
> +               pm_runtime_dont_use_autosuspend(&dev->dev);
> +       }
> +
> +       pcie_port_device_remove(dev);
> +
> +       /*
> +        * If this is a kexec reboot, turn off Bus Master bit on the
> +        * device to tell it to not continue to do DMA. Don't touch
> +        * devices in D3cold or unknown states.
> +        * If it is not a kexec reboot, firmware will hit the PCI
> +        * devices with big hammer and stop their DMA any way.
> +        */
> +       if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
> +               pci_disable_device(dev);
>  }
>
>  static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
> @@ -211,7 +234,7 @@ static void pcie_portdrv_err_resume(struct pci_dev *dev)
>
>         .probe          = pcie_portdrv_probe,
>         .remove         = pcie_portdrv_remove,
> -       .shutdown       = pcie_portdrv_remove,
> +       .shutdown       = pcie_portdrv_shutdown,
>
>         .err_handler    = &pcie_portdrv_err_handler,
>
> --
> 1.8.3.1

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

* Re: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
  2020-09-14  4:06 ` Lukas Wunner
@ 2020-09-14  6:13   ` Tiezhu Yang
  2020-09-14  6:30     ` Tiezhu Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Tiezhu Yang @ 2020-09-14  6:13 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: Bjorn Helgaas, Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal,
	oohall, rafael.j.wysocki, Xuefeng Li, Huacai Chen, Jiaxun Yang,
	linux-pci, linux-kernel

On 09/14/2020 12:06 PM, Lukas Wunner wrote:
> On Mon, Sep 14, 2020 at 04:29:10AM +0800, Tiezhu Yang wrote:
>> --- a/drivers/pci/pcie/portdrv_pci.c
>> +++ b/drivers/pci/pcie/portdrv_pci.c
>> @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
>>   	}
>>   
>>   	pcie_port_device_remove(dev);
>> +	pci_disable_device(dev);
>> +}
>> +
>> +static void pcie_portdrv_shutdown(struct pci_dev *dev)
>> +{
>> +	if (pci_bridge_d3_possible(dev)) {
>> +		pm_runtime_forbid(&dev->dev);
>> +		pm_runtime_get_noresume(&dev->dev);
>> +		pm_runtime_dont_use_autosuspend(&dev->dev);
>> +	}
>> +
>> +	pcie_port_device_remove(dev);
>> +
>> +	/*
>> +	 * If this is a kexec reboot, turn off Bus Master bit on the
>> +	 * device to tell it to not continue to do DMA. Don't touch
>> +	 * devices in D3cold or unknown states.
>> +	 * If it is not a kexec reboot, firmware will hit the PCI
>> +	 * devices with big hammer and stop their DMA any way.
>> +	 */
>> +	if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
>> +		pci_disable_device(dev);
> The last portion of this function is already executed afterwards by
> pci_device_shutdown().  You don't need to duplicate it here:
>
> device_shutdown()
>    dev->bus->shutdown() == pci_device_shutdown()
>      drv->shutdown() == pcie_portdrv_shutdown()
>        pci_disable_device()
>      pci_disable_device()

pcie_port_device_remove() deletes pci_disable_device(dev)  at the beginning of this patch.


diff 
<https://lore.kernel.org/linux-pci/CAAhV-H5-X9OcBe3iRxF8PnKW-0j_10FVqm8cbiqW2-Lv4mTTdQ@mail.gmail.com/T/#iZ2e.:..:1600028950-10644-1-git-send-email-yangtiezhu::40loongson.cn:0drivers:pci:pcie:portdrv_core.c> 
--git a/drivers/pci/pcie/portdrv_core.c 
b/drivers/pci/pcie/portdrv_core.c index 50a9522..1991aca 100644 --- 
a/drivers/pci/pcie/portdrv_core.c +++ b/drivers/pci/pcie/portdrv_core.c 
@@ -491,7 +491,6 @@ void pcie_port_device_remove(struct pci_dev *dev)   {
  	device_for_each_child(&dev->dev, NULL, remove_iter);
  	pci_free_irq_vectors(dev);
- pci_disable_device(dev);   }

>
> Thanks,
>
> Lukas


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

* Re: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
  2020-09-14  4:31   ` Huacai Chen
@ 2020-09-14  6:17     ` Tiezhu Yang
  0 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2020-09-14  6:17 UTC (permalink / raw)
  To: Huacai Chen, Bjorn Helgaas
  Cc: Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal, Lukas Wunner,
	oohall, rafael.j.wysocki, Xuefeng Li, Jiaxun Yang, linux-pci,
	linux-kernel, zhouyanjie, git

On 09/14/2020 12:31 PM, Huacai Chen wrote:
> Hi, Tiezhu
>
>> ------------------ Original ------------------
>> From:  "Tiezhu Yang"<yangtiezhu@loongson.cn>;
>> Date:  Mon, Sep 14, 2020 04:29 AM
>> To:  "Bjorn Helgaas"<bhelgaas@google.com>;
>> Cc:  "Konstantin Khlebnikov"<khlebnikov@openvz.org>; "Khalid Aziz"<khalid.aziz@oracle.com>; "Vivek Goyal"<vgoyal@redhat.com>; "Lukas Wunner"<lukas@wunner.de>; "oohall"<oohall@gmail.com>; "rafael.j.wysocki"<rafael.j.wysocki@intel.com>; "Xuefeng Li"<lixuefeng@loongson.cn>; "Huacai Chen"<chenhc@lemote.com>; "Jiaxun Yang"<jiaxun.yang@flygoat.com>; "linux-pci"<linux-pci@vger.kernel.org>; "linux-kernel"<linux-kernel@vger.kernel.org>;
>> Subject:  [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
>>
>>
>>
>> After commit 745be2e700cd ("PCIe: portdrv: call pci_disable_device
>> during remove") and commit cc27b735ad3a ("PCI/portdrv: Turn off PCIe
>> services during shutdown"), it also calls pci_disable_device() during
>> shutdown, this leads to shutdown or reboot failure occasionally due to
>> clear PCI_COMMAND_MASTER on the device in do_pci_disable_device().
>>
>> drivers/pci/pci.c
>> static void do_pci_disable_device(struct pci_dev *dev)
>> {
>>          u16 pci_command;
>>
>>          pci_read_config_word(dev, PCI_COMMAND, &pci_command);
>>          if (pci_command & PCI_COMMAND_MASTER) {
>>                  pci_command &= ~PCI_COMMAND_MASTER;
>>                  pci_write_config_word(dev, PCI_COMMAND, pci_command);
>>          }
>>
>>          pcibios_disable_device(dev);
>> }
>>
>> When remove "pci_command &= ~PCI_COMMAND_MASTER;", it can work well.
>>
>> As Oliver O'Halloran said, no need to call pci_disable_device() when
>> actually shutting down, but we should call pci_disable_device() before
>> handing over to the new kernel on kexec reboot, so we can do some
>> condition checks which are similar with pci_device_shutdown(), this is
>> done by commit 4fc9bbf98fd6 ("PCI: Disable Bus Master only on kexec
>> reboot") and commit 6e0eda3c3898 ("PCI: Don't try to disable Bus Master
>> on disconnected PCI devices").
>>
>> drivers/pci/pci-driver.c
>> static void pci_device_shutdown(struct device *dev)
>> {
>> ...
>>
>>          /*
>>           * If this is a kexec reboot, turn off Bus Master bit on the
>>           * device to tell it to not continue to do DMA. Don't touch
>>           * devices in D3cold or unknown states.
>>           * If it is not a kexec reboot, firmware will hit the PCI
>>           * devices with big hammer and stop their DMA any way.
>>           */
>>          if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot))
>>                  pci_clear_master(pci_dev);
>> }
> Have you really tried kexec? Why do you think kexec can disable pci
> device successfully while normal reboot/poweroff cannot?

Yes, I test it on kexec reboot,  it  works well.

>
> Huacai
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>> ---
>>   drivers/pci/pcie/portdrv_core.c |  1 -
>>   drivers/pci/pcie/portdrv_pci.c  | 25 ++++++++++++++++++++++++-
>>   2 files changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
>> index 50a9522..1991aca 100644
>> --- a/drivers/pci/pcie/portdrv_core.c
>> +++ b/drivers/pci/pcie/portdrv_core.c
>> @@ -491,7 +491,6 @@ void pcie_port_device_remove(struct pci_dev *dev)
>>   {
>>          device_for_each_child(&dev->dev, NULL, remove_iter);
>>          pci_free_irq_vectors(dev);
>> -       pci_disable_device(dev);
>>   }
>>
>>   /**
>> diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
>> index 3a3ce40..ce89a9e8 100644
>> --- a/drivers/pci/pcie/portdrv_pci.c
>> +++ b/drivers/pci/pcie/portdrv_pci.c
>> @@ -15,6 +15,7 @@
>>   #include <linux/init.h>
>>   #include <linux/aer.h>
>>   #include <linux/dmi.h>
>> +#include <linux/kexec.h>
>>
>>   #include "../pci.h"
>>   #include "portdrv.h"
>> @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
>>          }
>>
>>          pcie_port_device_remove(dev);
>> +       pci_disable_device(dev);
>> +}
>> +
>> +static void pcie_portdrv_shutdown(struct pci_dev *dev)
>> +{
>> +       if (pci_bridge_d3_possible(dev)) {
>> +               pm_runtime_forbid(&dev->dev);
>> +               pm_runtime_get_noresume(&dev->dev);
>> +               pm_runtime_dont_use_autosuspend(&dev->dev);
>> +       }
>> +
>> +       pcie_port_device_remove(dev);
>> +
>> +       /*
>> +        * If this is a kexec reboot, turn off Bus Master bit on the
>> +        * device to tell it to not continue to do DMA. Don't touch
>> +        * devices in D3cold or unknown states.
>> +        * If it is not a kexec reboot, firmware will hit the PCI
>> +        * devices with big hammer and stop their DMA any way.
>> +        */
>> +       if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
>> +               pci_disable_device(dev);
>>   }
>>
>>   static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
>> @@ -211,7 +234,7 @@ static void pcie_portdrv_err_resume(struct pci_dev *dev)
>>
>>          .probe          = pcie_portdrv_probe,
>>          .remove         = pcie_portdrv_remove,
>> -       .shutdown       = pcie_portdrv_remove,
>> +       .shutdown       = pcie_portdrv_shutdown,
>>
>>          .err_handler    = &pcie_portdrv_err_handler,
>>
>> --
>> 1.8.3.1


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

* Re: [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices
  2020-09-14  6:13   ` Tiezhu Yang
@ 2020-09-14  6:30     ` Tiezhu Yang
  0 siblings, 0 replies; 6+ messages in thread
From: Tiezhu Yang @ 2020-09-14  6:30 UTC (permalink / raw)
  To: Lukas Wunner
  Cc: Bjorn Helgaas, Konstantin Khlebnikov, Khalid Aziz, Vivek Goyal,
	oohall, rafael.j.wysocki, Xuefeng Li, Huacai Chen, Jiaxun Yang,
	linux-pci, linux-kernel

On 09/14/2020 02:13 PM, Tiezhu Yang wrote:
> On 09/14/2020 12:06 PM, Lukas Wunner wrote:
>> On Mon, Sep 14, 2020 at 04:29:10AM +0800, Tiezhu Yang wrote:
>>> --- a/drivers/pci/pcie/portdrv_pci.c
>>> +++ b/drivers/pci/pcie/portdrv_pci.c
>>> @@ -143,6 +144,28 @@ static void pcie_portdrv_remove(struct pci_dev 
>>> *dev)
>>>       }
>>>         pcie_port_device_remove(dev);
>>> +    pci_disable_device(dev);
>>> +}
>>> +
>>> +static void pcie_portdrv_shutdown(struct pci_dev *dev)
>>> +{
>>> +    if (pci_bridge_d3_possible(dev)) {
>>> +        pm_runtime_forbid(&dev->dev);
>>> +        pm_runtime_get_noresume(&dev->dev);
>>> +        pm_runtime_dont_use_autosuspend(&dev->dev);
>>> +    }
>>> +
>>> +    pcie_port_device_remove(dev);
>>> +
>>> +    /*
>>> +     * If this is a kexec reboot, turn off Bus Master bit on the
>>> +     * device to tell it to not continue to do DMA. Don't touch
>>> +     * devices in D3cold or unknown states.
>>> +     * If it is not a kexec reboot, firmware will hit the PCI
>>> +     * devices with big hammer and stop their DMA any way.
>>> +     */
>>> +    if (kexec_in_progress && (dev->current_state <= PCI_D3hot))
>>> +        pci_disable_device(dev);
>> The last portion of this function is already executed afterwards by
>> pci_device_shutdown().  You don't need to duplicate it here:
>>
>> device_shutdown()
>>    dev->bus->shutdown() == pci_device_shutdown()
>>      drv->shutdown() == pcie_portdrv_shutdown()
>>        pci_disable_device()
>>      pci_disable_device()
>
> pcie_port_device_remove() deletes pci_disable_device(dev)  at the 
> beginning of this patch.

Sorry, I misunderstood your meaning, you are right.

>
>
> diff 
> <https://lore.kernel.org/linux-pci/CAAhV-H5-X9OcBe3iRxF8PnKW-0j_10FVqm8cbiqW2-Lv4mTTdQ@mail.gmail.com/T/#iZ2e.:..:1600028950-10644-1-git-send-email-yangtiezhu::40loongson.cn:0drivers:pci:pcie:portdrv_core.c> 
> --git a/drivers/pci/pcie/portdrv_core.c 
> b/drivers/pci/pcie/portdrv_core.c index 50a9522..1991aca 100644 --- 
> a/drivers/pci/pcie/portdrv_core.c +++ 
> b/drivers/pci/pcie/portdrv_core.c @@ -491,7 +491,6 @@ void 
> pcie_port_device_remove(struct pci_dev *dev)   {
>      device_for_each_child(&dev->dev, NULL, remove_iter);
>      pci_free_irq_vectors(dev);
> - pci_disable_device(dev);   }
>
>>
>> Thanks,
>>
>> Lukas


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

end of thread, other threads:[~2020-09-14  6:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 20:29 [RFC PATCH v2] PCI/portdrv: Only disable Bus Master on kexec reboot and connected PCI devices Tiezhu Yang
2020-09-14  4:06 ` Lukas Wunner
2020-09-14  6:13   ` Tiezhu Yang
2020-09-14  6:30     ` Tiezhu Yang
     [not found] ` <tencent_44F0201A70619BA613F16BA4@qq.com>
2020-09-14  4:31   ` Huacai Chen
2020-09-14  6:17     ` Tiezhu Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).