Skip to contentSkip to conversation

PCI: merge slot and bus reset implementations

PATCH Superseded Raphael Norwitz 5 participants 14 messages Apr 1, 2021 – Apr 8, 2021 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: merge slot and bus reset implementations

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +9 -8
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;
+}
+
 static void pci_dev_lock(struct pci_dev *dev)
 {
 	pci_cfg_access_lock(dev);
@@ -5102,10 +5109,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)
 	rc = pci_pm_reset(dev, 0);
 	if (rc != -ENOTTY)
 		return rc;
-	rc = pci_dev_reset_slot_function(dev, 0);
-	if (rc != -ENOTTY)
-		return rc;
-	return pci_parent_bus_reset(dev, 0);
+	return pci_reset_bus_function(dev, 0);
 }
 EXPORT_SYMBOL_GPL(__pci_reset_function_locked);
 
@@ -5135,13 +5139,10 @@ int pci_probe_reset_function(struct pci_dev *dev)
 	if (rc != -ENOTTY)
 		return rc;
 	rc = pci_pm_reset(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-	rc = pci_dev_reset_slot_function(dev, 1);
 	if (rc != -ENOTTY)
 		return rc;
 
-	return pci_parent_bus_reset(dev, 1);
+	return pci_reset_bus_function(dev, 1);
 }
 
 /**
include/linux/pci.h +1 -0
index 86c799c97b77..979d54335ac1 100644
@@ -1228,6 +1228,7 @@ int pci_probe_reset_bus(struct pci_bus *bus);
 int pci_reset_bus(struct pci_dev *dev);
 void pci_reset_secondary_bus(struct pci_dev *dev);
 void pcibios_reset_secondary_bus(struct pci_dev *dev);
+int pci_reset_bus_function(struct pci_dev *dev, int probe);
 void pci_update_resource(struct pci_dev *dev, int resno);
 int __must_check pci_assign_resource(struct pci_dev *dev, int i);
 int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 27 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 8 lines
drivers/pci/pci.c +5 -0
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 46 lines
drivers/pci/pci.c +4 -8
+}
+
 static void pci_dev_lock(struct pci_dev *dev)
 {
 	pci_cfg_access_lock(dev);
@@ -5102,10 +5109,7 @@ int __pci_reset_function_locked(struct pci_dev *dev)
 	rc = pci_pm_reset(dev, 0);
 	if (rc != -ENOTTY)
 		return rc;
-	rc = pci_dev_reset_slot_function(dev, 0);
-	if (rc != -ENOTTY)
-		return rc;
-	return pci_parent_bus_reset(dev, 0);
+	return pci_reset_bus_function(dev, 0);
 }
 EXPORT_SYMBOL_GPL(__pci_reset_function_locked);
 
@@ -5135,13 +5139,10 @@ int pci_probe_reset_function(struct pci_dev *dev)
 	if (rc != -ENOTTY)
 		return rc;
 	rc = pci_pm_reset(dev, 1);
-	if (rc != -ENOTTY)
-		return rc;
-	rc = pci_dev_reset_slot_function(dev, 1);
 	if (rc != -ENOTTY)
 		return rc;
 
-	return pci_parent_bus_reset(dev, 1);
+	return pci_reset_bus_function(dev, 1);
 }
 
 /**
include/linux/pci.h +1 -0
index 86c799c97b77..979d54335ac1 100644
@@ -1228,6 +1228,7 @@ int pci_probe_reset_bus(struct pci_bus *bus);
 int pci_reset_bus(struct pci_dev *dev);
 void pci_reset_secondary_bus(struct pci_dev *dev);
 void pcibios_reset_secondary_bus(struct pci_dev *dev);
+int pci_reset_bus_function(struct pci_dev *dev, int probe);
 void pci_update_resource(struct pci_dev *dev, int resno);
 int __must_check pci_assign_resource(struct pci_dev *dev, int i);
 int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
Signature · 1 line
2.20.1
#2 lore raw
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;  

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

Alex

#3 lore raw
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;  

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Thanks

Quoted 3 lines

Alex

#4 lore raw
Quoted 48 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 42 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 27 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 8 lines
drivers/pci/pci.c +5 -0
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;    

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 5 lines
Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

#5 lore raw
Quoted 54 lines · Alex Williamson
Quoted 51 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 49 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;    

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

Quoted 6 lines
Quoted 2 lines

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

#6 lore raw

[+cc Greg for visibility]

Hello,

[...]

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

The only person who ever pulled my ear, so to speak, over using ternary was Greg as a bad style where, especially where it does not need to be used.

But, I digress. I humbly think that we should move back on track and finish review of Raphael's patch. Would use a ternary here be a show-stopper?

Krzysztof

#7 lore raw
Quoted 22 lines · Krzysztof Wilczyński

[+cc Greg for visibility]

Hello,

[...]

Quoted 17 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 5 lines
Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

Quoted 5 lines
Quoted 1 line

It is up to us where this bar is set.

The only person who ever pulled my ear, so to speak, over using ternary was Greg as a bad style where, especially where it does not need to be used.

Good to hear that I'm not alone.

Quoted 4 lines

But, I digress. I humbly think that we should move back on track and finish review of Raphael's patch. Would use a ternary here be a show-stopper?

Of course no, I would fix it locally when apply.

Thanks

Quoted 2 lines

Krzysztof

#8 lore raw
In reply to Leon Romanovsky
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Thanks,
Amey

#9 lore raw
Quoted 72 lines · On Wed, Apr 07, 2021 at 01:53:56PM +0530, [email protected] wrote:
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

Quoted 7 lines

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Did you look when they were introduced?

Thanks

Quoted 3 lines

Thanks,
Amey

#10 lore raw
Quoted 77 lines · Leon Romanovsky
Quoted 76 lines · On Wed, Apr 07, 2021 at 01:53:56PM +0530, [email protected] wrote:
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;
Quoted 8 lines
Quoted 3 lines

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Did you look when they were introduced?

Thanks

that code trace_kprobe in 2 years old.
If you want more recent example checkout drivers/pci/controller/pcie-brcmstb.c:1112,1117:
return pcie->rescal ? brcm_phy_cntl(pcie, 1) : 0; which was introduced 7 months ago.
There are lot of examples in pci.c also.

Thanks,
Amey

#11 lore raw
Quoted 84 lines · On Wed, Apr 07, 2021 at 06:36:01PM +0530, [email protected] wrote:
Quoted 83 lines · Leon Romanovsky
Quoted 72 lines · On Wed, Apr 07, 2021 at 01:53:56PM +0530, [email protected] wrote:
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

Quoted 7 lines

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Did you look when they were introduced?

Quoted 8 lines
Quoted 2 lines

Thanks

that code trace_kprobe in 2 years old.
If you want more recent example checkout drivers/pci/controller/pcie-brcmstb.c:1112,1117:
return pcie->rescal ? brcm_phy_cntl(pcie, 1) : 0; which was introduced 7 months ago.
There are lot of examples in pci.c also.

Yeah, I know, copy-paste is a powerful tool.

Can we please progress with this patch instead of doing archaeological research?

Thanks

Quoted 3 lines

Thanks,
Amey

#12 lore raw
Quoted 94 lines · Leon Romanovsky
Quoted 84 lines · On Wed, Apr 07, 2021 at 06:36:01PM +0530, [email protected] wrote:
Quoted 83 lines · Leon Romanovsky
Quoted 72 lines · On Wed, Apr 07, 2021 at 01:53:56PM +0530, [email protected] wrote:
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

Quoted 7 lines

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Did you look when they were introduced?

Quoted 8 lines
Quoted 2 lines

Thanks

that code trace_kprobe in 2 years old.
If you want more recent example checkout drivers/pci/controller/pcie-brcmstb.c:1112,1117:
return pcie->rescal ? brcm_phy_cntl(pcie, 1) : 0; which was introduced 7 months ago.
There are lot of examples in pci.c also.

Quoted 7 lines

Yeah, I know, copy-paste is a powerful tool.

Can we please progress with this patch instead of doing archaeological research?

Thanks

Sorry I didn't understand what you said.

Thanks,
Amey

#13 lore raw
In reply to Leon Romanovsky
Quoted 94 lines · Leon Romanovsky
Quoted 84 lines · On Wed, Apr 07, 2021 at 06:36:01PM +0530, [email protected] wrote:
Quoted 83 lines · Leon Romanovsky
Quoted 72 lines · On Wed, Apr 07, 2021 at 01:53:56PM +0530, [email protected] wrote:
Quoted 58 lines · Leon Romanovsky
Quoted 57 lines · Alex Williamson
Quoted 53 lines · On Sun, 4 Apr 2021 11:04:32 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 47 lines · Alex Williamson
Quoted 31 lines · On Thu, 1 Apr 2021 15:27:37 +0300 Leon Romanovsky <[email protected]> wrote:
Quoted 30 lines · Raphael Norwitz

Slot resets are bus resets with additional logic to prevent a device from being removed during the reset. Currently slot and bus resets have separate implementations in pci.c, complicating higher level logic. As discussed on the mailing list, they should be combined into a generic function which performs an SBR. This change adds a function, pci_reset_bus_function(), which first attempts a slot reset and then attempts a bus reset if -ENOTTY is returned, such that there is now a single device agnostic function to perform an SBR.

This new function is also needed to add SBR reset quirks and therefore is exposed in pci.h.

---
 drivers/pci/pci.c   | 17 +++++++++--------
 include/linux/pci.h |  1 +
 2 files changed, 10 insertions(+), 8 deletions(-)
drivers/pci/pci.c +0 -0
index 16a17215f633..12a91af2ade4 100644
@@ -4982,6 +4982,13 @@ static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
 	return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
 }
 
Quoted 11 lines

drivers/pci/pci.c static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) · line 4989

Quoted 5 lines
drivers/pci/pci.c +5 -0
+int pci_reset_bus_function(struct pci_dev *dev, int probe)
+{
+	int rc = pci_dev_reset_slot_function(dev, probe);
+
+	return (rc == -ENOTTY) ? pci_parent_bus_reset(dev, probe) : rc;

The previous coding style is preferable one in the Linux kernel. int rc = pci_dev_reset_slot_function(dev, probe);
if (rc != -ENOTTY)
return rc;
return pci_parent_bus_reset(dev, probe);

Quoted 2 lines

That'd be news to me, do you have a reference? I've never seen complaints for ternaries previously. Thanks,

The complaint is not to ternaries, but to the function call as one of the parameters, that makes it harder to read.

Quoted 7 lines
Quoted 3 lines

Sorry, I don't find a function call as a parameter to a ternary to be extraordinary, nor do I find it to be a discouraged usage model within the kernel. This seems like a pretty low bar for hard to read code.

It is up to us where this bar is set.

Thanks

On the side note there are plenty of places where this pattern is used though
for example -
kernel/time/clockevents.c:328:
return force ? clockevents_program_min_delta(dev) : -ETIME;

Quoted 7 lines

kernel/trace/trace_kprobe.c:233:
return tk ? within_error_injection_list(trace_kprobe_address(tk)) :

       false;

kernel/signal.c:3104:
return oset ? put_compat_sigset(oset, &old_set, sizeof(*oset)) : 0; etc

Did you look when they were introduced?

Quoted 8 lines
Quoted 2 lines

Thanks

that code trace_kprobe in 2 years old.
If you want more recent example checkout drivers/pci/controller/pcie-brcmstb.c:1112,1117:
return pcie->rescal ? brcm_phy_cntl(pcie, 1) : 0; which was introduced 7 months ago.
There are lot of examples in pci.c also.

Quoted 7 lines

Yeah, I know, copy-paste is a powerful tool.

Can we please progress with this patch instead of doing archaeological research?

Thanks

I don't have a strong view on the style guidelines being discussed here.

I just sent a V2 replacing the ternary function parameter with your suggestion.

Quoted 3 lines
Quoted 3 lines

Thanks,
Amey