Page MenuHomeFreeBSD

Hyper-V: vmbus: Add NULL check for vmbus_res
ClosedPublic

Authored by zlei on Oct 31 2023, 2:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 7, 10:01 PM
Unknown Object (File)
Mar 13 2024, 3:56 AM
Unknown Object (File)
Dec 28 2023, 9:57 AM
Unknown Object (File)
Dec 23 2023, 2:36 AM
Unknown Object (File)
Dec 16 2023, 1:54 AM
Unknown Object (File)
Nov 29 2023, 1:13 PM
Unknown Object (File)
Nov 10 2023, 4:56 PM
Unknown Object (File)
Nov 2 2023, 9:09 AM

Details

Summary

QEMU emulates Hyper-V [1] but lacks vmbus_res, thus no coherence information
is available. Add NULL check for it and fallback to no coherence. This will prevent
FreeBSD guests from page fault on QEMU hypervisor with the Hyper-V enlightenment
hv-synic enabled.

Real Hyper-V both gen1 and gen2 have vmbus_res thus are not effected by this change.

  1. https://www.qemu.org/docs/master/system/i386/hyperv.html

PR: 274810
Diagnosed by: mhorne
Fixes: e7a9817b8d32 Hyper-V: vmbus: implementat bus_get_dma_tag in vmbus
MFC after: immediately (we want this in 14.0)

Test Plan
  1. Setup Vultr VM with custom ISO. Install FreeBSD 13.2 and install the patched kernel, then verify it boots correctly.
  2. Run on QEMU with Hyper-V enlightenment hv-synic enabled.
  3. Run on real Hyper-V gen1 and gen2 hypervisor.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

zlei requested review of this revision.Oct 31 2023, 2:01 PM
zlei edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Oct 31 2023, 2:11 PM

@schakrabarti_microsoft.com @andrew

From the review D41728 I guess on x86 there should have hardware coherency.

I might get wrong place but did not find any useful information about "Coherency" or "vmbus_res" or "_CCA" from the public document [1].
So is the "Coherency attribute" is ARM64 specific ?
Then we may want coherent default to true on x86 and false on ARM64.

  1. https://github.com/MicrosoftDocs/Virtualization-Documentation
In D42414#968057, @zlei wrote:

@schakrabarti_microsoft.com @andrew

From the review D41728 I guess on x86 there should have hardware coherency.

I might get wrong place but did not find any useful information about "Coherency" or "vmbus_res" or "_CCA" from the public document [1].
So is the "Coherency attribute" is ARM64 specific ?
Then we may want coherent default to true on x86 and false on ARM64.

  1. https://github.com/MicrosoftDocs/Virtualization-Documentation

It does not exactly answer the question, but the BUS_DMA_COHERENT flag has no effect on the x86 busdma implementation.

sys/dev/hyperv/vmbus/vmbus.c
1422–1424

Please get it tested in real Hyper-V gen1 (x86) and gen2 VM (arm and x86) to avoid regression.
Also please do also a ufs storage check along with this, to make sure, the storage is properly cache aligned, to avoid any regression.

zlei added inline comments.
sys/dev/hyperv/vmbus/vmbus.c
1422–1424

Hi @lwhsu ,
I do not have real Hyper-V gen1 or gen2 VMs. Would you please test this ?

Thanks very much.

sys/dev/hyperv/vmbus/vmbus.c
1422–1424

I managed to get the patch tested on Hyper-V gen1 (x86) and gen2 (x86 only) on a Windows 10 host. The two VMs to be tested are created from FreeBSD-14.0-RC3-amd64.vhd.xz.

So far all looks good , w/o the patch.

From the tests I can confirm that both gen1(x86) and gen2(x86) has vmbus_res. So with the patch no regression is possible.

As for gen2 arm, there should be vmbus_res devices, so I believe no regression test is needed.

In D42414#968057, @zlei wrote:

@schakrabarti_microsoft.com @andrew

From the review D41728 I guess on x86 there should have hardware coherency.

I might get wrong place but did not find any useful information about "Coherency" or "vmbus_res" or "_CCA" from the public document [1].
So is the "Coherency attribute" is ARM64 specific ?
Then we may want coherent default to true on x86 and false on ARM64.

  1. https://github.com/MicrosoftDocs/Virtualization-Documentation

It does not exactly answer the question, but the BUS_DMA_COHERENT flag has no effect on the x86 busdma implementation.

And from the tests on Hyper-V gen1 (x86) and gen2 (x86), the dmesg shows

vmbus0: Bus is not cache-coherent

without the patch.

delphij added a subscriber: delphij.

For systems where vmbus_res is available, the code behavior won't change, so those worked before the change will work fine after it.

For systems where vmbus_res is unavailable, the change would make the code to disable coherent instead of a NULL pointer dereference.

Therefore, I do not see a possibility of regression overall. Please consider this as a blessing from re@ for expedited MFC in order to be part of RC4.

sys/dev/hyperv/vmbus/vmbus.c
1422–1424

Can you remove this line by initializing 'coherent' at the beginning of the call?

zlei edited the test plan for this revision. (Show Details)

Address @whu 's comment.

This revision now requires review to proceed.Nov 2 2023, 6:36 AM
This revision is now accepted and ready to land.Nov 2 2023, 6:54 AM
zlei edited the test plan for this revision. (Show Details)

Ping @whu .

This revision was automatically updated to reflect the committed changes.