Skip to contentSkip to conversation

pci: fix memory leak when virtio pci hotplug

PATCH In review Zhiqiang Liu 3 participants 5 messages Mar 21, 2021 – Mar 25, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: fix memory leak when virtio pci hotplug

From: Feilong Lin <[email protected]>

Repeated hot-plugging of pci devices for a virtual machine driven by virtio, we found that there is a leak in kmalloc-4k, which was confirmed as the memory of the pci_device structure. Then we found out that it was missing pci_dev_put() after pci_get_slot() in enable_slot() of acpiphp_glue.c.

---
 drivers/pci/hotplug/acpiphp_glue.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/hotplug/acpiphp_glue.c +1 -0
index 3365c93abf0e..f031302ad401 100644
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
 			slot->flags &= ~SLOT_ENABLED;
 			continue;
 		}
+		pci_dev_put(dev);
 	}
 }
 
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Zhiqiang Liu

From: Feilong Lin <[email protected]>

Repeated hot-plugging of pci devices for a virtual machine driven by virtio, we found that there is a leak in kmalloc-4k, which was confirmed as the memory of the pci_device structure. Then we found out that it was missing pci_dev_put() after pci_get_slot() in enable_slot() of acpiphp_glue.c.

---
  drivers/pci/hotplug/acpiphp_glue.c | 1 +
  1 file changed, 1 insertion(+)
drivers/pci/hotplug/acpiphp_glue.c +0 -0
index 3365c93abf0e..f031302ad401 100644

drivers/pci/hotplug/acpiphp_glue.c static void enable_slot(struct acpiphp_slot *slot, bool bridge) · line 539

Quoted 7 lines
drivers/pci/hotplug/acpiphp_glue.c +1 -0
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
  			slot->flags &= ~SLOT_ENABLED;
  			continue;
  		}
+		pci_dev_put(dev);
  	}
  }
 
#2 lore raw

friendly ping..

Quoted 31 lines · Wu Bo
Quoted 20 lines · Zhiqiang Liu

From: Feilong Lin <[email protected]>

Repeated hot-plugging of pci devices for a virtual machine driven by virtio, we found that there is a leak in kmalloc-4k, which was confirmed as the memory of the pci_device structure. Then we found out that it was missing pci_dev_put() after pci_get_slot() in enable_slot() of acpiphp_glue.c.

---
  drivers/pci/hotplug/acpiphp_glue.c | 1 +

  1 file changed, 1 insertion(+)
drivers/pci/hotplug/acpiphp_glue.c +0 -0
index 3365c93abf0e..f031302ad401 100644

drivers/pci/hotplug/acpiphp_glue.c static void enable_slot(struct acpiphp_slot *slot, bool bridge) · line 539

Quoted 7 lines
drivers/pci/hotplug/acpiphp_glue.c +1 -0
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
               slot->flags &= ~SLOT_ENABLED;
               continue;
           }
+        pci_dev_put(dev);
       }
   }
 

.

#3 lore raw
In reply to Zhiqiang Liu
Quoted 11 lines · Zhiqiang Liu

From: Feilong Lin <[email protected]>

Repeated hot-plugging of pci devices for a virtual machine driven by virtio, we found that there is a leak in kmalloc-4k, which was confirmed as the memory of the pci_device structure. Then we found out that it was missing pci_dev_put() after pci_get_slot() in enable_slot() of acpiphp_glue.c.

Since this came from you, Zhiqiang, it needs a signed-off-by (not just a reviewed-by) from you. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=v5.11#n361

Also see
https://lore.kernel.org/r/[email protected]
and

- Wrap commit log to fill 80 columns
- s/pci/PCI/ (subject and commit log)
- Run "git log --oneline drivers/pci/hotplug/acpiphp_glue.c". It's not completely consistent, but at least match the style of one of them.

There is no "pci_device" structure. I think you mean the "struct pci_dev".

The commit log doesn't actually say what the patch does. It's obvious from the patch, but it should say in the commit log. Look at previous commit logs to see how they do it.

Quoted 20 lines
---
 drivers/pci/hotplug/acpiphp_glue.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/hotplug/acpiphp_glue.c +1 -0
index 3365c93abf0e..f031302ad401 100644
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
 			slot->flags &= ~SLOT_ENABLED;
 			continue;
 		}
+		pci_dev_put(dev);
 	}
 }
 
Signature · 1 line
2.19.1
#4 lore raw

Thanks for your suggestion.

I will rewrite the commit log and send the v2 patch.

Quoted 54 lines · Bjorn Helgaas
Quoted 11 lines · Zhiqiang Liu

From: Feilong Lin <[email protected]>

Repeated hot-plugging of pci devices for a virtual machine driven by virtio, we found that there is a leak in kmalloc-4k, which was confirmed as the memory of the pci_device structure. Then we found out that it was missing pci_dev_put() after pci_get_slot() in enable_slot() of acpiphp_glue.c.

Since this came from you, Zhiqiang, it needs a signed-off-by (not just a reviewed-by) from you. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=v5.11#n361

Also see
https://lore.kernel.org/r/[email protected]
and

- Wrap commit log to fill 80 columns
- s/pci/PCI/ (subject and commit log)
- Run "git log --oneline drivers/pci/hotplug/acpiphp_glue.c". It's not completely consistent, but at least match the style of one of them.

There is no "pci_device" structure. I think you mean the "struct pci_dev".

The commit log doesn't actually say what the patch does. It's obvious from the patch, but it should say in the commit log. Look at previous commit logs to see how they do it.

Quoted 20 lines
---
 drivers/pci/hotplug/acpiphp_glue.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/hotplug/acpiphp_glue.c +1 -0
index 3365c93abf0e..f031302ad401 100644
@@ -533,6 +533,7 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
 			slot->flags &= ~SLOT_ENABLED;
 			continue;
 		}
+		pci_dev_put(dev);
 	}
 }
 
Signature · 1 line
2.19.1

.