Skip to content

Commit 8f7bb0b

Browse files
authored
feat: Deprecate looking-glass shm in favor of kvmfr module (#1013)
* feat: Deprecate looking-glass shm in favor of kvmfr * feat: add kvmfr0 to qemu cgroup_device_acl If someone has a better way to implement this regex, hit me up! i just happened to know how to do this with perl as i couldnt figure it out with sed * feat: Manually load kvmfr the first time so the user do not have to reboot use it when enabling. * chore: make introduction a bit clearer
1 parent 014c4ed commit 8f7bb0b

File tree

1 file changed

+83
-15
lines changed

1 file changed

+83
-15
lines changed

system_files/desktop/shared/usr/share/ublue-os/just/84-bazzite-virt.just

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ setup-virtualization ACTION="":
2525
echo " Use 'group' to select Add $USER to libvirt group"
2626
echo " Use 'vfio-on' to select Enable VFIO drivers"
2727
echo " Use 'vfio-off' to select Disable VFIO drivers"
28-
echo " Use 'shm' to select Autocreate Looking-Glass shm"
28+
echo " Use 'kvmfr' to select Autocreate Looking-Glass shm"
2929
exit 0
3030
elif [ "$OPTION" == "" ]; then
3131
echo "${bold}Virtualization Setup${normal}"
@@ -37,7 +37,7 @@ setup-virtualization ACTION="":
3737
"Add $USER to libvirt group" \
3838
"Enable VFIO drivers" \
3939
"Disable VFIO drivers" \
40-
"Autocreate Looking-Glass shm" \
40+
"Enable kvmfr module" \
4141
)
4242
fi
4343
if [[ "${OPTION,,}" =~ (^enable[[:space:]]virtualization|virt-on) ]]; then
@@ -129,29 +129,97 @@ setup-virtualization ACTION="":
129129
--delete-if-present="vfio_pci.disable_vga=0" \
130130
$VFIO_IDS_KARG
131131
fi
132-
elif [[ "${OPTION,,}" =~ shm ]]; then
132+
elif [[ "${OPTION,,}" =~ kvmfr ]]; then
133133
# Check if we are running on a Steam Deck
134134
if /usr/libexec/hwsupport/valve-hardware; then
135135
echo "IOMMU is not supported on Steam Deck"
136136
exit 0
137137
fi
138-
echo "Bazzite currently uses a deprecated implementation of the Looking Glass shm."
139-
echo "This implementation will not be supported in the future and we are in the process"
140-
echo "of moving over to the KVMFR kernel module."
141-
echo "Until this is done please open any Looking Glass issues you have in Bazzite"
142-
echo "in the $(Urllink "https://discord.bazzite.gg/" "Bazzite Discord") or the $(Urllink "https://github.com/ublue-os/bazzite/issues" "Bazzite Github issue tracker")"
138+
echo "$(Urllink "https://looking-glass.io/docs/rc/ivshmem_kvmfr/#libvirt" "This module") along with $(Urllink "https://looking-glass.io" "Looking Glass") is very experimental and not recommended for production use!"
139+
echo "The ublue team packages the kvmfr module only because it has to be supplied with the system image while using an atomic desktop."
140+
echo "If you do plan to use Looking Glass, please $(Urllink "https://universal-blue.discourse.group/docs?topic=956" "follow the guide here") on how to compile it for your system."
141+
echo "To use the kvmfr module after enabling it, just add and edit the xml for libvirt from the documentation in the first link."
142+
echo "Since we package the kvmfr module please open kvmfr related issues you have on Bazzite"
143+
echo "in the $(Urllink "https://discord.bazzite.gg/" "Bazzite Discord") or the $(Urllink "https://github.com/ublue-os/bazzite/issues" "Bazzite Github issue tracker")."
143144
echo "~ @HikariKnight"
144145
CONFIRM=$(Choose Ok Cancel)
145146
if [ "$CONFIRM" == "Cancel" ]; then
146147
exit 0
147148
fi
148-
echo "Creating tmpfile definition for shm file in /etc/tmpfiles.d/"
149-
sudo bash -c "cat << LOOKING_GLASS_TMP > /etc/tmpfiles.d/10-looking-glass.conf
150-
# Type Path Mode UID GID Age Argument
151-
f /dev/shm/looking-glass 0660 1000 qemu -
152-
LOOKING_GLASS_TMP"
153-
echo "Adding SELinux context record for /dev/shm/looking-glass"
154-
sudo semanage fcontext -a -t svirt_tmpfs_t /dev/shm/looking-glass
149+
echo ""
150+
echo "Setting up kvmfr module so it loads next boot"
151+
sudo bash -c 'cat << KVMFR_DRACUT > /etc/dracut.conf.d/kvmfr.conf
152+
install_items+=" /etc/modprobe.d/kvmfr.conf "
153+
KVMFR_DRACUT'
154+
sudo bash -c "cat << KVMFR_MODPROBE > /etc/modprobe.d/kvmfr.conf
155+
options kvmfr static_size_mb=128
156+
KVMFR_MODPROBE"
157+
echo "Adding udev rule for /dev/kvmfr0"
158+
sudo bash -c 'cat << KVMFR_UDEV > /etc/udev/rules.d/99-kvmfr.rules
159+
SUBSYSTEM=="kvmfr", OWNER="'$USER'", GROUP="qemu", MODE="0660"
160+
KVMFR_UDEV'
161+
echo "Adding /dev/kvmfr0 to qemu cgroup_device_acl"
162+
sudo perl -0777 -pi -e 's/
163+
#cgroup_device_acl = \[
164+
# "\/dev\/null", "\/dev\/full", "\/dev\/zero",
165+
# "\/dev\/random", "\/dev\/urandom",
166+
# "\/dev\/ptmx", "\/dev\/kvm",
167+
# "\/dev\/userfaultfd"
168+
#\]
169+
/
170+
cgroup_device_acl = \[
171+
"\/dev\/null", "\/dev\/full", "\/dev\/zero",
172+
"\/dev\/random", "\/dev\/urandom",
173+
"\/dev\/ptmx", "\/dev\/kvm",
174+
"\/dev\/userfaultfd", "\/dev\/kvmfr0"
175+
\]
176+
/' /etc/libvirt/qemu.conf
177+
echo "Adding SELinux context record for /dev/kvmfr0"
178+
sudo semanage fcontext -a -t svirt_tmpfs_t /dev/kvmfr0
179+
echo "Adding SELinux access rules for /dev/kvmfr0"
180+
if [ ! -d "$HOME/.config/selinux_te/mod" ]; then
181+
mkdir -p "$HOME/.config/selinux_te/mod"
182+
fi
183+
if [ ! -d "$HOME/.config/selinux_te/pp" ]; then
184+
mkdir -p "$HOME/.config/selinux_te/pp"
185+
fi
186+
bash -c "cat << KVMFR_SELINUX > $HOME/.config/selinux_te/kvmfr.te
187+
module kvmfr 1.0;
188+
189+
require {
190+
type device_t;
191+
type svirt_t;
192+
class chr_file { open read write map };
193+
}
194+
195+
#============= svirt_t ==============
196+
allow svirt_t device_t:chr_file { open read write map };
197+
KVMFR_SELINUX"
198+
echo "This is the type enforcement we wrote for SELinux and you can find it in $HOME/.config/selinux_te/kvmfr.te"
199+
echo "#======= start of kvmfr.te ======="
200+
cat "$HOME/.config/selinux_te/kvmfr.te"
201+
echo "#======== end of kvmfr.te ========"
202+
checkmodule -M -m -o "$HOME/.config/selinux_te/mod/kvmfr.mod" "$HOME/.config/selinux_te/kvmfr.te"
203+
semodule_package -o "$HOME/.config/selinux_te/pp/kvmfr.pp" -m "$HOME/.config/selinux_te/mod/kvmfr.mod"
204+
sudo semodule -i "$HOME/.config/selinux_te/pp/kvmfr.pp"
205+
echo "Loading kvmfr module so you do not have to reboot to use it the first time"
206+
sudo modprobe kvmfr static_size_mb=128
207+
sudo chown $USER:qemu /dev/kvmfr0
208+
echo ""
209+
echo "Kvmfr0 $(Urllink "https://looking-glass.io/docs/B7-rc1/install_libvirt/#determining-memory" "static size is set to 128mb by default")"
210+
echo "this will work with up to 4K SDR resolutiion, as most dummy plugs go up to 4K"
211+
echo "some games will try use the adapters max resolution on first boot and cause issues if the value is too low."
212+
echo "Most ghost display adapters max out at 4k, hence the default value of 128mb."
213+
echo ""
214+
echo "If you need to change it to a different value"
215+
echo "you can do that in /etc/modprobe.d/kvmfr.conf"
216+
echo "$(Urllink "https://looking-glass.io/docs/rc/ivshmem_kvmfr/#libvirt" "Please read official documentation for kvmfr for how to use it")"
217+
echo ""
218+
echo "Press OK to start the process of regenerating your initramfs, this will take a long time"
219+
echo "and there is no good way to track progress for it, if anything is wrong it will error out."
220+
echo "${b}NOTE: You can start using kvmfr right now without rebooting, but you will need to regenerate initramfs for it to auto load next boot.${n}"
221+
CONFIRM=$(Choose OK)
222+
rpm-ostree initramfs --enable
155223
elif [[ "${OPTION,,}" =~ group ]]; then
156224
if ! grep -q "^libvirt" /etc/group; then
157225
grep '^libvirt' /usr/lib/group | sudo tee -a /etc/group > /dev/null

0 commit comments

Comments
 (0)