From patchwork Thu Jul 14 09:10:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 9229213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C4E86075D for ; Thu, 14 Jul 2016 08:17:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DF1F26464 for ; Thu, 14 Jul 2016 08:17:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3287D28159; Thu, 14 Jul 2016 08:17:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A04C926464 for ; Thu, 14 Jul 2016 08:17:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DA116E89E; Thu, 14 Jul 2016 08:17:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0058.outbound.protection.outlook.com [104.47.40.58]) by gabe.freedesktop.org (Postfix) with ESMTPS id F0CF16E219 for ; Thu, 14 Jul 2016 08:17:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=f24Z1/hhTIumNR90P+3mgeK8eTMP7jBfJoDWtGvKtRM=; b=ECvm0iC0i5GLJx0PjnMdB5aUXM+6cWV5tcA1WeCX9hhqx74wbQyzBWLMzsxbuRWEF0XiDkb03rPeERcztx5FbrHtnLqxHIocMjyiJI0xNPtBI9zBqXWtZyXyb7oYf0Jk2I6eCq0jiS1Wvc+mjv5fCsDo+neL1HjcLJM56JSrViY= Received: from CY1PR12CA0031.namprd12.prod.outlook.com (10.160.137.41) by BLUPR12MB0611.namprd12.prod.outlook.com (10.163.217.17) with Microsoft SMTP Server (TLS) id 15.1.539.14; Thu, 14 Jul 2016 07:44:50 +0000 Received: from CO1NAM03FT020.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e48::203) by CY1PR12CA0031.outlook.office365.com (2a01:111:e400:4c1f::41) with Microsoft SMTP Server (TLS) id 15.1.528.16 via Frontend Transport; Thu, 14 Jul 2016 07:44:50 +0000 Authentication-Results: spf=none (sender IP is 165.204.84.22) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=permerror action=none header.from=amd.com; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV02.amd.com (165.204.84.22) by CO1NAM03FT020.mail.protection.outlook.com (10.152.80.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.539.16 via Frontend Transport; Thu, 14 Jul 2016 07:44:50 +0000 Received: from SCYBEXDAG04.amd.com (10.34.11.14) by SATLEXCHOV02.amd.com (10.181.40.72) with Microsoft SMTP Server (TLS) id 14.3.266.1; Thu, 14 Jul 2016 02:44:24 -0500 Received: from shlnxcqesrv2.amd.com (10.237.70.153) by SCYBEXDAG04.amd.com (10.34.11.14) with Microsoft SMTP Server id 14.3.266.1; Thu, 14 Jul 2016 15:44:19 +0800 From: Qiang Yu To: Subject: [libdrm][PATCH v2 1/2] drm: Fix multi GPU drmGetDevice return wrong device Date: Thu, 14 Jul 2016 17:10:55 +0800 Message-ID: <1468487456-28666-1-git-send-email-Qiang.Yu@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.22; IPV:CAL; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(428002)(189002)(199003)(16796002)(7846002)(101416001)(305945005)(106466001)(26826002)(356003)(50466002)(5003940100001)(36756003)(105586002)(48376002)(53416004)(229853001)(2351001)(2906002)(86362001)(586003)(77096005)(87936001)(19580405001)(4326007)(8936002)(189998001)(246002)(8676002)(110136002)(92566002)(50226002)(50986999)(7696003)(19580395003)(11100500001)(47776003)(5003600100003)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR12MB0611; H:SATLEXCHOV02.amd.com; FPR:; SPF:None; PTR:hybridsmtp.amd.com,hybridsmtp02.amd.com; MX:1; A:1; LANG:en; X-MS-Office365-Filtering-Correlation-Id: 873a85c6-b244-4bc7-f008-08d3abbabca6 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0611; 2:3g0NLNNAcAfLEOfZ1sjzb5SJN5P+FN+l6/8BlVR++UTrzyAwiQse0/cbHDyw+ZmaWOvDcmJkBlr63O4s4bMBOQXdTbRbrDx13iGR6Cxsplbq5ITNVqmkGb5umh6S9RufGLX88w7nUEp6XQgu1bhmaC80ppQId3P7FQnHEyEAF2xVtstRfp6lGz8e+T/0EzwV; 3:serOONQ9n90pAWsIanShZ5wfp9gODc7GT43C4okLQDiWdMRwVOrlkkZqtaV54Mdp+jLj8BehgwxEKOSRCvSuAxZRNCdkdhEQrDJbGCEfPvDoe/7XRffxAx+S7c7Gj6C97sM/foeja0uQhzCyJ4W2g4gLNKAPcdExl+wha+KQWAvjcJUPslQU/Jb3gGCoNA6HV2muDWoOS7EhuI4DvP/ONdQdYg7wGWt85EzB1CkiSvY= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR12MB0611; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0611; 25:KjrUUwtYvNxig9/hiCv5N0bHzaUPRL63bdfuge9BIxDuoL9O6yH7whTPpfancaOyrKXMCjlEyT8YCtlwFeeHuAFMd43aMuqyRTIpHOLG21V0qQlE2/r1eWIraG9NX+WDYEuBvxXSUmCT3dtKczuJd6+qmhNgzy1hClTpVS3S9lOlhnyh0JIVASnFS1XF/QUmZUtyY6k6uXyl5/AzOlOEe8AEjPaTeZ7EBHxEFA0JLZW5RmjATX+Av3XiZwmmox+z1AXTM3HDVUlyM8T4fT1vY86KQi971XVKsqU+aRixh1aqOGCVn2VJ74Ufdj1ByPZ2/a5trspdv8uu6m9cu8BfyrjWzCmasUowtOm7HF+kXUcxvjRP6gnKK06XvyOdec83pJSUww7/zdGyboubUumpT+JEdgr8jwve3I9rej0+aiuEGupWPlV9iME/0NjNZGidiLDmvNjtviKdnMCXuYYIqrtHxdHRMA1DB7Cn32+/4tqpy3nEXTq2ssyvcwoiCa49bPrH5Wy9BJZ08zEzY/D79ZG0imhM3SFJZSbuvwL2D418Rg5VpIiTgkbGv5VVh/6RvxjYZwJYVbUnoa9lYLRozIPJ/AdiiBS1nNwlXVJ+2JQhH2TGdHez8zpZ7Fn39McoZeLeXgd7SPvN4+xE3DoJBo+gb/omIWcBtKkx9K4s8SxFADG0de0kdBWZuA/AK0Lwmdbgp32cqY84In4Y/38u/aRcxBW7j3GwCxC8Yomtn2a9hbMbsi3EJqzxhDecosS5 X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0611; 31:3F3a0sCEHvTtXS5Q6Q17/BEI8KJPx9o3EbOCvu5fnc23zwpCHaXyIBwxirWhS50AlTNCQA+TC1djNKxBlydBAiWfP41Ijo09ZQMD4MBfliYZqennnwye0B0Q0dcZSZnlim8Gb5KLGeB+05aLzNDvJogzzYIXGCC7NqFkDQi2jAYCpoLg3tQe/id26B47ffU+9vqVx20YqemhkltbVgEUDA==; 20:ArNHKgbEbnXASw58A000GjWe3EesNMdW4gavBgHYQ+Ffj393DjhYSZjZKf03wC6veoHfXcm5hQUNc7fOAEf4GXPgC6YQQkIasJbYRqHH9nXbEZ/wAPl9i5Cmw22hnvbwrZbeiR7PecQePWxoEP7UEvSMAAHQWQdZq/AqxQEaEO7O7Y3WQz94noZBP8HV84vADJuzRV+TXZa0RokMcB+n/PRHqKRDBQCHPL28M6tIIu3BE2fEfkPwyJh0+ydPgfmfHityYPb3GCO/0qoVW3kVlo86l7Vz32VQAppIrVK+2UGLlF3/SSe1g9n18hnpVdYVKZxmlAcIigyCZXl4DLtzE4TbaXZvxPW3kWRi2vE2mYfO5AqSXoemN9BWmx6Syeo2Q0aaZLpm7+JCPhIMvY/4WLrBU8z44EyD2G3jV2Itb2dgAE9qz9AN6uYddu+Q6WpqmSHNpDxYU2P3T8hoy0IUk8qYPvvs3yipuvewG9C3SZQy7mpGK+6FMjEavLuUqJfB X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(8121501046)(5005006)(13013025)(13021025)(10201501046)(3002001)(6055026); SRVR:BLUPR12MB0611; BCL:0; PCL:0; RULEID:; SRVR:BLUPR12MB0611; X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0611; 4:mLTKqOBchiH6GFomLe6XTTBI+so1vXjrM8+iEFMMqADyImHFw1nHoO9Yip0zB1CgsWjvOd0wmLoLsGSxijAkhLejkqJmTitgPyqslh4bMdLtSsgWm3JloBVcCuFz7WWkrB6v3N29dB+dH6ZIfssQvmQJAvBhvn2kjh1R5ZymSqwJtu8JgBUuW0k6qQfhc4WZmMqjV94Z/a9GNXkJMf3F9u7bHrPgx067XjHosHFQwla4VZ/bG6tkKYu3/Y4vTnJ8MxBqh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EpLhJzTPadPKIaCnBe9Rz7Xj5Upma3ct6zg==; 24:Y3Y9zyoBdSRPt42C/85ISJlv942ULiXVhLFPD+tz7uOmYhLL5T3D19Em4IGV2GpqmKDFNUpDwil8xvvaf1mvBjgNb7CdSRUde0NihqYHrX4=; 7:T4JA6GULj0EAbnx8q8u+lwbF3tC3uGyg7apLiP0s6p+iZkgqredGyKq9t8PbKkry3aS+vAT7IjHrug9//Uo7jtiKpqM1qq86skSZRiT73bGO/LjzM9UFenNLZ1dbLFOw3bOCNmycgYAm1z8CPkuevACoRhLDGUICSvtRNY2Oq66aYtkzENPkudXhBZlRLjvovRcWA5iSI4IixjEZxDvMAdS586w9L5M0/Gw/3uh1VWxKuASl3QwVVVGP5+0ysOML SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR12MB0611; 20:Gbe9p+1EHRxqYCKel8hq1XrjSEXFnEQFz8tfucYAbPVfmnn+b2UJVsjyfSzjrojlJauu+qeU/1dnIqaySbxGHc9Bbsf9Fq6sC9565bp6WqYerciSR7S6BtD/y+Fj31RIfu/g6BxezbDk7XRSV5psljbQ63DIR6+QEVU9FO/DwIr7SJuqynEiw3o1hjcOknERt33iIajgIbcY4HUmBA3bFmdiu3NRym9MI/+tZ2DgK8J18MJVdCyR33KxQH36Zgsj X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2016 07:44:50.4664 (UTC) X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.22]; Helo=[SATLEXCHOV02.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR12MB0611 Cc: Qiang Yu , Emil Velikov , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drmGetDevice will always return the first device it find under /dev/dri/. This is not true for multi GPU situation. Change-Id: I2a85a8a4feba8a5cc517ad75c6afb532fa07c53d Signed-off-by: Qiang Yu Reviewed-by: Emil Velikov --- xf86drm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 6689f7c..19001db 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -3087,6 +3087,7 @@ int drmGetDevice(int fd, drmDevicePtr *device) int maj, min; int ret, i, node_count; int max_count = 16; + dev_t find_rdev; if (fd == -1 || device == NULL) return -EINVAL; @@ -3094,6 +3095,7 @@ int drmGetDevice(int fd, drmDevicePtr *device) if (fstat(fd, &sbuf)) return -errno; + find_rdev = sbuf.st_rdev; maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); @@ -3154,17 +3156,24 @@ int drmGetDevice(int fd, drmDevicePtr *device) local_devices = temp; } - local_devices[i] = d; + /* store target at local_devices[0] for ease to use below */ + if (find_rdev == sbuf.st_rdev && i) { + local_devices[i] = local_devices[0]; + local_devices[0] = d; + } + else + local_devices[i] = d; i++; } node_count = i; - /* Fold nodes into a single device if they share the same bus info */ + /* Fold nodes into a single device if they share the same bus info + * and nodes with same bus info will be merged into the first node + * position in local_devices */ drmFoldDuplicatedDevices(local_devices, node_count); *device = local_devices[0]; - for (i = 1; i < node_count && local_devices[i]; i++) - drmFreeDevice(&local_devices[i]); + drmFreeDevices(&local_devices[1], node_count - 1); closedir(sysdir); free(local_devices);