RE: [PATCH] PCI: hv: Add hv_pci_remove_slots() when we unload the driver

From: Dexuan Cui
Date: Tue Feb 12 2019 - 19:17:47 EST

> From: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
> Sent: Tuesday, February 12, 2019 4:13 AM
> ...
> This patch fixes three bugs:
> 1) set hpdev->pci_slot to NULL
> 2) move code destroying the slot inside a locked region in
> hv_eject_device_work()
> 3) Add missing slots removal code in hv_pci_remove()
> We need three patches, not one.
> (1) and (2), I am not entirely sure we want them in stable kernels,
> since they are potential bugs, waiting for your input.
> Lorenzo

(1) is actually unnecessary, as I suppose hpdev should be freed at a later
place in the same function hv_eject_device_work -> put_pcichild() -> kfree(hpdev).
But today I think I found a refcount bug in the hot-remove case and the "kfree(hpdev)"
is never called in the hot-remove case. I'll further dig into this and make some extra

About (2), it's a race condition that can happen when the device is being hot-removed
and we're unloading the pci-hyperv driver at the same time. This is not a normal usage,
so I agree it doesn't really need to go into the stables.

(3) should go into the stables.

I'll make 3 separate patches, and extra patches for the refcount issue, and possible other
minor issues.

-- Dexuan