From patchwork Fri Aug 31 11:54:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10583643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F24C14BD for ; Fri, 31 Aug 2018 11:54:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F094281C3 for ; Fri, 31 Aug 2018 11:54:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3101E283FE; Fri, 31 Aug 2018 11:54:51 +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=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9F95281C3 for ; Fri, 31 Aug 2018 11:54:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9CD136E8CD; Fri, 31 Aug 2018 11:54:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0047.outbound.protection.outlook.com [104.47.33.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id B3E5A6E8CD for ; Fri, 31 Aug 2018 11:54:48 +0000 (UTC) Received: from fedoratest.localdomain (155.4.205.56) by SN6PR05MB4590.namprd05.prod.outlook.com (2603:10b6:805:38::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1122.9; Fri, 31 Aug 2018 11:54:45 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org, linux-graphics-maintainer@vmware.com Subject: [PATCH libdrm] libdrm: Allow dynamic drm majors on linux Date: Fri, 31 Aug 2018 13:54:19 +0200 Message-Id: <20180831115419.4922-1-thellstrom@vmware.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: AM6PR06CA0027.eurprd06.prod.outlook.com (2603:10a6:20b:14::40) To SN6PR05MB4590.namprd05.prod.outlook.com (2603:10b6:805:38::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95bc9078-6012-4e9c-2055-08d60f388c34 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:SN6PR05MB4590; X-Microsoft-Exchange-Diagnostics: 1; SN6PR05MB4590; 3:5kuhcr+oAB/5z2ygCtz6HmAEdnbz08pQGP479lKatOIuHFkkcOUapkLkKM4PUn6qRqA/D5ylpSgQyqS/Fhnc5mNdL803xzxi79HtA/CUUJeBkQXsfFhw/3vdCFWFmRrKIbLDaJh7GoNWJeNYC3gLVc95WlKeAJ6bGpY7RqQWabaaD/hdCPwQVbMIa1ByHsjau3mHuc6u+CoUlhHe7LXwqXR1L1u74Nm7bBm7tZoJyZqIMtTNRC5bdxYDT3jx27oz; 25:0nIfSqPAhIamgCYV13enSWUFAA1fPr9jG9ZTtzWBV8TjuRxdXw/Y3/YjQBcLU8d1IsMJYttrriPAqRwAMkzRMIjkgySiCITTicQ3LzwrOZMU77GA+9t3ZrwmY8zHNKow0u07fwEdG/98AJGG98c62xO0pR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6kMbURkMmiqAdbvJDJSiYss05OSSlU5JXG9VU6SlKhL02u6ZpDTt0m26qwL3V6MCxa69G/wCaY+Y5kL4rdBqYY8pop0bNd2nWKKc=; 4:o/lBwAC8cu+tLGT8RftDmoqCpv+u5vRONcQb3dsaHFW5uNGPhKPJR84S+znaoDwOnvc3Ss2BGyOYa2AnMnzAndpfLC+RIRpcbAy9DNqy1ZGW8LQbrhPx7koEca5lMweNhlfP+PEFot6T6rL34GjKSJK+xoLmKwhggZmbMeKpzgcaceXgbpt0CL155WphH4l8DVEZfHbcu9ajH8cgAoTn4MSwE51+jAxGjw2pdh7b6oBfIGob9vVm2QQf/Ls7nRzEHyEkZLXS2OgD/du39M4NTslCUJUxy0gjU7nBNaO2mo0rXZwr/i3Hg+S7FjwBxXn7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(10201501046)(3002001)(3231311)(944501410)(52105095)(93006095)(93001095)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699016); SRVR:SN6PR05MB4590; BCL:0; PCL:0; RULEID:; SRVR:SN6PR05MB4590; X-Forefront-PRVS: 07817FCC2D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(136003)(39860400002)(366004)(396003)(189003)(199004)(5660300001)(476003)(956004)(2616005)(6636002)(6666003)(1076002)(3846002)(6116002)(4326008)(107886003)(106356001)(105586002)(51416003)(386003)(6506007)(52116002)(186003)(26005)(316002)(478600001)(16526019)(16586007)(966005)(2906002)(53936002)(68736007)(86362001)(50466002)(6486002)(25786009)(97736004)(50226002)(36756003)(48376002)(81166006)(81156014)(47776003)(7736002)(66066001)(305945005)(486006)(8676002)(6306002)(6512007)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR05MB4590; H:fedoratest.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR05MB4590; 23:G6626YKnL7ZvH0eSX+L2FQyG75F0IUUJ+qnDDo5/x?= zik/EDnTOBa6SCTb+VeAtN8aOGsHXBhia0EHrae2q8N7bEixo5c8DhWZ+xtj+XXuxHMNKkzIZQHxodJ/+Ln8fCHIk8oNTJ9IxIfS2mSSkX3keOttQl54WJ0/0J3Jw1bMUvOGWWuGnYLV1RueqW07kz35DWBQuKvTlCBhNBdKKbRxh8IKIKV6mwq6SyHsXVJRteIcZ+L1szC1KHn0MK1dD5NT7w4vFgNHhUPnC5sysx+azpazU35Py6WEggjzTV26b2MDLoVI9u/j+ExcLheG5zn8Bap3QhuE+7Z9lZqQQvYKeidVgwQxSRtcagoYxdYonnABYGeflSF+xLF8QCL3OwIYduEI1f+PHuRrAkUwEfNesJ1fbC7O+7xWSSSZRJCYAjB+TSSzEMESIsazIfaICEPEtIxl431+3aW4HzIfVsawirB6eaOQQ02R3M/5Twc+2/duYKZq2jhRuO2f59T1E11OsUO4h4USXNNNpYCWHboAHCLrcpEMMCiaiLNdIAi72JMtXpOkCeccz5ffp7xFEad062s0FHZlvEOfcU/zuZMhEX6mMgn9Cr4aUx06gYXzmHo3T+qHs3N6HAxpUDTaNkPRKPK7qCjfd30tEtb14AT7VOsPzvjFqqZMTW2hze2K6jvUABlE1ffhcds/MnvC1tPgLd1qe0pU04XcyOa2aAotUN9BVpDDUJ8edLrKGaBhYAkE8FyTM5chiAt7Ak85o5reJdGaZw9ZyRnhfUADdL2UMuV3apIA5AECYbIPFzsGi/tNzMZh1oTt20ZKD59WkDc+9bk/ooBHjqF6HBJvXDAwwuyuvffiWtA7c9Erk4jOvGBlz3YeArZ9isrzJti3bfD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M2EagOUZNsa8nWbFlJdXBrfV2bckgMIwmexZ0IsvGpTvrRqAtXrIGpshs+nTPURXALUNbLLClbq7GPytWavOI9zqzMlR81RIDJO/pq372nwA==; 5:OJtgZ39AF4mio2orAc76ErFpeibGbfx15+q7Muf/5BXKHkBBKi89WTT1LmLWMiZlBygLDCgccQfqK8sRhfW7pXgR+2y7lLL2+SUkfBxtWClVeJFXISbLemaCLS57DRVO1QeF6gQfqHsA2Pi/2UFdCDHMH74vJGNMX+bUrdch//E=; 7:Oe9BZsDiT+yV1gxj7tlgoZD7x5dX/iPnMb/KOAMEiL9jR04B0pgeQfmjLcSMEdcYRV99fEEgCZntZUGuOshAz3DZwA5jBETdjo9vDyYAudUdPUDDfkmar4pPI+y8aRbmzhA9ml/QN/17t8AmGE1JvLJomL9HOI1QwV7E3GCoB1aBJvdfLndwBrJjtmA17EjGADznRhQBay35ohdvR4W4eKZm2KT0UcaS/dv34tzjbQJ4VBp7E2o6KWOYYBmbgupB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR05MB4590; 20:4UuAabafqqRP2l1eFDugFcECmdhnKt3QgdiQ+EgyG8BN0pnCwkmgIu0MHJCemyApvx1gk1uTAlP92PecXGt+K/8pnfGszC18mW/x8D1ub9AXYb/s9SDRlon8MGnG/yOL9MuKqU8xy3kdL1AxM7v/3n2ZU7AJ8aew6lCS4UkKRLc= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2018 11:54:45.7130 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95bc9078-6012-4e9c-2055-08d60f388c34 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR05MB4590 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP To determine whether a device node is a drm device node or not, the code currently compares the node's major number to the static drm major device number. This breaks the standalone vmwgfx driver on XWayland dri clients, https://cgit.freedesktop.org/mesa/vmwgfx and any future attempt to introduce dynamic device numbers for drm. So instead of checking for the device major, instead check for the presence of the /sys/dev/char/:/device/drm directory. Signed-off-by: Thomas Hellstrom Reviewed-by: Eric Engestrom Acked-by: Dave Airlie --- xf86drm.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/xf86drm.c b/xf86drm.c index 7807dce9..4cfc5d3e 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -2761,6 +2761,21 @@ char *drmGetDeviceNameFromFd(int fd) return strdup(name); } +static bool +drmNodeIsDRM(int maj, int min) +{ +#ifdef __linux__ + char path[64]; + struct stat sbuf; + + snprintf(path, sizeof(path), "/sys/dev/char/%d:%d/device/drm", + maj, min); + return stat(path, &sbuf) == 0; +#else + return maj == DRM_MAJOR; +#endif +} + int drmGetNodeTypeFromFd(int fd) { struct stat sbuf; @@ -2772,7 +2787,7 @@ int drmGetNodeTypeFromFd(int fd) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) { + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) { errno = EINVAL; return -1; } @@ -2837,7 +2852,7 @@ static char *drmGetMinorNameForFD(int fd, int type) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return NULL; snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/drm", maj, min); @@ -2871,7 +2886,7 @@ static char *drmGetMinorNameForFD(int fd, int type) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return NULL; switch (type) { @@ -3731,7 +3746,7 @@ process_device(drmDevicePtr *device, const char *d_name, maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return -1; subsystem_type = drmParseSubsystemType(maj, min); @@ -3845,7 +3860,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return -EINVAL; node_type = drmGetMinorType(min); @@ -3911,7 +3926,7 @@ int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return -EINVAL; subsystem_type = drmParseSubsystemType(maj, min); @@ -4071,7 +4086,7 @@ char *drmGetDeviceNameFromFd2(int fd) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return NULL; snprintf(path, sizeof(path), "/sys/dev/char/%d:%d", maj, min); @@ -4097,7 +4112,7 @@ char *drmGetDeviceNameFromFd2(int fd) maj = major(sbuf.st_rdev); min = minor(sbuf.st_rdev); - if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode)) + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) return NULL; node_type = drmGetMinorType(min);