Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FD passing for shared memory #78

Closed
wants to merge 5 commits into from

Conversation

DemiMarie
Copy link
Contributor

@DemiMarie DemiMarie commented Jul 10, 2021

This is another attempt at using FD passing for shared memory, at the cost of still requiring shmoverride.

This doesn’t actually work, and it may not be a good use of time even if it did. The reason I am filing it as a PR is to at least give it a chance to be reviewed, so that the work done on it has a chance of not being wasted. The code is now fully functional and has been tested over VNC. The main advantage is that the same approach works on Wayland, which does not support System V IPC. Newer versions of glibc (which do not use the legacy __fxstat and __fxstat64 functions) are known to build but have not been otherwise tested.

@DemiMarie
Copy link
Contributor Author

This actually works now! I am still not sure if the extra complexity (and overhead) is worthwhile, but this shows that the approach is viable. Tray icons have not been tested.

@DemiMarie
Copy link
Contributor Author

Last few commits add some consistency checks and fix a premature free() in shmoverride, which led to every element of shmoverride’s global list being located in freed memory.

@DemiMarie DemiMarie force-pushed the xcb-fd-passing branch 8 times, most recently from c93b2c4 to d0bb7d3 Compare July 18, 2021 01:02
@DemiMarie
Copy link
Contributor Author

PipelineRetry

@DemiMarie
Copy link
Contributor Author

This has passed every test I can think of, which proves that shmoverride will not be needed at all for Wayland.

@DemiMarie
Copy link
Contributor Author

PipelineRefresh

@DemiMarie
Copy link
Contributor Author

Windows qubes work, too!

@marmarek
Copy link
Member

I'm going to leave it open until after branching off R4.1.

@DemiMarie DemiMarie force-pushed the xcb-fd-passing branch 6 times, most recently from 78a0c65 to 54ce194 Compare August 3, 2021 22:21
Comment on lines +156 to +167
#if defined MAP_ANON && defined MAP_ANONYMOUS && (MAP_ANONYMOUS) != (MAP_ANON)
# error header bug (def mismatch)
#endif
#ifndef MAP_ANON
# define MAP_ANON 0
#endif
#ifndef MAP_ANONYMOUS
# define MAP_ANONYMOUS 0
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much of this section is necessary?

@DemiMarie DemiMarie force-pushed the xcb-fd-passing branch 2 times, most recently from c66b5d8 to 57e7a3a Compare October 6, 2021 06:35
@DemiMarie
Copy link
Contributor Author

PipelineRetry

@DemiMarie
Copy link
Contributor Author

@marmarek please re-review

@marmarek
Copy link
Member

marmarek commented Jul 8, 2022

GUI daemon crashes with qubes-guid: XGetWindowAttributes: Inappropriate ioctl for device
You can extract more logs from var_log.tar.gz in https://openqa.qubes-os.org/tests/43364#downloads

@qubesos-bot
Copy link

qubesos-bot commented Jul 8, 2022

OpenQA test summary

Complete test suite and dependencies: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.1&build=2022100203-4.1&flavor=pull-requests

New failures, excluding unstable

Compared to: https://openqa.qubes-os.org/tests/overview?distri=qubesos&version=4.1&build=2022092706-4.1&flavor=update

Failed tests

40 failures

Fixed failures

Compared to: https://openqa.qubes-os.org/tests/46840#dependencies

1 fixed
  • system_tests_network_updates
    • TC_11_QvmTemplateMgmtVM_whonix-gw-16: test_010_template_install (error)
      subprocess.CalledProcessError: Command 'systemcheck --cli' returned...

