User:Keks24/drafts/Non root Xorg

= To-do =
 * Fighting for Schmusis (most likely) intentionally failed operation
 * general
 * user sticky (4711) bit on "/usr/bin/Xorg" has still to be set to make an autologin via openrc work or is it just "/dev/tty7"?
 * Automatic_login_to_virtual_console
 * .zprofile autologin
 * test non-root without any patches
 * look for error messages
 * test  patch with
 * make work
 * wiki article
 * instead of referencing to the forum, upload the files to the wiki to make them persistent
 * upload evidences about publishing the diff files under GPLv2 and reference to them
 * adapt new references
 * message
 * kajzer: When the wiki article is done, so he can remove his repository
 * ch1p: When the wiki article is done. Just because and that's why.
 * Ask for permissions to upload below diff files and evidence files about publishing under GPLv2
 * ch1p: When the wiki article is done. Just because and that's why.
 * Ask for permissions to upload below diff files and evidence files about publishing under GPLv2

For discussion page
{{CodeBox|title=for discussion page|1=

Non_root_Xorg
Hello ,

I am currently working on Non_root_Xorg and I would like to persist the diff files on the article, instead of only referncing to them. I do not want to blow up the article, therefore I was about to upload them here, but I am only allowed to upload picture files.

Could you please give the permissions to upload the files?

Thank you!

My current draft

PS. I also would like to upload and reference to the evidences from Evgeny "ch1p" Zinoviev and "kajzersoze", that they agreed to publish their work under "GPLv2".

~ }}

= author tree =


 * rootless_modesetting_1.20.3.patch: Evgeny "ch1p" Zinoviev, license: GPL2 (see e-mail history)
 * adapted from modesetting
 * amdgpu-non-root.diff: "GitHub: kajzersoze", license: GPL2 (see private forum message)
 * radeon-non-root.diff: "GitHub: kajzersoze", license: GPL2 (see private forum message)
 * new patch names

= Actual wiki article =

https://wiki.gentoo.org/wiki/Non_root_Xorg

Handling of DRM ioctls
No management of group membership can grant the  capability needed to perform the DRM ioctls. However, a simple program named has been made available in GitHub, which must be installed with the set-user-ID on execution file mode bit set (i.e.  would show   or  ), and can perform   calls on behalf of other processes, with the help of  (from package ). The program gets open file descriptors for character special files from a UNIX domain socket via file descriptor passing ( control messages sent as ancillary data with a POSIX   call), and command-line options specify the requested ioctl. Several ebuilds suitable for a custom repository are available for the package in the Gentoo Forums

Patches are available for making the,  and  X.Org video drivers work with. The ebuilds for their corresponding packages (, and, respectively) can apply them as user patches in the usual way.

Use custom ebuild repository

 * Display ebuild file in a filebox
 * Use a more recent ebuid. Reference to gentoo overlay??. Use at your own risk: https://codeberg.org/keks24/gentoo-overlay
 * Reference to forum posts
 * file upload should be considered as latest version
 * ebuild: https://forums.gentoo.org/viewtopic-t-1092792-postdays-0-postorder-asc-start-75.html#8478520
 * : https://forums.gentoo.org/viewtopic-p-8329654.html#8329654
 * : https://forums.gentoo.org/viewtopic-p-8376782.html#8376782
 * : https://forums.gentoo.org/viewtopic-p-8448466.html#8448466


 * Instructions to add the overlay manually?
 * Mask all packages
 * Unmask wanted packages. Research: Has an alternative been implemented yet?
 * Add entry in
 * emerge --sync / eix-sync
 * emerge --ask x11-misc/drm_master_util
 * emerge --sync / eix-sync
 * emerge --ask x11-misc/drm_master_util

Apply patch files

 * Only apply the patch file for the video driver, which is currently in use
 * Upload and reference evidence about the agreement to apply GPL2 to patch files

Modesetting: x11-base/xorg-server

 * Instructions to apply the patch files
 * Put download link here

AMDGPU: x11-drivers/xf86-video-amdgpu

 * Instructions to apply the patch files
 * Put download link here

Radeon: x11-drivers/xf86-video-ati

 * Instructions to apply the patch files
 * Put download link here

Verification

 * Read and get debugging information
 * Modesetting
 * https://ch1p.io/non-root-xorg-modesetting/
 * https://forums.gentoo.org/viewtopic-p-8329654.html#8329654
 * AMDGPU
 * https://forums.gentoo.org/viewtopic-p-8376782.html#8376782
 * Radeon
 * https://forums.gentoo.org/viewtopic-p-8448466.html#8448466


 * startx output

= Files =

ebuild: drm_master_util-9999.ebuild
https://codeberg.org/keks24/gentoo-overlay/src/branch/master/x11-misc/drm_master_util/drm_master_util-9999.ebuild

Modesetting: x11-base/xorg-server
https://ch1p.io/non-root-xorg-modesetting/

