diff mbox series

[v3] PCI/ERR: Use pcie_aer_is_native() to judge whether OS owns AER

Message ID 20220727035334.9997-1-chenzhuo.1@bytedance.com (mailing list archive)
State Superseded
Headers show
Series [v3] PCI/ERR: Use pcie_aer_is_native() to judge whether OS owns AER | expand

Commit Message

Zhuo Chen July 27, 2022, 3:53 a.m. UTC
Use pcie_aer_is_native() in place of "host->native_aer ||
pcie_ports_native" to judge whether OS has native control of AER
in pcie_do_recovery().

Replace "dev->aer_cap && (pcie_ports_native || host->native_aer)" in
get_port_device_capability() with pcie_aer_is_native(), which has no
functional changes.

Signed-off-by: Zhuo Chen <chenzhuo.1@bytedance.com>
---
Changelog:
v3:
- Simplify why we use pcie_aer_is_native().
- Revert modification of pci_aer_clear_nonfatal_status() and comments.
v2:
- Add details and note in commit log.
---
 drivers/pci/pcie/err.c          | 3 +--
 drivers/pci/pcie/portdrv_core.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

Comments

Kuppuswamy Sathyanarayanan July 27, 2022, 4:02 a.m. UTC | #1
On 7/26/22 8:53 PM, Zhuo Chen wrote:
> Use pcie_aer_is_native() in place of "host->native_aer ||
> pcie_ports_native" to judge whether OS has native control of AER
> in pcie_do_recovery().
> 
> Replace "dev->aer_cap && (pcie_ports_native || host->native_aer)" in
> get_port_device_capability() with pcie_aer_is_native(), which has no
> functional changes.
> 
> Signed-off-by: Zhuo Chen <chenzhuo.1@bytedance.com>
> ---

Patch looks better now. It looks like following two changes
can also be replaced with pcie_aer_is_native() check.

