android_kernel_xiaomi_sm7250/drivers/hv
Vitaly Kuznetsov c3f8c7e986 Drivers: hv: Never allocate anything besides framebuffer from framebuffer memory region
[ Upstream commit f0880e2cb7e1f8039a048fdd01ce45ab77247221 ]

Passed through PCI device sometimes misbehave on Gen1 VMs when Hyper-V
DRM driver is also loaded. Looking at IOMEM assignment, we can see e.g.

$ cat /proc/iomem
...
f8000000-fffbffff : PCI Bus 0000:00
  f8000000-fbffffff : 0000:00:08.0
    f8000000-f8001fff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe
...
fe0000000-fffffffff : PCI Bus 0000:00
  fe0000000-fe07fffff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe
    fe0000000-fe07fffff : 2ba2:00:02.0
      fe0000000-fe07fffff : mlx4_core

the interesting part is the 'f8000000' region as it is actually the
VM's framebuffer:

$ lspci -v
...
0000:00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller])
	Flags: bus master, fast devsel, latency 0, IRQ 11
	Memory at f8000000 (32-bit, non-prefetchable) [size=64M]
...

 hv_vmbus: registering driver hyperv_drm
 hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Synthvid Version major 3, minor 5
 hyperv_drm 0000:00:08.0: vgaarb: deactivate vga console
 hyperv_drm 0000:00:08.0: BAR 0: can't reserve [mem 0xf8000000-0xfbffffff]
 hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Cannot request framebuffer, boot fb still active?

Note: "Cannot request framebuffer" is not a fatal error in
hyperv_setup_gen1() as the code assumes there's some other framebuffer
device there but we actually have some other PCI device (mlx4 in this
case) config space there!

The problem appears to be that vmbus_allocate_mmio() can use dedicated
framebuffer region to serve any MMIO request from any device. The
semantics one might assume of a parameter named "fb_overlap_ok"
aren't implemented because !fb_overlap_ok essentially has no effect.
The existing semantics are really "prefer_fb_overlap". This patch
implements the expected and needed semantics, which is to not allocate
from the frame buffer space when !fb_overlap_ok.

Note, Gen2 VMs are usually unaffected by the issue because
framebuffer region is already taken by EFI fb (in case kernel supports
it) but Gen1 VMs may have this region unclaimed by the time Hyper-V PCI
pass-through driver tries allocating MMIO space if Hyper-V DRM/FB drivers
load after it. Devices can be brought up in any sequence so let's
resolve the issue by always ignoring 'fb_mmio' region for non-FB
requests, even if the region is unclaimed.

Reviewed-by: Michael Kelley <mikelley@microsoft.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Link: https://lore.kernel.org/r/20220827130345.1320254-4-vkuznets@redhat.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-09-28 11:02:57 +02:00
..
channel_mgmt.c Drivers: hv: vmbus: Expose monitor data only when monitor pages are used 2022-02-23 11:58:41 +01:00
channel.c vmbus: keep pointer to ring buffer page 2019-11-20 18:47:31 +01:00
connection.c Drivers: hv: vmbus: Offload the handling of channels to two workqueues 2018-12-13 09:16:22 +01:00
hv_balloon.c hv_balloon: rate-limit "Unhandled message" warning 2022-04-15 14:14:49 +02:00
hv_fcopy.c Drivers: hv: fcopy: restore correct transfer length 2017-09-22 10:29:54 +02:00
hv_kvp.c Drivers: hv: kvp: Fix the recent regression caused by incorrect clean-up 2019-09-16 08:21:54 +02:00
hv_snapshot.c Merge 4.11-rc4 into char-misc-next 2017-03-27 09:13:04 +02:00
hv_trace_balloon.h hv_balloon: trace post_status 2018-03-06 09:57:17 -08:00
hv_trace.c hv: add SPDX license to trace 2018-03-28 13:24:56 +02:00
hv_trace.h hv: add SPDX license to trace 2018-03-28 13:24:56 +02:00
hv_util.c hv_utils: Fix passing zero to 'PTR_ERR' warning 2021-07-20 16:15:45 +02:00
hv_utils_transport.c vfs: do bulk POLL* -> EPOLL* replacement 2018-02-11 14:34:03 -08:00
hv_utils_transport.h Drivers: hv: util: move waiting for release to hv_utils_transport itself 2017-03-16 16:42:00 +09:00
hv.c random: remove unused irq_flags argument from add_interrupt_randomness() 2022-06-25 11:49:01 +02:00
hyperv_vmbus.h Drivers: hv: vmbus: Expose monitor data only when monitor pages are used 2022-02-23 11:58:41 +01:00
Kconfig x86, hyperv: remove PCI dependency 2019-01-13 09:51:00 +01:00
Makefile hv_balloon: trace post_status 2018-03-06 09:57:17 -08:00
ring_buffer.c Drivers: hv: vmbus: Prevent load re-ordering when reading ring buffer 2022-04-20 09:12:49 +02:00
vmbus_drv.c Drivers: hv: Never allocate anything besides framebuffer from framebuffer memory region 2022-09-28 11:02:57 +02:00