{{FileBox|lang=diff|filename=/etc/portage/patches/x11-base/xorg-server/xorg-server-non-root-modesetting-1.20.4.diff|1=
 * 1) Copyright (C) 2020  Evgeny "ch1p" Zinoviev                                      #
 * 2) This program is free software; you can redistribute it and/or                   #
 * 3) modify it under the terms of the GNU General Public License                     #
 * 4) as published by the Free Software Foundation; either version 2                  #
 * 5) of the License, or (at your option) any later version.                          #
 * 6) This program is distributed in the hope that it will be useful,                 #
 * 7) but WITHOUT ANY WARRANTY; without even the implied warranty of                  #
 * 8) MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                   #
 * 9) GNU General Public License for more details.                                    #
 * 10) You should have received a copy of the GNU General Public License               #
 * 11) along with this program; if not, write to the Free Software                     #
 * 12) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. #
 * 1) You should have received a copy of the GNU General Public License               #
 * 2) along with this program; if not, write to the Free Software                     #
 * 3) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. #
 * 1) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. #

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c index 8d29b13..1034ef9 100644 --- a/hw/xfree86/drivers/modesetting/driver.c +++ b/hw/xfree86/drivers/modesetting/driver.c @@ -34,6 +34,11 @@ +#include  +#include  +#include  +#include  +#include  @@ -62,6 +67,8 @@ +#define DRM_HACK_SOCKET_NAME "xorg_drm_master_util" + static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y); static Bool CloseScreen(ScreenPtr pScreen); static Bool EnterVT(ScrnInfoPtr pScrn); @@ -1513,11 +1520,66 @@ msSharedPixmapNotifyDamage(PixmapPtr ppix) return ret; } +static int +send_fd(int sock, int fd) +{ +   // This function does the arcane magic for sending +   // file descriptors over unix domain sockets +   struct msghdr msg; +   struct iovec iov[1]; +   struct cmsghdr *cmsg = NULL; +   char ctrl_buf[CMSG_SPACE(sizeof(int))]; +   char data[1]; + +   memset(&msg, 0, sizeof(struct msghdr)); +   memset(ctrl_buf, 0, CMSG_SPACE(sizeof(int))); + +   data[0] = ' '; +   iov[0].iov_base = data; +   iov[0].iov_len = sizeof(data); + +   msg.msg_name = NULL; +   msg.msg_namelen = 0; +   msg.msg_iov = iov; +   msg.msg_iovlen = 1; +   msg.msg_controllen =  CMSG_SPACE(sizeof(int)); +   msg.msg_control = ctrl_buf; + +   cmsg = CMSG_FIRSTHDR(&msg); +   cmsg->cmsg_level = SOL_SOCKET; +   cmsg->cmsg_type = SCM_RIGHTS; +   cmsg->cmsg_len = CMSG_LEN(sizeof(int)); + +   *((int *) CMSG_DATA(cmsg)) = fd; + +   return sendmsg(sock, &msg, 0); +} + +static void* +thread_func(void* argument) +{ +   int ret; +   int option = *(int *)argument; +   char cmd[32]; +   sprintf(cmd, "/usr/bin/drm_master_util %s -r", (!option ? "-s" : "-d")); + +   ret = system(cmd); +   if (ret == -1 || WEXITSTATUS(ret) != 0) { +       fprintf(stderr, "%s\n", strerror(errno)); +       //exit(1); +   } + +    pthread_exit(NULL); // you could also return NULL here to exit no difference +} + static Bool SetMaster(ScrnInfoPtr pScrn) {    modesettingPtr ms = modesettingPTR(pScrn); -   int ret; +   int ret = 0; +   pthread_t my_thread; +   struct sockaddr_un addr; +   int sock, conn, option = 0; if (ms->pEnt->location.type == BUS_PLATFORM && @@ -1528,10 +1590,21 @@ SetMaster(ScrnInfoPtr pScrn)    if (ms->fd_passed)         return TRUE; -    ret = drmSetMaster(ms->fd); -    if (ret) -        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n", -                  strerror(errno)); +    sock = socket(AF_UNIX, SOCK_STREAM, 0); +    memset(&addr, 0, sizeof(addr)); +    addr.sun_family = AF_UNIX; +    strcpy(&addr.sun_path[1], DRM_HACK_SOCKET_NAME); +    bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + +    listen(sock, 1); +    pthread_create(&my_thread, NULL, thread_func, &option); + +    conn = accept(sock, NULL, 0); +    send_fd(conn, ms->fd); +    close(conn); +    close(sock); + +    pthread_join(my_thread, NULL);     return ret == 0; } @@ -1769,6 +1842,9 @@ static void LeaveVT(ScrnInfoPtr pScrn) {     modesettingPtr ms = modesettingPTR(pScrn); +    pthread_t my_thread; +    struct sockaddr_un addr; +    int sock, conn, option = 1;     xf86_hide_cursors(pScrn); @@ -1780,8 +1856,21 @@ LeaveVT(ScrnInfoPtr pScrn)         return; -    if (!ms->fd_passed) -        drmDropMaster(ms->fd); +    sock = socket(AF_UNIX, SOCK_STREAM, 0); +   memset(&addr, 0, sizeof(addr)); +   addr.sun_family = AF_UNIX; +   strcpy(&addr.sun_path[1], DRM_HACK_SOCKET_NAME); +   bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + +   listen(sock, 1); +   pthread_create(&my_thread, NULL, thread_func, &option); + +   conn = accept(sock, NULL, 0); +   send_fd(conn, ms->fd); +   close(conn); +   close(sock); + +   pthread_join(my_thread, NULL); } /* }}
 * 1) endif
 * 1) include 
 * 1) include 
 * 2) include "xf86.h"
 * 3) include "xf86Priv.h"
 * 1) include "driver.h"
 * 1) ifdef XF86_PDEV_SERVER_FD
 * 1) endif

AMDGPU: x11-drivers/xf86-video-amdgpu
https://github.com/kajzersoze/patches/blob/master/amdgpu-nonroot.diff

Radeon: x11-drivers/xf86-video-ati
https://github.com/kajzersoze/patches/blob/master/radeon-nonroot.diff

= References and stuff =