From a10ffde406de720c6d2fd1cfbd9a905704b15b32 Mon Sep 17 00:00:00 2001 From: galternat Date: Wed, 7 Oct 2026 17:54:04 +0200 Subject: [PATCH] modesetting: release seatd GPU FDs through libseat ms_try_open() falls back to seatd_libseat_open_graphics() when the driver can't open the node itself, but every FD from open_hw() is closed with a plain close(). seatd keeps its own reference to the device, and the FD stays in seatd-libseat.c's list, where a later open that reuses the FD number can be mistaken for it. Export seatd_libseat_close_graphics() and call it before closing an FD that may have come from open_hw(). It does nothing for an FD that wasn't opened through seatd, so the driver doesn't have to remember where each FD came from. drmOpen() FDs of PCI entities and server FDs aren't closed on these paths. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: galternat --- hw/xfree86/common/seatd-libseat.h | 1 + hw/xfree86/drivers/video/modesetting/driver.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/hw/xfree86/common/seatd-libseat.h b/hw/xfree86/common/seatd-libseat.h index a9da51a0b0..fa6252b305 100644 --- a/hw/xfree86/common/seatd-libseat.h +++ b/hw/xfree86/common/seatd-libseat.h @@ -46,6 +46,7 @@ extern void seatd_libseat_fini(void); **/ _X_EXPORT extern int seatd_libseat_open_graphics(const char *path); +_X_EXPORT extern void seatd_libseat_close_graphics(int fd); extern void seatd_libseat_open_device(InputInfoPtr p, int *fd, Bool *paus); extern void seatd_libseat_close_device(InputInfoPtr p); diff --git a/hw/xfree86/drivers/video/modesetting/driver.c b/hw/xfree86/drivers/video/modesetting/driver.c index 88c15a4d20..0b0afef9ba 100644 --- a/hw/xfree86/drivers/video/modesetting/driver.c +++ b/hw/xfree86/drivers/video/modesetting/driver.c @@ -260,6 +260,15 @@ ms_try_open(const char *dev) #endif } +static int +ms_close_hw(int fd) +{ +#ifdef SEATD_LIBSEAT + seatd_libseat_close_graphics(fd); +#endif + return close(fd); +} + static int open_hw(const char *dev) { @@ -286,7 +295,7 @@ open_hw(const char *dev) break; } - close(fd); + ms_close_hw(fd); fd = -1; } } @@ -345,7 +354,7 @@ probe_hw(const char *dev, struct xf86_platform_device *platform_dev) if (fd != -1) { int ret = check_outputs(fd, NULL); - close(fd); + ms_close_hw(fd); return ret; } return FALSE; @@ -380,7 +389,7 @@ probe_hw_pci(const char *dev, struct pci_device *pdev) sv.drm_dd_major = -1; sv.drm_dd_minor = -1; if (drmSetInterfaceVersion(fd, &sv)) { - close(fd); + ms_close_hw(fd); return FALSE; } @@ -390,7 +399,7 @@ probe_hw_pci(const char *dev, struct pci_device *pdev) if (id && devid && !strcmp(id, devid)) ret = check_outputs(fd, NULL); - close(fd); + ms_close_hw(fd); free(id); free(devid); return ret; @@ -1119,7 +1128,7 @@ FreeScreen(ScrnInfoPtr pScrn) if (!(ms->pEnt->location.type == BUS_PLATFORM && (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))) #endif - ret = close(ms->fd); + ret = ms_close_hw(ms->fd); (void) ret; ms_ent->fd = 0; }