• Dexuan Cui's avatar
    PCI: hv: Add hibernation support · ac82fc83
    Dexuan Cui authored
    Add suspend() and resume() functions so that Hyper-V virtual PCI devices
    are handled properly when the VM hibernates and resumes from
    hibernation.
    
    Note that the suspend() function must make sure there are no pending
    work items before calling vmbus_close(), since it runs in a process
    context as a callback in dpm_suspend(). When it starts to run, the
    channel callback hv_pci_onchannelcallback(), which runs in a tasklet
    context, can be still running concurrently and scheduling new work items
    onto hbus->wq in hv_pci_devices_present() and hv_pci_eject_device(), and
    the work item handlers can access the vmbus channel, which can be being
    closed by hv_pci_suspend(), e.g. the work item handler
    pci_devices_present_work() -> new_pcichild_device() writes to the vmbus
    channel.
    
    To eliminate the race, hv_pci_suspend() disables the channel callback
    tasklet, sets hbus->state to hv_pcibus_removing, and re-enables the
    tasklet.  This way, when hv_pci_suspend() proceeds, it knows that no new
    work item can be scheduled, and then it flushes hbus->wq and safely
    closes the vmbus channel.
    Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
    Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
    Reviewed-by: default avatarMichael Kelley <mikelley@microsoft.com>
    ac82fc83
pci-hyperv.c 89.1 KB