virtio-win / kvm-guest-drivers-windows

Windows paravirtualized drivers for QEMU\KVM
https://www.linux-kvm.org/page/WindowsGuestDrivers
BSD 3-Clause "New" or "Revised" License
1.92k stars 377 forks source link

Hide "Eject virtio drivers" from "Safely Remove Hardware and Eject Media" with virio-win-0.1.160_amd64. #366

Open reboottttt opened 5 years ago

reboottttt commented 5 years ago

Hi all, I installed virtio drivers on windows server 2012 R2 , then I found that "Safely Remove Hardware and Eject Media" in the lower right corner can eject virtio drivers like "VirtIO Serial Drivers" and "Red Hat VirtIO Ethernet Adapter", the drivers will be disabled after clicking "eject xxxx Drivers", I also test on windows 7, windows 10, windows 2016, they are all the same. My question is, how can I hide these "Eject xxxx virtio drivers" button?Showing these buttons can be very unsafe when confuse these drivrer names. In fact, I can temporarily hide these virito drivers by modifying the registry. But, is there any way to implement this in the driver code?

thanks

safely remove hardware and eject media

eject virtio drivers

vrozenfe commented 5 years ago

for storage drivers take a look at STOR_DEVICE_CAPABILITIES_EX structure https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/storport/ns-storport-_stor_device_capabilities_ex

and WDF_DEVICE_PNP_CAPABILITIES for kmdf devices.

tofurky commented 5 years ago

Windows 10 1809 made a change with how it determines which drives are suitable for storing pagefiles. Unfortunately, it will now refuse to use a pagefile on any removable non-system (i.e. not C:\) drive even if it's been explicitly told to. The workaround some have found is to disable hotswap in their BIOS settings or via a registry key. However, it appears to be hard-coded in viostor here: https://github.com/virtio-win/kvm-guest-drivers-windows/blob/639c2aab55f26e03230508e23bdb1ceb346f7723/viostor/virtio_stor.c#L853-L861

So, I guess +1 from me. It's not as simple as rebuilding the driver as Windows 10 refuses to load anything unsigned, unless you specifically allow loading ANY unsigned code, forever, via a bcdedit parameter :cry:.

For searchability, the error that pops up is "Windows created a temporary paging file on your computer because of a problem that occurred with your paging file configuration when you started your computer."

If this capability were added, it might make sense to model it after how ahcistor does it via the TreatAsInternalPort parameter as is documented here: https://support.microsoft.com/en-us/help/3083627/internal-sata-drives-show-up-as-removeable-media

vrozenfe commented 5 years ago

I added this code mostly as a placeholder for the future PNP related stuff. The original idea was to set Removable according to VIRTIO_SCSI_F_HOTPLUG flag. I'm going to continue working on this piece of code in the future. Cheers, Vadim.

reboottttt commented 5 years ago

for storage drivers take a look at STOR_DEVICE_CAPABILITIES_EX structure https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/storport/ns-storport-_stor_device_capabilities_ex

and WDF_DEVICE_PNP_CAPABILITIES for kmdf devices.

OK, I will read and learn deeply. thanks for reply.

vrozenfe commented 5 years ago

@tofurky Sorry, I didn't pay attention that you were referencing viostor driver, because I have some similar code for vioscsi driver as well in my local repository.

reboottttt commented 5 years ago

Windows 10 1809 made a change with how it determines which drives are suitable for storing pagefiles. Unfortunately, it will now refuse to use a pagefile on any removable non-system (i.e. not C:) drive even if it's been explicitly told to. The workaround some have found is to disable hotswap in their BIOS settings or via a registry key. However, it appears to be hard-coded in viostor here:

kvm-guest-drivers-windows/viostor/virtio_stor.c

Lines 853 to 861 in 639c2aa

if ((SrbPnPFlags & SRB_PNP_FLAGS_ADAPTER_REQUEST) == 0) { RhelDbgPrint(TRACE_LEVEL_FATAL, " not SRB_PNP_FLAGS_ADAPTER_REQUEST SrbPnPFlags = %d, PnPAction = %d\n", SrbPnPFlags, PnPAction); if ((PnPAction == StorQueryCapabilities) && (SRB_DATA_TRANSFER_LENGTH(Srb) >= sizeof(STOR_DEVICE_CAPABILITIES))) { PSTOR_DEVICE_CAPABILITIES storCapabilities = (PSTOR_DEVICE_CAPABILITIES)SRB_DATA_BUFFER(Srb); RtlZeroMemory(storCapabilities, sizeof(*storCapabilities)); storCapabilities->Removable = 1; } else { SrbStatus = SRB_STATUS_INVALID_REQUEST; So, I guess +1 from me. It's not as simple as rebuilding the driver as Windows 10 refuses to load anything unsigned, unless you specifically allow loading ANY unsigned code, forever, via a bcdedit parameter .

For searchability, the error that pops up is "Windows created a temporary paging file on your computer because of a problem that occurred with your paging file configuration when you started your computer."

If this capability were added, it might make sense to model it after how ahcistor does it via the TreatAsInternalPort parameter as is documented here: https://support.microsoft.com/en-us/help/3083627/internal-sata-drives-show-up-as-removeable-media

Thanks for reply. So...it's seems like difficult implement by change driver code?

reboottttt commented 5 years ago

I added this code mostly as a placeholder for the future PNP related stuff. The original idea was to set Removable according to VIRTIO_SCSI_F_HOTPLUG flag. I'm going to continue working on this piece of code in the future. Cheers, Vadim.

thanks for reply. It’s really good news, I have been troubled by this issue recently. Compared to xen, you can solve this problem by modifying xenpci, and kvm is blocking on Microsoft pci. Looking forward to your update!

tofurky commented 5 years ago

Thanks for reply. So...it's seems like difficult implement by change driver code?

Flipping removable from 1 to 0 would be easy but that'd break the functionality for people who depend on it. It'd be significantly more involved to apply the removable flag on a per-device basis depending on the value of a yet-to-be-created registry key.

vrozenfe commented 5 years ago

@tofurky @reboottttt Adding a registry key would be a simplest and fastest solution. However, I would prefer to see the driver itself turning removable flag off for system, pagefile, crash dump disks, etc. I'm going to make some research to see if it is doable. Will keep you updated. Cheers, Vadim.

tofurky commented 5 years ago

just an update, i saw that microsoft released KB4476976 (https://support.microsoft.com/en-us/help/4476976/windows-10-update-kb4476976) which among other things does this:

Addresses an issue that occurs if you create a page file on a drive with FILE_PORTABLE_DEVICE characteristics. The “Windows created a temporary warning” message appears.

haven't tested it yet.

edit: KB4476976 fixes the pagefile on removable storage as advertised.