drivers/pci/pcie/aer.c:1407:	if ((host->native_aer || pcie_ports_native) && aer) {
drivers/pci/pcie/aer.c:1426:	if ((host->native_aer || pcie_ports_native) && aer) {



> Changelog:
> v3:
> - Simplify why we use pcie_aer_is_native().
> - Revert modification of pci_aer_clear_nonfatal_status() and comments.
> v2:
> - Add details and note in commit log.
> ---
>  drivers/pci/pcie/err.c          | 3 +--
>  drivers/pci/pcie/portdrv_core.c | 3 +--
>  2 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
> index 0c5a143025af..121a53338e44 100644
> --- a/drivers/pci/pcie/err.c
> +++ b/drivers/pci/pcie/err.c
> @@ -184,7 +184,6 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
>  	int type = pci_pcie_type(dev);
>  	struct pci_dev *bridge;
>  	pci_ers_result_t status = PCI_ERS_RESULT_CAN_RECOVER;
> -	struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
>  
>  	/*
>  	 * If the error was detected by a Root Port, Downstream Port, RCEC,
> @@ -243,7 +242,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
>  	 * it is responsible for clearing this status.  In that case, the
>  	 * signaling device may not even be visible to the OS.
>  	 */
> -	if (host->native_aer || pcie_ports_native) {
> +	if (pcie_aer_is_native(dev)) {
>  		pcie_clear_device_status(dev);
>  		pci_aer_clear_nonfatal_status(dev);
>  	}
> diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
> index 604feeb84ee4..98c18f4a01b2 100644
> --- a/drivers/pci/pcie/portdrv_core.c
> +++ b/drivers/pci/pcie/portdrv_core.c
> @@ -221,8 +221,7 @@ static int get_port_device_capability(struct pci_dev *dev)
>  	}
>  
>  #ifdef CONFIG_PCIEAER
> -	if (dev->aer_cap && pci_aer_available() &&
> -	    (pcie_ports_native || host->native_aer)) {
> +	if (pcie_aer_is_native(dev) && pci_aer_available()) {
>  		services |= PCIE_PORT_SERVICE_AER;
>  
>  		/*
Zhuo Chen July 27, 2022, 5:35 a.m. UTC | #2
On 7/26/22 9:02 PM, Sathyanarayanan Kuppuswamy wrote:
> 
> 
> On 7/26/22 8:53 PM, Zhuo Chen wrote:
>> Use pcie_aer_is_native() in place of "host->native_aer ||
>> pcie_ports_native" to judge whether OS has native control of AER
>> in pcie_do_recovery().
>>
>> Replace "dev->aer_cap && (pcie_ports_native || host->native_aer)" in
>> get_port_device_capability() with pcie_aer_is_native(), which has no
>> functional changes.
>>
>> Signed-off-by: Zhuo Chen <chenzhuo.1@bytedance.com>
>> ---
> 
> Patch looks better now. It looks like following two changes
> can also be replaced with pcie_aer_is_native() check.
> 
> drivers/pci/pcie/aer.c:1407:	if ((host->native_aer || pcie_ports_native) && aer) {
> drivers/pci/pcie/aer.c:1426:	if ((host->native_aer || pcie_ports_native) && aer) {

Good advice. But I wonder is there a scenario that dev->rcec ("root") is 
NULL meanwhile dev->aer_cap is not NULL? If so, replace 
"(host->native_aer || pcie_ports_native) && aer" with 
pcie_aer_is_native() will change original function.

> 
> 
> 
>> Changelog:
>> v3:
>> - Simplify why we use pcie_aer_is_native().
>> - Revert modification of pci_aer_clear_nonfatal_status() and comments.
>> v2:
>> - Add details and note in commit log.
>> ---
>>   drivers/pci/pcie/err.c          | 3 +--
>>   drivers/pci/pcie/portdrv_core.c | 3 +--
>>   2 files changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
>> index 0c5a143025af..121a53338e44 100644
>> --- a/drivers/pci/pcie/err.c
>> +++ b/drivers/pci/pcie/err.c
>> @@ -184,7 +184,6 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
>>   	int type = pci_pcie_type(dev);
>>   	struct pci_dev *bridge;
>>   	pci_ers_result_t status = PCI_ERS_RESULT_CAN_RECOVER;
>> -	struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
>>   
>>   	/*
>>   	 * If the error was detected by a Root Port, Downstream Port, RCEC,
>> @@ -243,7 +242,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
>>   	 * it is responsible for clearing this status.  In that case, the
>>   	 * signaling device may not even be visible to the OS.
>>   	 */
>> -	if (host->native_aer || pcie_ports_native) {
>> +	if (pcie_aer_is_native(dev)) {
>>   		pcie_clear_device_status(dev);
>>   		pci_aer_clear_nonfatal_status(dev);
>>   	}
>> diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
>> index 604feeb84ee4..98c18f4a01b2 100644
>> --- a/drivers/pci/pcie/portdrv_core.c
>> +++ b/drivers/pci/pcie/portdrv_core.c
>> @@ -221,8 +221,7 @@ static int get_port_device_capability(struct pci_dev *dev)
>>   	}
>>   
>>   #ifdef CONFIG_PCIEAER
>> -	if (dev->aer_cap && pci_aer_available() &&
>> -	    (pcie_ports_native || host->native_aer)) {
>> +	if (pcie_aer_is_native(dev) && pci_aer_available()) {
>>   		services |= PCIE_PORT_SERVICE_AER;
>>   
>>   		/*
> 

Thanks,
Zhuo Chen
Zhuo Chen July 27, 2022, 9:37 a.m. UTC | #3
On 7/26/22 1:35 PM, Zhuo Chen wrote:
> 
> On 7/26/22 9:02 PM, Sathyanarayanan Kuppuswamy wrote:
>>
>>
>> On 7/26/22 8:53 PM, Zhuo Chen wrote:
>>> Use pcie_aer_is_native() in place of "host->native_aer ||
>>> pcie_ports_native" to judge whether OS has native control of AER
>>> in pcie_do_recovery().
>>>
>>> Replace "dev->aer_cap && (pcie_ports_native || host->native_aer)" in
>>> get_port_device_capability() with pcie_aer_is_native(), which has no
>>> functional changes.
>>>
>>> Signed-off-by: Zhuo Chen <chenzhuo.1@bytedance.com>
>>> ---
>>
>> Patch looks better now. It looks like following two changes
>> can also be replaced with pcie_aer_is_native() check.
>>
>> drivers/pci/pcie/aer.c:1407:    if ((host->native_aer || 
>> pcie_ports_native) && aer) {
>> drivers/pci/pcie/aer.c:1426:    if ((host->native_aer || 
>> pcie_ports_native) && aer) {
> 
> Good advice. But I wonder is there a scenario that dev->rcec ("root") is 
> NULL meanwhile dev->aer_cap is not NULL? If so, replace 
> "(host->native_aer || pcie_ports_native) && aer" with 
> pcie_aer_is_native() will change original function.
> 
Do you mean changing "if ((host->native_aer || pcie_ports_native) && 
aer)" into "if (pcie_aer_is_native(dev) && aer)" ?
I thought changing into "if (pcie_aer_is_native(dev))" before.

One another doubt. Not every pci device support aer. When dev->aer_cap 
is NULL and root->aer_cap is not NULL in aer_root_reset(), 
pcie_aer_is_native() will return false and OS cannot operate root 
register. It's different from just using "(host->native_aer || 
pcie_ports_native)".

Or we can change "if ((host->native_aer || pcie_ports_native) && aer)" 
into "if (pcie_aer_is_native(root))". But in this way, argument NULL 
pointer check should be added in pcie_aer_is_native().

>>
>>
>>
>>> Changelog:
>>> v3:
>>> - Simplify why we use pcie_aer_is_native().
>>> - Revert modification of pci_aer_clear_nonfatal_status() and comments.
>>> v2:
>>> - Add details and note in commit log.
>>> ---
>>>   drivers/pci/pcie/err.c          | 3 +--
>>>   drivers/pci/pcie/portdrv_core.c | 3 +--
>>>   2 files changed, 2 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
>>> index 0c5a143025af..121a53338e44 100644
>>> --- a/drivers/pci/pcie/err.c
>>> +++ b/drivers/pci/pcie/err.c
>>> @@ -184,7 +184,6 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev 
>>> *dev,
>>>       int type = pci_pcie_type(dev);
>>>       struct pci_dev *bridge;
>>>       pci_ers_result_t status = PCI_ERS_RESULT_CAN_RECOVER;
>>> -    struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
>>>       /*
>>>        * If the error was detected by a Root Port, Downstream Port, 
>>> RCEC,
>>> @@ -243,7 +242,7 @@ pci_ers_result_t pcie_do_recovery(struct pci_dev 
>>> *dev,
>>>        * it is responsible for clearing this status.  In that case, the
>>>        * signaling device may not even be visible to the OS.
>>>        */
>>> -    if (host->native_aer || pcie_ports_native) {
>>> +    if (pcie_aer_is_native(dev)) {
>>>           pcie_clear_device_status(dev);
>>>           pci_aer_clear_nonfatal_status(dev);
>>>       }
>>> diff --git a/drivers/pci/pcie/portdrv_core.c 
>>> b/drivers/pci/pcie/portdrv_core.c
>>> index 604feeb84ee4..98c18f4a01b2 100644
>>> --- a/drivers/pci/pcie/portdrv_core.c
>>> +++ b/drivers/pci/pcie/portdrv_core.c
>>> @@ -221,8 +221,7 @@ static int get_port_device_capability(struct 
>>> pci_dev *dev)
>>>       }
>>>   #ifdef CONFIG_PCIEAER
>>> -    if (dev->aer_cap && pci_aer_available() &&
>>> -        (pcie_ports_native || host->native_aer)) {
>>> +    if (pcie_aer_is_native(dev) && pci_aer_available()) {
>>>           services |= PCIE_PORT_SERVICE_AER;
>>>           /*
>>
> 
> Thanks,
> Zhuo Chen
Kuppuswamy Sathyanarayanan Aug. 2, 2022, 10:18 p.m. UTC | #4
On 7/27/22 2:37 AM, Zhuo Chen wrote:
>>
> Do you mean changing "if ((host->native_aer || pcie_ports_native) && aer)" into "if (pcie_aer_is_native(dev) && aer)" ?
> I thought changing into "if (pcie_aer_is_native(dev))" before.
> 
> One another doubt. Not every pci device support aer. When dev->aer_cap is NULL and root->aer_cap is not NULL in aer_root_reset(), pcie_aer_is_native() will return false and OS cannot operate root register. It's different from just using "(host->native_aer || pcie_ports_native)".
> 
> Or we can change "if ((host->native_aer || pcie_ports_native) && aer)" into "if (pcie_aer_is_native(root))". But in this way, argument NULL pointer check should be added in pcie_aer_is_native().

Looking into it again, I think it is better to leave it as it is. Please ignore my comment.
Zhuo Chen Aug. 12, 2022, 9:27 a.m. UTC | #5
On 8/3/22 6:18 AM, Sathyanarayanan Kuppuswamy wrote:
> 
> 
> On 7/27/22 2:37 AM, Zhuo Chen wrote:
>>>
>> Do you mean changing "if ((host->native_aer || pcie_ports_native) && aer)" into "if (pcie_aer_is_native(dev) && aer)" ?
>> I thought changing into "if (pcie_aer_is_native(dev))" before.
>>
>> One another doubt. Not every pci device support aer. When dev->aer_cap is NULL and root->aer_cap is not NULL in aer_root_reset(), pcie_aer_is_native() will return false and OS cannot operate root register. It's different from just using "(host->native_aer || pcie_ports_native)".
>>
>> Or we can change "if ((host->native_aer || pcie_ports_native) && aer)" into "if (pcie_aer_is_native(root))". But in this way, argument NULL pointer check should be added in pcie_aer_is_native().
> 
> Looking into it again, I think it is better to leave it as it is. Please ignore my comment.
> 

Thanks! Is there anything else to improve and what's next for
the patch v3 ?
diff mbox series

Patch

diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c
index 0c5a143025af..121a53338e44 100644
--- a/drivers/pci/pcie/err.c
+++ b/drivers/pci/pcie/err.c
@@ -184,7 +184,6 @@  pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	int type = pci_pcie_type(dev);
 	struct pci_dev *bridge;
 	pci_ers_result_t status = PCI_ERS_RESULT_CAN_RECOVER;
-	struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
 
 	/*
 	 * If the error was detected by a Root Port, Downstream Port, RCEC,
@@ -243,7 +242,7 @@  pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
 	 * it is responsible for clearing this status.  In that case, the
 	 * signaling device may not even be visible to the OS.
 	 */
-	if (host->native_aer || pcie_ports_native) {
+	if (pcie_aer_is_native(dev)) {
 		pcie_clear_device_status(dev);
 		pci_aer_clear_nonfatal_status(dev);
 	}
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index 604feeb84ee4..98c18f4a01b2 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -221,8 +221,7 @@  static int get_port_device_capability(struct pci_dev *dev)
 	}
 
 #ifdef CONFIG_PCIEAER
-	if (dev->aer_cap && pci_aer_available() &&
-	    (pcie_ports_native || host->native_aer)) {
+	if (pcie_aer_is_native(dev) && pci_aer_available()) {
 		services |= PCIE_PORT_SERVICE_AER;
 
 		/*