Unstable tests

  • system_tests_basic_vm_qrexec_gui

    TC_00_AppVM_fedora-36/test_223_audio_play_hvm (1/5 times with errors)
    • job 46378 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_00_AppVM_whonix-ws-16/test_223_audio_play_hvm (1/5 times with errors)
    • job 46232 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_whonix-ws-16/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 46232 AssertionError: only silence detected, no useful audio data
  • system_tests_pvgrub_salt_storage

    TC_41_HVMGrub_fedora-36/test_000_standalone_vm (1/5 times with errors)
    • job 46071 AssertionError: Failed command: dnf clean expire-cache && dnf insta...
    TC_10_VMSalt_debian-11/test_001_multi_state_highstate (1/5 times with errors)
    • job 46241 AssertionError: 'file_|-/home/user/something_|-/home/user/something...
    TC_10_VMSalt_fedora-36/test_001_multi_state_highstate (1/5 times with errors)
    • job 46241 AssertionError: 'file_|-/home/user/something_|-/home/user/something...
    TC_40_PVGrub_debian-11/test_010_template_based_vm (1/5 times with errors)
    • job 46071 AssertionError: Failed command: apt-get update && apt-get install -...
  • system_tests_splitgpg

    TC_00_Direct_whonix-ws-16/test_080_option_parser (1/5 times with errors)
    • job 46242 AssertionError: "qubes-gpg-client: unrecognized option '--export-op...
  • system_tests_qrexec

    TC_00_Qrexec_whonix-gw-16/test_050_qrexec_simple_eof (1/5 times with errors)
    • job 46374 AssertionError: Timeout, probably EOF wasn't transferred to the VM ...
    TC_00_Qrexec_fedora-36/test_052_qrexec_vm_service_eof (1/5 times with errors)
    • job 46752 AssertionError: Timeout, probably EOF wasn't transferred
    TC_00_Qrexec_whonix-ws-16/test_055_qrexec_dom0_service_abort (1/5 times with errors)
    • job 46259 AssertionError: Timeout, probably stdout wasn't closed
    TC_00_Qrexec_debian-11/test_070_qrexec_vm_simultaneous_write (2/5 times with errors)
    • job 46228 AssertionError: Timeout, probably deadlock
    • job 46259 AssertionError: Timeout, probably deadlock
    TC_00_Qrexec_fedora-36/test_070_qrexec_vm_simultaneous_write (2/5 times with errors)
    • job 46259 AssertionError: Timeout, probably deadlock
    • job 46752 AssertionError: Timeout, probably deadlock
  • system_tests_network_ipv6

    VmIPv6Networking_debian-11/test_020_simple_proxyvm_nm (1/5 times with errors)
    • job 46069 AssertionError: 1 != 0 : nm-applet window not found
    VmIPv6Networking_debian-11/test_040_inter_vm (1/5 times with errors)
    • job 46239 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 90 secon...
    VmIPv6Networking_fedora-36/test_040_inter_vm (1/5 times with errors)
    • job 46239 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 90 secon...
    VmIPv6Networking_debian-11/test_540_ipv6_inter_vm (1/5 times with errors)
    • job 46239 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 90 secon...
    VmIPv6Networking_fedora-36/test_540_ipv6_inter_vm (1/5 times with errors)
    • job 46239 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 90 secon...
  • system_tests_network_updates

    TC_11_QvmTemplateMgmtVM_whonix-gw-16/test_000_template_list (1/5 times with errors)
    • job 46764 subprocess.CalledProcessError: Command 'systemcheck --cli' returned...
    TC_10_QvmTemplate_whonix-gw-16/test_010_template_install (2/5 times with errors)
    • job 46240 subprocess.CalledProcessError: Command 'systemcheck --cli' returned...
    • job 46473 AssertionError: libvirt event impl drain timeout
    TC_11_QvmTemplateMgmtVM_debian-11/test_010_template_install (1/5 times with errors)
    • job 46070 AssertionError: libvirt event impl drain timeout
    TC_11_QvmTemplateMgmtVM_whonix-gw-16/test_010_template_install (3/5 times with errors)
    • job 46240 None
    • job 46435 subprocess.CalledProcessError: Command 'systemcheck --cli' returned...
    • job 46764 qvm-template: error: Template 'debian-11-minimal' not found.
  • system_tests_backupdispvm

    TC_10_RestoreInDispVM_whonix-gw-16/test_000_basic_backup (1/5 times with errors)
    • job 46231 qubesadmin.exc.QubesException: qvm-backup-restore tool missing in w...
    TC_10_RestoreInDispVM_whonix-ws-16/test_000_basic_backup (1/5 times with errors)
    • job 46231 qubesadmin.exc.QubesException: qvm-backup-restore tool missing in w...
  • system_tests_dispvm

    TC_04_DispVM/test_003_cleanup_destroyed (3/5 times with errors)
    • job 46086 raise exceptions.TimeoutError()... asyncio.exceptions.TimeoutError
    • job 46222 raise exceptions.TimeoutError()... asyncio.exceptions.TimeoutError
    • job 46368 raise exceptions.TimeoutError()... asyncio.exceptions.TimeoutError
    TC_20_DispVM_fedora-36/test_010_simple_dvm_run (3/5 times with errors)
    • job 46086 assert len(self.loop._selector.get_map()) \... AssertionError
    • job 46222 assert len(self.loop._selector.get_map()) \... AssertionError
    • job 46368 assert len(self.loop._selector.get_map()) \... AssertionError
    TC_20_DispVM_whonix-gw-16/test_010_simple_dvm_run (3/5 times with errors)
    TC_20_DispVM_whonix-ws-16/test_010_simple_dvm_run (3/5 times with errors)
    • job 46086 assert len(self.loop._selector.get_map()) \... AssertionError
    • job 46222 assert len(self.loop._selector.get_map()) \... AssertionError
    • job 46368 assert len(self.loop._selector.get_map()) \... AssertionError
    TC_20_DispVM_whonix-gw-16/test_020_gui_app (3/5 times with errors)
    TC_20_DispVM_debian-11/test_030_edit_file (3/5 times with errors)
    • job 46086 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46222 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46368 AssertionError: Timeout while waiting for disp[0-9]* window to show
    TC_20_DispVM_fedora-36/test_030_edit_file (3/5 times with errors)
    • job 46086 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46222 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46368 AssertionError: Timeout while waiting for disp[0-9]* window to show
    TC_20_DispVM_whonix-gw-16/test_030_edit_file (3/5 times with errors)
    TC_20_DispVM_whonix-ws-16/test_030_edit_file (3/5 times with errors)
    • job 46086 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46222 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46368 AssertionError: Timeout while waiting for disp[0-9]* window to show
    TC_20_DispVM_debian-11/test_100_open_in_dispvm (3/5 times with errors)
    • job 46086 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46222 AssertionError: Timeout while waiting for disp[0-9]* window to show
    • job 46368 AssertionError: './open-file test.txt' failed with ./open-file test...
    TC_20_DispVM_fedora-36/test_100_open_in_dispvm (5/5 times with errors)
    • job 46086 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46096 self.assertEqual(test_txt_content.s... AssertionError: b'' != b'test1'
    • job 46222 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46368 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46488 self.assertEqual(test_txt_content.s... AssertionError: b'' != b'test1'
    TC_20_DispVM_whonix-gw-16/test_100_open_in_dispvm (3/5 times with errors)
    TC_20_DispVM_whonix-ws-16/test_100_open_in_dispvm (3/5 times with errors)
    • job 46086 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46222 AssertionError: './open-file test.txt' failed with ./open-file test...
    • job 46368 AssertionError: Timeout while waiting for disp[0-9]* window to show
  • system_tests_devices

    TC_10_Attach_debian-11/test_000_attach_reattach (3/5 times with errors)
    • job 46053 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    • job 46223 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    • job 46369 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    TC_10_Attach_fedora-36/test_000_attach_reattach (2/5 times with errors)
    • job 46053 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    • job 46223 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    TC_10_Attach_whonix-gw-16/test_000_attach_reattach (2/5 times with errors)
    • job 46053 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    • job 46223 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    TC_10_Attach_whonix-ws-16/test_000_attach_reattach (2/5 times with errors)
    • job 46053 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
    • job 46223 subprocess.CalledProcessError: Command 'ls /dev/xvdi' returned non-...
  • system_tests_basic_vm_qrexec_gui_btrfs

    TC_00_AppVM_fedora-36-pool/test_000_start_shutdown (1/5 times with errors)
    • job 46371 qubes.exc.QubesVMError: Cannot connect to qrexec agent for 90 secon...
    TC_00_AppVM_fedora-36-pool/test_010_run_xterm (1/5 times with errors)
    • job 46371 raise exceptions.TimeoutError()... asyncio.exceptions.TimeoutError
    TC_00_AppVM_fedora-36-pool/test_011_run_gnome_terminal (1/5 times with errors)
    • job 46371 AssertionError: Timeout while waiting for user@test-inst-vm1 window...
    TC_00_AppVM_debian-11-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 46371 subprocess.CalledProcessError: Command 'pacmd unload-module module-...
    TC_00_AppVM_whonix-ws-16-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 46225 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_debian-11-pool/test_224_audio_rec_muted_hvm (1/5 times with errors)
    • job 46098 subprocess.CalledProcessError: Command 'pkill parecord' returned no...
    TC_00_AppVM_debian-11-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 46098 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_whonix-ws-16-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 46225 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_debian-11-pool/test_300_bug_1028_gui_memory_pinning (1/5 times with errors)
    • job 46225 assert len(self.loop._selector.get_map()) \... AssertionError
    TC_00_AppVM_fedora-36-pool/test_300_bug_1028_gui_memory_pinning (1/5 times with errors)
    • job 46225 assert len(self.loop._selector.get_map()) \... AssertionError
  • system_tests_basic_vm_qrexec_gui_ext4

    TC_00_AppVM_whonix-ws-16-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 46252 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_whonix-ws-16-pool/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 46252 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_fedora-36-pool/test_300_bug_1028_gui_memory_pinning (1/5 times with errors)
    • job 46084 assert len(self.loop._selector.get_map()) \... AssertionError
  • system_tests_basic_vm_qrexec_gui_xfs

    TC_00_AppVM_whonix-ws-16-pool/test_223_audio_play_hvm (1/5 times with errors)
    • job 46227 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_whonix-ws-16-pool/test_225_audio_rec_unmuted_hvm (2/5 times with errors)
    • job 46227 AssertionError: only silence detected, no useful audio data
    • job 46373 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_debian-11-pool/test_300_bug_1028_gui_memory_pinning (1/5 times with errors)
    • job 46085 assert len(self.loop._selector.get_map()) \... AssertionError
  • system_tests_basic_vm_qrexec_gui@hw1

    TC_00_AppVM_fedora-36/test_223_audio_play_hvm (1/5 times with errors)
    • job 46378 AssertionError: Timeout waiting for pulseaudio start in test-inst-v...
    TC_00_AppVM_whonix-ws-16/test_223_audio_play_hvm (1/5 times with errors)
    • job 46232 AssertionError: only silence detected, no useful audio data
    TC_00_AppVM_whonix-ws-16/test_225_audio_rec_unmuted_hvm (1/5 times with errors)
    • job 46232 AssertionError: only silence detected, no useful audio data
  • system_tests_extra

    TC_00_InputProxy_debian-11/test_050_mouse_late_attach (1/5 times with errors)
    • job 46063 AssertionError: unexpectedly None : Device 'test-inst-input: Test i...
    TC_00_InputProxy_fedora-36/test_050_mouse_late_attach (1/5 times with errors)
    • job 46063 AssertionError: unexpectedly None : Device 'test-inst-input: Test i...
  • system_tests_network

    VmNetworking_debian-11/test_020_simple_proxyvm_nm (1/5 times with errors)
    • job 46068 AssertionError: 1 != 0 : nm-applet window not found

@DemiMarie
Copy link
Contributor Author

GUI daemon crashes with qubes-guid: XGetWindowAttributes: Inappropriate ioctl for device You can extract more logs from var_log.tar.gz in https://openqa.qubes-os.org/tests/43364#downloads

That was due to an incorrect check for the return value of XGetWindowAttributes in an old version of #105. I fixed the problem in that PR. Please re-enable openQA on this PR.

This avoids having to define XLIB_ILLEGAL_ACCESS, which we would prefer
to avoid.
Xlib does not support file descriptor passing or dma-bufs.  The GUI
daemon does not currently use either of these, but it will in the
future.  Switching from Xlib to XCB is a necessary first step in that
direction.
Referencing a function that the GUI daemon no longer uses would be
confusing.
This is another attempt at using FD passing for shared memory, at the
cost of still requiring shmoverride.

The reason I am filing it as a PR is to at least give it a
chance to be reviewed, so that the work done on it has a chance of not
being wasted.
By sending a freshly opened Xen file descriptor at each request, the
offset is guaranteed to be 0.  Furthermore, there is no need to call
IOCTL_GNTDEV_UNMAP_GRANT_REF after munmap() ― just calling munmap() is
sufficient.

The only remaining reason to override munmap() is to handle mfn-based
mappings, which may have an offset that is not a multiple of the page
size.  These require correcting the address before the kernel will
accept the munmap() call.  Fortunately, there is no legitimate reason
for the X.org Server to call munmap() with a non-page-aligned address,
so it is safe to unconditionally align the address and pass the aligned
version to the kernel, adjusting the size accordingly.  Therefore, it is
no longer necessary for shmoverride to maintain any state whatsoever
about the current mappings, simplifying the code enormously.  No mutex
locking is needed, and no list of mapped pages needs to be kept.  The
result is that the code is simpler and less prone to bugs.
@DemiMarie
Copy link
Contributor Author

Closing in favor of #116.

@DemiMarie DemiMarie closed this Oct 3, 2022
@DemiMarie DemiMarie deleted the xcb-fd-passing branch October 3, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants