fbdev: hyperv_fb: Fix hang in kdump kernel when on Hyper-V Gen 2 VMs
PATCH 1/1 fbdev: hyperv_fb: Fix hang in kdump kernel when on Hyper-V Gen 2 VMs
From: Michael Kelley <[email protected]>
Gen 2 Hyper-V VMs boot via EFI and have a standard EFI framebuffer device. When the kdump kernel runs in such a VM, loading the efifb driver may hang because of accessing the framebuffer at the wrong memory address.
The scenario occurs when the hyperv_fb driver in the original kernel moves the framebuffer to a different MMIO address because of conflicts with an already-running efifb or simplefb driver. The hyperv_fb driver then informs Hyper-V of the change, which is allowed by the Hyper-V FB VMBus device protocol. However, when the kexec command loads the kdump kernel into crash memory via the kexec_file_load() system call, the system call doesn't know the framebuffer has moved, and it sets up the kdump screen_info using the original framebuffer address. The transition to the kdump kernel does not go through the Hyper-V host, so Hyper-V does not reset the framebuffer address like it would do on a reboot. When efifb tries to run, it accesses a non-existent framebuffer address, which traps to the Hyper-V host. After many such accesses, the Hyper-V host thinks the guest is being malicious, and throttles the guest to the point that it runs very slowly or appears to have hung.
When the kdump kernel is loaded into crash memory via the kexec_load() system call, the problem does not occur. In this case, the kexec command builds the screen_info table itself in user space from data returned by the FBIOGET_FSCREENINFO ioctl against /dev/fb0, which gives it the new framebuffer location.
This problem was originally reported in 2020 [1], resulting in commit 3cb73bc3fa2a ("hyperv_fb: Update screen_info after removing old framebuffer"). This commit solved the problem by setting orig_video_isVGA to 0, so the kdump kernel was unaware of the EFI framebuffer. The efifb driver did not try to load, and no hang occurred. But in 2024, commit c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info") effectively reverted 3cb73bc3fa2a. Commit c25a19afb81c has no reference to 3cb73bc3fa2a, so perhaps it was done without knowing the implications that were reported with 3cb73bc3fa2a. In any case, as of commit c25a19afb81c, the original problem came back again.
Interestingly, the hyperv_drm driver does not have this problem because it never moves the framebuffer. The difference is that the hyperv_drm driver removes any conflicting framebuffers *before* allocating an MMIO address, while the hyperv_fb drivers removes conflicting framebuffers *after* allocating an MMIO address. With the "after" ordering, hyperv_fb may encounter a conflict and move the framebuffer to a different MMIO address. But the conflict is essentially bogus because it is removed a few lines of code later.
Rather than fix the problem with the approach from 2020 in commit 3cb73bc3fa2a, instead slightly reorder the steps in hyperv_fb so conflicting framebuffers are removed before allocating an MMIO address. Then the default framebuffer MMIO address should always be available, and there's never any confusion about which framebuffer address the kdump kernel should use -- it's always the original address provided by the Hyper-V host. This approach is already used by the hyperv_drm driver, and is consistent with the usage guidelines at the head of the module with the function aperture_remove_conflicting_devices().
This approach also solves a related minor problem when kexec_load() is used to load the kdump kernel. With current code, unbinding and rebinding the hyperv_fb driver could result in the framebuffer moving back to the default framebuffer address, because on the rebind there are no conflicts. If such a move is done after the kdump kernel is loaded with the new framebuffer address, at kdump time it could again have the wrong address.
This problem and fix are described in terms of the kdump kernel, but it can also occur with any kernel started via kexec.
See extensive discussion of the problem and solution at [2].
[1] https://lore.kernel.org/linux-hyperv/[email protected]/
[2] https://lore.kernel.org/linux-hyperv/BLAPR10MB521793485093FDB448F7B2E5FDE92@BLAPR10MB5217.namprd10.prod.outlook.com/
---
The "Fixes" tag uses commit c25a19afb81c because that's where the problem was re-exposed, and how far back a stable backport is needed. But I've taken a completely different, and hopefully better, approach in the solution that isn't related to the code changes in c25a19afb81c.
drivers/video/fbdev/hyperv_fb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/video/fbdev/hyperv_fb.c +13 -7
@@ -989,6 +989,7 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) base =pci_resource_start (pdev,0 ); size =pci_resource_len (pdev,0 ); +aperture_remove_conflicting_devices (base, size,KBUILD_MODNAME );/* * For Gen 1 VM, we can directly use the contiguous memory
@@ -1010,11 +1011,21 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) goto getmem_done; }pr_info ("Unable to allocate enough contiguous physical memory on Gen 1 VM. Using MMIO instead.\n" ); + }else { +aperture_remove_all_conflicting_devices (KBUILD_MODNAME ); }/* -* Cannot use the contiguous physical memory. -* Allocate mmio space for framebuffer. +* Cannot use contiguous physical memory, so allocate MMIO space for +* the framebuffer. At this point in the function, conflicting devices +* that might have claimed the framebuffer MMIO space based on +* screen_info.lfb_base must have already been removed so that +* vmbus_allocate_mmio() does not allocate different MMIO space. If the +* kdump image were to be loaded using kexec_file_load(), the +* framebuffer location in the kdump image would be set from +* screen_info.lfb_base at the time that kdump is enabled. If the +* framebuffer has moved elsewhere, this could be the wrong location, +* causing kdump to hang when efifb (for example) loads. */ dio_fb_size = screen_width * screen_height * screen_depth /8 ;
@@ -1051,11 +1062,6 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info) info->screen_size = dio_fb_size; getmem_done: -if (base && size) -aperture_remove_conflicting_devices (base, size,KBUILD_MODNAME ); -else -aperture_remove_all_conflicting_devices (KBUILD_MODNAME ); -if (!gen2vm)pci_dev_put (pdev);
Signature · 1 line
2.25.1
Quoted 77 lines · On 2/19/25 00:01, [email protected] wrote:
From: Michael Kelley <[email protected]>
Gen 2 Hyper-V VMs boot via EFI and have a standard EFI framebuffer device. When the kdump kernel runs in such a VM, loading the efifb driver may hang because of accessing the framebuffer at the wrong memory address.
The scenario occurs when the
hyperv_fbdriver in the original kernel moves the framebuffer to a different MMIO address because of conflicts with an already-running efifb or simplefb driver. Thehyperv_fbdriver then informs Hyper-V of the change, which is allowed by the Hyper-V FB VMBus device protocol. However, when the kexec command loads the kdump kernel into crash memory via thekexec_file_load()system call, the system call doesn't know the framebuffer has moved, and it sets up the kdumpscreen_infousing the original framebuffer address. The transition to the kdump kernel does not go through the Hyper-V host, so Hyper-V does not reset the framebuffer address like it would do on a reboot. When efifb tries to run, it accesses a non-existent framebuffer address, which traps to the Hyper-V host. After many such accesses, the Hyper-V host thinks the guest is being malicious, and throttles the guest to the point that it runs very slowly or appears to have hung.When the kdump kernel is loaded into crash memory via the
kexec_load()system call, the problem does not occur. In this case, the kexec command builds thescreen_infotable itself in user space from data returned by theFBIOGET_FSCREENINFOioctl against/dev/fb0, which gives it the new framebuffer location.This problem was originally reported in 2020 [1], resulting in commit
3cb73bc3fa2a("hyperv_fb: Updatescreen_infoafter removing old framebuffer"). This commit solved the problem by settingorig_video_isVGAto 0, so the kdump kernel was unaware of the EFI framebuffer. The efifb driver did not try to load, and no hang occurred. But in 2024, commitc25a19afb81c("fbdev/hyperv_fb: Do not clear globalscreen_info") effectively reverted3cb73bc3fa2a. Commitc25a19afb81chas no reference to3cb73bc3fa2a, so perhaps it was done without knowing the implications that were reported with3cb73bc3fa2a. In any case, as of commitc25a19afb81c, the original problem came back again.Interestingly, the
hyperv_drmdriver does not have this problem because it never moves the framebuffer. The difference is that thehyperv_drmdriver removes any conflicting framebuffers *before* allocating an MMIO address, while thehyperv_fbdrivers removes conflicting framebuffers *after* allocating an MMIO address. With the "after" ordering,hyperv_fbmay encounter a conflict and move the framebuffer to a different MMIO address. But the conflict is essentially bogus because it is removed a few lines of code later.Rather than fix the problem with the approach from 2020 in commit
3cb73bc3fa2a, instead slightly reorder the steps inhyperv_fbso conflicting framebuffers are removed before allocating an MMIO address. Then the default framebuffer MMIO address should always be available, and there's never any confusion about which framebuffer address the kdump kernel should use -- it's always the original address provided by the Hyper-V host. This approach is already used by thehyperv_drmdriver, and is consistent with the usage guidelines at the head of the module with the functionaperture_remove_conflicting_devices().This approach also solves a related minor problem when
kexec_load()is used to load the kdump kernel. With current code, unbinding and rebinding thehyperv_fbdriver could result in the framebuffer moving back to the default framebuffer address, because on the rebind there are no conflicts. If such a move is done after the kdump kernel is loaded with the new framebuffer address, at kdump time it could again have the wrong address.This problem and fix are described in terms of the kdump kernel, but it can also occur with any kernel started via kexec.
See extensive discussion of the problem and solution at [2].
[1] https://lore.kernel.org/linux-hyperv/[email protected]/
[2] https://lore.kernel.org/linux-hyperv/BLAPR10MB521793485093FDB448F7B2E5FDE92@BLAPR10MB5217.namprd10.prod.outlook.com/Reported-by Thomas Tai <[email protected]>Fixes c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info")Signed-off-by Michael Kelley <[email protected]>
Quoted 8 lines
---
The "Fixes" tag uses commitc25a19afb81cbecause that's where the problem was re-exposed, and how far back a stable backport is needed. But I've taken a completely different, and hopefully better, approach in the solution that isn't related to the code changes inc25a19afb81c.drivers/video/fbdev/hyperv_fb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
applied to fbdev tree.
Thanks!
Helge
From: Helge Deller <[email protected]> Sent: Saturday, March 8, 2025 6:59 PM
Quoted 4 lines · On 2/19/25 00:01, [email protected] wrote:
Quoted 2 lines
From: Michael Kelley <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Reported-by Thomas Tai <[email protected]>Fixes c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info")Signed-off-by Michael Kelley <[email protected]>---
The "Fixes" tag uses commitc25a19afb81cbecause that's where the problem was re-exposed, and how far back a stable backport is needed. But I've taken a completely different, and hopefully better, approach in the solution that isn't related to the code changes inc25a19afb81c.
Quoted 5 lines
Quoted 2 lines
drivers/video/fbdev/hyperv_fb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)applied to fbdev tree.
Thank you!
Related, I noticed the patch "fbdev: hyperv_fb: iounmap() the correct memory when removing a device" is also in the fbdev for-next branch. Wei Liu previously applied this patch to the hyperv-fixes tree (see [1]) and it's already in linux-next. Won't having it also in fbdev produce a merge conflict?
Michael
[1] https://lore.kernel.org/linux-hyperv/Z6wHDw8BssJyQHiM@liuwe-devbox-debian-v2/
Helge Deller
maintainerQuoted 23 lines · Michael Kelley
From: Helge Deller <[email protected]> Sent: Saturday, March 8, 2025 6:59 PM
Quoted 4 lines · On 2/19/25 00:01, [email protected] wrote:
Quoted 2 lines
From: Michael Kelley <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Reported-by Thomas Tai <[email protected]>Fixes c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info")Signed-off-by Michael Kelley <[email protected]>---
The "Fixes" tag uses commitc25a19afb81cbecause that's where the problem was re-exposed, and how far back a stable backport is needed. But I've taken a completely different, and hopefully better, approach in the solution that isn't related to the code changes inc25a19afb81c.Quoted 5 lines
Quoted 2 lines
drivers/video/fbdev/hyperv_fb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)applied to fbdev tree.
Quoted 8 lines
Thank you!
Related, I noticed the patch "fbdev:
hyperv_fb:iounmap()the correct memory when removing a device" is also in the fbdev for-next branch. Wei Liu previously applied this patch to the hyperv-fixes tree (see [1]) and it's already in linux-next. Won't having it also in fbdev produce a merge conflict?
[1] https://lore.kernel.org/linux-hyperv/Z6wHDw8BssJyQHiM@liuwe-devbox-debian-v2/
Thanks Michael!
I now dropped that patch from the fbdev tree to avoid collisions.
Btw, I'm fine if we agree that all hyperv-fbdev fixes & patches go through hyperv or other trees. Just let me know.
Helge
Wei Liu
maintainerQuoted 33 lines · Helge Deller
Quoted 23 lines · Michael Kelley
From: Helge Deller <[email protected]> Sent: Saturday, March 8, 2025 6:59 PM
Quoted 4 lines · On 2/19/25 00:01, [email protected] wrote:
Quoted 2 lines
From: Michael Kelley <[email protected]>
[snip]
Quoted 10 lines
Quoted 10 lines
Reported-by Thomas Tai <[email protected]>Fixes c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info")Signed-off-by Michael Kelley <[email protected]>---
The "Fixes" tag uses commitc25a19afb81cbecause that's where the problem was re-exposed, and how far back a stable backport is needed. But I've taken a completely different, and hopefully better, approach in the solution that isn't related to the code changes inc25a19afb81c.Quoted 5 lines
Quoted 2 lines
drivers/video/fbdev/hyperv_fb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)applied to fbdev tree.
Quoted 8 lines
Thank you!
Related, I noticed the patch "fbdev:
hyperv_fb:iounmap()the correct memory when removing a device" is also in the fbdev for-next branch. Wei Liu previously applied this patch to the hyperv-fixes tree (see [1]) and it's already in linux-next. Won't having it also in fbdev produce a merge conflict?
[1] https://lore.kernel.org/linux-hyperv/Z6wHDw8BssJyQHiM@liuwe-devbox-debian-v2/
Quoted 5 lines
Thanks Michael!
I now dropped that patch from the fbdev tree to avoid collisions.Btw, I'm fine if we agree that all hyperv-fbdev fixes & patches go through hyperv or other trees. Just let me know.
I can pick up all hyperv-fbdev patches in the future. Thanks Helge.
Wei.
Quoted 2 lines
Helge
Quoted 69 lines · On Tue, Feb 18, 2025 at 03:01:30PM -0800, [email protected] wrote:
From: Michael Kelley <[email protected]>
Gen 2 Hyper-V VMs boot via EFI and have a standard EFI framebuffer device. When the kdump kernel runs in such a VM, loading the efifb driver may hang because of accessing the framebuffer at the wrong memory address.
The scenario occurs when the
hyperv_fbdriver in the original kernel moves the framebuffer to a different MMIO address because of conflicts with an already-running efifb or simplefb driver. Thehyperv_fbdriver then informs Hyper-V of the change, which is allowed by the Hyper-V FB VMBus device protocol. However, when the kexec command loads the kdump kernel into crash memory via thekexec_file_load()system call, the system call doesn't know the framebuffer has moved, and it sets up the kdumpscreen_infousing the original framebuffer address. The transition to the kdump kernel does not go through the Hyper-V host, so Hyper-V does not reset the framebuffer address like it would do on a reboot. When efifb tries to run, it accesses a non-existent framebuffer address, which traps to the Hyper-V host. After many such accesses, the Hyper-V host thinks the guest is being malicious, and throttles the guest to the point that it runs very slowly or appears to have hung.When the kdump kernel is loaded into crash memory via the
kexec_load()system call, the problem does not occur. In this case, the kexec command builds thescreen_infotable itself in user space from data returned by theFBIOGET_FSCREENINFOioctl against/dev/fb0, which gives it the new framebuffer location.This problem was originally reported in 2020 [1], resulting in commit
3cb73bc3fa2a("hyperv_fb: Updatescreen_infoafter removing old framebuffer"). This commit solved the problem by settingorig_video_isVGAto 0, so the kdump kernel was unaware of the EFI framebuffer. The efifb driver did not try to load, and no hang occurred. But in 2024, commitc25a19afb81c("fbdev/hyperv_fb: Do not clear globalscreen_info") effectively reverted3cb73bc3fa2a. Commitc25a19afb81chas no reference to3cb73bc3fa2a, so perhaps it was done without knowing the implications that were reported with3cb73bc3fa2a. In any case, as of commitc25a19afb81c, the original problem came back again.Interestingly, the
hyperv_drmdriver does not have this problem because it never moves the framebuffer. The difference is that thehyperv_drmdriver removes any conflicting framebuffers *before* allocating an MMIO address, while thehyperv_fbdrivers removes conflicting framebuffers *after* allocating an MMIO address. With the "after" ordering,hyperv_fbmay encounter a conflict and move the framebuffer to a different MMIO address. But the conflict is essentially bogus because it is removed a few lines of code later.Rather than fix the problem with the approach from 2020 in commit
3cb73bc3fa2a, instead slightly reorder the steps inhyperv_fbso conflicting framebuffers are removed before allocating an MMIO address. Then the default framebuffer MMIO address should always be available, and there's never any confusion about which framebuffer address the kdump kernel should use -- it's always the original address provided by the Hyper-V host. This approach is already used by thehyperv_drmdriver, and is consistent with the usage guidelines at the head of the module with the functionaperture_remove_conflicting_devices().This approach also solves a related minor problem when
kexec_load()is used to load the kdump kernel. With current code, unbinding and rebinding thehyperv_fbdriver could result in the framebuffer moving back to the default framebuffer address, because on the rebind there are no conflicts. If such a move is done after the kdump kernel is loaded with the new framebuffer address, at kdump time it could again have the wrong address.This problem and fix are described in terms of the kdump kernel, but it can also occur with any kernel started via kexec.
Quoted 8 lines
See extensive discussion of the problem and solution at [2].
[1] https://lore.kernel.org/linux-hyperv/[email protected]/
[2] https://lore.kernel.org/linux-hyperv/BLAPR10MB521793485093FDB448F7B2E5FDE92@BLAPR10MB5217.namprd10.prod.outlook.com/Reported-by Thomas Tai <[email protected]>Fixes c25a19afb81c ("fbdev/hyperv_fb: Do not clear global screen_info")Signed-off-by Michael Kelley <[email protected]>
Applied to hyperv-fixes, thanks!