From 1bb7f7d243d58075af1bebae76bd038febf0f442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A7=E7=80=AC=E7=B4=85=E8=8E=89=E6=A0=96?= Date: Mon, 28 Feb 2022 20:35:24 +0800 Subject: [PATCH] Introduce `fboff` to disable framebuffer --- README.md | 16 +++++++++++++++- exec-cmds | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59b8325..e7a2717 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ cat /etc/pve/qemu-server/204.conf ### 2.7. `pci_remove` and `pci_rescan` -In the reverse of 2.6, sometimes host will actually hold some memory in PCI device's address space, and prevent that space being handled by vfio-pci driver. One common example is `simplefb` allocating `BOOTFB` in [boot GPU's address space](https://github.com/torvalds/linux/blob/7e57714cd0ad2d5bb90e50b5096a0e671dec1ef3/drivers/firmware/sysfb_simplefb.c#L115) despite setting `video=simplefb:off` in kernel cmdline. A [hack](https://github.com/furkanmustafa/forcefully-remove-bootfb) exists but it is [not guranteed to work for everyone](https://github.com/SRH1605/forcefully-remove-bootfb/pull/1#issuecomment-1054073276). As such one can unbind and rebind the PCI device to free up the entire address space allocated for the device, indirectly getting rid of the offending memory allocation. +In a reverse scenario of 2.6, sometimes host will actually hold some memory in PCI device's address space, and prevent that space being handled by vfio-pci driver and thus the VM. One common example is `simplefb` allocating `BOOTFB` in [boot GPU's address space](https://github.com/torvalds/linux/blob/7e57714cd0ad2d5bb90e50b5096a0e671dec1ef3/drivers/firmware/sysfb_simplefb.c#L115) despite setting `video=simplefb:off` in kernel cmdline. A [hack](https://github.com/furkanmustafa/forcefully-remove-bootfb) exists but it is [not guranteed to work for everyone](https://github.com/SRH1605/forcefully-remove-bootfb/pull/1#issuecomment-1054073276). As such one can unbind and rebind the PCI device to free up the entire address space allocated for the device, indirectly getting rid of the offending memory allocation. However, this won't work on all memory allocation. For memory occupied by `efifb`/`simplefb`, please see below. The difference between this set of commands and `pci_unbind`/`pci_rebind` is that this set runs before VM is started (need to have all the memory availabe before passthrough), while `pci_unbind`/`pci_rebind` happens after VM is stopped (so we know VGA is no longer in use and can be given back to the host). @@ -215,6 +215,20 @@ cat /etc/pve/qemu-server/204.conf #pci_rescan ``` +### 2.8. `fboff` + +In addition to the `BOOTFB` issue, many users need to specify `video=efifb:off` or equivalent kernel parameter. However, [not everyone can use that](https://www.reddit.com/r/VFIO/comments/ks7ve3/alternative_to_efifboff/) in their workflow. As such, `fboff` can be used as an alternative to kernel parameter. + +```yaml +cat /etc/pve/qemu-server/204.conf + +## free memory used by simplefb.0 +#fboff simplefb.0 +## alternatively.. +#fboff efifb.0 +#fboff vesafb.0 +``` + ### 3. Legacy features These are features that are no really longer needed to achieve a good latency in a VM. diff --git a/exec-cmds b/exec-cmds index e7fdee0..4be9212 100755 --- a/exec-cmds +++ b/exec-cmds @@ -109,9 +109,18 @@ exec_qm_depends() { qm start "$1" } +exec_fboff() { + echo "Disabling $1 to prepare to pass GPU to VM$VMID" + echo "$1" > /sys/bus/platform/devices/$1/driver/unbind +} + exec_cmds() { while read CMD ARG1 ARG2 ARG3 REST; do case "$CMD" in + "#fboff") + if_action pre-start exec_fboff "$ARG1" + ;; + "#pci_remove") if_action pre-start exec_pci_unbind "$ARG1" "$ARG2" "$ARG3" ;;