Bug 221074 - Hyper V Gen 2 install has no mouse
Summary: Hyper V Gen 2 install has no mouse
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-virtualization (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-28 21:19 UTC by scorpionmage
Modified: 2021-03-11 01:38 UTC (History)
11 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description scorpionmage 2017-07-28 21:19:29 UTC
When FreeBSD 11.1 is installed on a Gen 2 VM, no mouse shows in the /dev directory. 

Service moused comes up with the message "unable to open /dev/psm0: No such file or directory". No mouse in X either.

Installing from the same media in a Gen 1 VM creates a /dev/psm0 and the mouse works.
Comment 1 Sepherosa Ziehau 2017-08-04 09:29:50 UTC
(In reply to scorpionmage from comment #0)

This is not planned.  If you want to use X, use VNC instead.  I use tigerVNC daily for the FreeBSD development work and of course firefox :).
Comment 2 scorpionmage 2017-08-05 23:59:31 UTC
(In reply to Sepherosa Ziehau from comment #1)
So, there will be no mouse working in X for a HyperV Gen 2 VM?
Comment 3 Sepherosa Ziehau 2017-08-07 01:23:32 UTC
(In reply to scorpionmage from comment #2)

As I said, no plan for it yet.  The Hyper-V console is _not_ suitable for X related stuffs.  And again, if you want to use X, use VNC; it is recommended and works quite well on both gen1 and gen2 Hyper-V.
Comment 4 Sepherosa Ziehau 2017-08-07 01:26:04 UTC
(In reply to scorpionmage from comment #2)

Well, if you _do_ want to stick w/ using the X on the Hyper-V console, then use gen1 VM, which has an emulated PS2 mouse.  I actually don't see gen2 VM buys anything useful for desktop users.
Comment 5 Greg V 2017-09-09 23:03:15 UTC
(In reply to Sepherosa Ziehau from comment #4)
Gen2 VM is based on UEFI and SCSI instead of BIOS and IDE. As a desktop user, I only want to use modern systems, not legacy :) The thought of using emulated IDE drives is terrifying. (VirtualBox emulates NVMe, dammit!)

I actually recommend using VcXsrv and SSH X forwarding via PuTTY. I have a little PowerShell script to launch the VM and run X apps from the VM on the Windows desktop: https://github.com/myfreeweb/xvmmgr

Still, why exactly is the Hyper-V console "_not_ suitable for X related stuffs"?
Comment 6 scorpionmage 2019-05-24 05:42:23 UTC
(In reply to Sepherosa Ziehau from comment #3)
Can you please explain why the console is not suitable? Is there a difference between the Gen 1 and Gen 2 consoles?

I am not a fan of the VNC option as now I have to get a viewer on my Windows machine as well as manage a different configuration from other Linux VMs.
Comment 7 scorpionmage 2019-05-24 05:49:40 UTC
(In reply to Greg V from comment #5)
Agree - the modern technologies are the reason. And it also allows the streamlining of configurations across Linux and FreeBSD VMs. It also allows the GPT partitioning scheme which enables creating temporary filesystem VHDXs which are then mounted by UUID and not by controller location.

Thanks for the suggestion. I have also tried xrdp, which ran into issues after an update - the port might not have a maintainer.
Comment 8 scorpionmage 2019-05-24 05:50:08 UTC
BTW, this is also happening in 12.0 and Current.
Comment 9 scorpionmage 2019-05-24 05:53:24 UTC
(In reply to Greg V from comment #5)
(In reply to scorpionmage from comment #7)
I switched to using xmonad on FreeBSD in the interim, as it lets me use X without a mouse. It does force learning lots of keyboard shortcuts, though, both for the WM and the applications :-(
Comment 10 Lars Engels freebsd_committer 2020-04-24 07:08:46 UTC
It's sad to see that mouse integration is still not integrated with latest Hyper-V and FreeBSD 12.1. Maybe the "Microsoft <3 FreeBSD" slogan was meant not too serious.
Comment 11 Lars Engels freebsd_committer 2020-04-24 09:43:06 UTC
Sorry, disregard my last comment. It was written out of frustation.
Comment 12 Dwerva 2021-03-08 03:26:41 UTC
I thought I would load up BSD in a Hyper-v for old time sake.  And then the horror on my face as I realized I could only use the keyboard.  And then when I search for a workaround, I find this bug report and the fact that it has been so ignorantly brushed aside.

I used to be an avid BSD user, then I switched to Linux.  You want to know why?  This is the exact BSD mentality that made me switch.

"No mouse in Hyper-v?  Too bad, I don't use it so why should anyone else need to use it, therefore I won't implement it."

And you guys wonder why Linux has become so popular? 

BSD has gone from being one of the greatest to being one of the worst, and a laughing stock.

R.I.P.
Comment 13 Dexuan Cui 2021-03-08 09:45:48 UTC
(In reply to Dwerva from comment #12)
Hi Dwerva, maybe you can use a Generation-1 FreeBSD VM as a workaround? Mouse works with Gen1 FreeBSD VMs, because Hyper-V emulates a legacy mouse.

For Gen-2 VMs, Hyper-V doesn't emulate the legacy mouse, so we have to develop a para-virtualized front-end mouse driver in the VM to use mouse. For Linux VM, the driver is https://github.com/torvalds/linux/blob/master/drivers/hid/hid-hyperv.c. I once tried to port the driver to FreeBSD, but unluckily it turned out I couldn't understand how the mouse APIs work in FreeBSD (I studied the mouse APIs for a few days but still didn't quite understand which sets of API should be used and how the Hyper-V mouse events should be converted to the mouse events that can be understood by FreeBSD) so I gave up... :-( I hope somebody with more knowledge on FreeBSD mouse APIs can help.
Comment 14 Vladimir Kondratyev freebsd_committer 2021-03-10 22:41:40 UTC
(In reply to Dexuan Cui from comment #13)
> I once tried to port the driver to FreeBSD, but unluckily it
> turned out I couldn't understand how the mouse APIs work in FreeBSD

Hi Dexuan, could you send me your port?
After 13 has got generic HID support, it is probably quite easy to connect the port with mouse/whatever else HID-based API.

What is needed are:
1. Standard probe/attach/detach functions.
2. Routine to fetch HID report descriptor.
3. Interrupt control functions: setup/unsetup/start/stop.
4. Interrupt handler capable of reading input report.
5. Get report/Set report/Write output report routines (only if supported).

See https://github.com/freebsd/freebsd-src/blob/main/sys/dev/hid/hid_if.m for HID transport backend protocol description.

And could someone from Microsoft give some attention to Gen 2 VM keyboard improvement reviews: https://reviews.freebsd.org/D28170 and https://reviews.freebsd.org/D28171 ?
Comment 15 Dexuan Cui 2021-03-11 00:12:47 UTC
(In reply to Vladimir Kondratyev from comment #14)
Hi Vladimir, sorry I actually just did some research and didn't write any code. :-)

The Hyper-V/VMBus part of the driver should be straightforward, I'm just not familiar with the HID part. The core logic of the Hyper-V mouse driver in Linux VM is Line 296~306 (https://github.com/torvalds/linux/blob/master/drivers/hid/hid-hyperv.c#L296): IIRC, for every mouse event, the Hyper-V host sends a 7-byte "input_report", which in Linux VM is handled by the Linux HID API hid_input_report() and nothing else is done. In FreeBSD, I'm not sure what the equivalent API is?  -- I read the page you shared and I guess it may be:

METHOD int get_report {
	device_t dev;
	void *data;
	hid_size_t maxlen;
	hid_size_t *actlen;
	uint8_t type;
	uint8_t id;
};

I suppose the format of the 7 bytes from the Hyper-V host should comply with the HID spec for mouse (I guess there is a spec for this?), and if so, FreeBSD can use the 7 bytes directly, just like Linux VM does.

I'm currently in the middle of something else, so sorry I can't work on this right now. I guess Wei (whu) on our team can help on this, and also review the 2 kbd patches.
Comment 16 Vladimir Kondratyev freebsd_committer 2021-03-11 01:08:19 UTC
(In reply to Dexuan Cui from comment #15)
> I'm just not familiar with the HID part.
And I am not familiar with VMbus :-)

> IIRC, for every mouse event, the Hyper-V host sends
> a 7-byte "input_report", which in Linux VM is handled
> by the Linux HID API hid_input_report() and nothing else is done.
> In FreeBSD, I'm not sure what the equivalent API is?

intr_handler callback sends input report body to upper layers. See e.g. iichid driver:
https://github.com/freebsd/freebsd-src/blob/main/sys/dev/iicbus/iichid.c#L583.
The callback is registered with intr_setup method https://github.com/freebsd/freebsd-src/blob/main/sys/dev/hid/hid_if.m#L50.

> I suppose the format of the 7 bytes from the Hyper-V host
> should comply with the HID spec for mouse
As it is not a boot protocol which takes only 3 bytes, it should be prescribed in HID report descriptor. I think it lies in one of the Linux header files.

> I guess Wei (whu) on our team can help on this, and also review the 2 kbd patches.
That would be great! Thanks! If someone familiar with VMbus would write driver capable to just print these 7 bytes, I would easily connect it to our HID API.
Comment 17 Dexuan Cui 2021-03-11 01:38:13 UTC
(In reply to Vladimir Kondratyev from comment #16)
Thanks, Vladimir! Sounds like a good cooperation opportunity! :-)