libdrm: Fix issue about differrent domainID but same BDF

For multiple GPUs which has the same BDF, but has different domain ID,
the drmOpenByBusid will return the wrong fd when startx.

The reproduce sequence as below:
1. Call drmOpenByBusid to open Card0, then will return the right fd0, and the
fd0 is master privilege;
2. Call drmOpenByBusid to open Card1. In function drmOpenByBusid, it will
open Card0 first, this time, the fd1 for opening Card0 is not master
privilege, and will call drmSetInterfaceVersion to identify the
domain ID feature, as the fd1 is not master privilege, then drmSetInterfaceVersion
will fail, and then won't compare domain ID, then return the wrong fd for Card1.

Solution:
First loop search the best match fd about drm 1.4.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Emily Deng <Emily.Deng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
main
Emily Deng 2019-02-14 15:53:38 +08:00 committed by Alex Deucher
parent 1592d471bb
commit 56c21f877b
1 changed files with 23 additions and 0 deletions

View File

@ -586,8 +586,31 @@ static int drmOpenByBusid(const char *busid, int type)
if (base < 0)
return -1;
/* We need to try for 1.4 first for proper PCI domain support */
drmMsg("drmOpenByBusid: Searching for BusID %s\n", busid);
for (i = base; i < base + DRM_MAX_MINOR; i++) {
fd = drmOpenMinor(i, 1, type);
drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd);
if (fd >= 0) {
sv.drm_di_major = 1;
sv.drm_di_minor = 4;
sv.drm_dd_major = -1; /* Don't care */
sv.drm_dd_minor = -1; /* Don't care */
if (!drmSetInterfaceVersion(fd, &sv)) {
buf = drmGetBusid(fd);
drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf);
if (buf && drmMatchBusID(buf, busid, 1)) {
drmFreeBusid(buf);
return fd;
}
if (buf)
drmFreeBusid(buf);
}
close(fd);
}
}
for (i = base; i < base + DRM_MAX_MINOR; i++) {
fd = drmOpenMinor(i, 1, type);
drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd);
if (fd >= 0) {