From patchwork Tue Aug 23 21:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12952614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 899D3C32772 for ; Tue, 23 Aug 2022 21:06:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 311B410F9BB; Tue, 23 Aug 2022 21:06:54 +0000 (UTC) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8DB6C10F9BB for ; Tue, 23 Aug 2022 21:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661288796; x=1692824796; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=fJ9pjNm4NMYTgmupKFJ8FJfVgbI6Sq4DdpGtBCUttI8=; b=jyE6lm4XPCG9Z8FeR2sEI7FqNCzN7xDOeMcbYc15mGcEeO9OPDrdYaUW Grcre4CmwpzHuRvFoBoDgqFmRNW0tcbAtVU06Kmcrxxv49+HkSIW2j2/H Sko2HCjjSZ4z6KK0zWCbBZFqGiGoDa0+iuuQAe5kcqzDPOfkFjh4B57xv OfRGGfqG+VYRb47qXzRHD+bilNMmO9wtc8mxiNhM31MxoDkZntcea4Cjd wqTGkXyeMeJFcyrzMXIPCNT0qgOD8vTXlVYWAVULgmATRiluK5tS18eO6 YPya+LiUdkH1NjqIdb0T+gDbklvRPEKkIkyf1bYcDCOSwMUgvevZNf37s g==; X-IronPort-AV: E=McAfee;i="6500,9779,10448"; a="273547894" X-IronPort-AV: E=Sophos;i="5.93,258,1654585200"; d="scan'208";a="273547894" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 14:06:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,258,1654585200"; d="scan'208";a="605792502" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga007.jf.intel.com with ESMTP; 23 Aug 2022 14:06:34 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:33 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:33 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 23 Aug 2022 14:06:33 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.170) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j8V/YvLn0sZoX//ojguOsFVzBBWdX9SP65t/nRw5eRY63K5NfQk7VAb8xRwlMU7zt+igzJ3tZds1yL1LKpKDjqZuIGlPqFInUrpuvVp/1Dgpezg+gMENvprIAb+OHnEjKhGIlMmJzUEZ5IA3UQQ1l4Hro2A8SODK3wDEFfTEmLYtK/L1cXTFv4y0bQBXf/g4unmiRO6d8mk9M4VOAB9tRiaS+lFNulAgseBLbfskEP4NUr0pVqssDSqf0qB5iS0i/j67YVFzeH+7WDjD02zzGlK/7qiP7Im53/FyAPRGW5ZFUtimVlLzC62bscSZJcGIGibAT4nMK21b2HgAtmnJiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BDkLFHPmfsDohvcMf5kOhuH7rDPkqhTsb/4eTNUNr5Y=; b=O1yZbw0H5KwRpVJtzHdWF1T4s+89onqiNNlzZKRU1lMX3NzBKa/VSaLwbLlunBWdWKWL0HyoGm1gEax4qzn5AMlglM9/GS0wFkujhXplDOXYSU9XVIEIQnWxmtoWHKbvhMDzjEm8+tqmMoRE0LyY1VQzST09FOFc7XVXC1WPKvkc1A6gkTauXHqEV3Sc+fdQmypVJrIoHtt6xmn36TUm0fMRgtKUowvRFk6RICtYgQ3gj1qtwPwADf28Vt/zezA1v3I5HduX5H0ADiKks5E3dsAvpXWXkjNDSpyPqgWOPI3jIw9icYPnSkI/M9VGtNvcpMdDJnJxoQsdYQwzuyU2ZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by SA2PR11MB5130.namprd11.prod.outlook.com (2603:10b6:806:11d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Tue, 23 Aug 2022 21:06:31 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::b04c:807c:4ea0:c62e]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::b04c:807c:4ea0:c62e%9]) with mapi id 15.20.5566.014; Tue, 23 Aug 2022 21:06:31 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: Subject: [PATCH v2 1/2] drm: Expand max DRM device number to full MINORBITS Date: Tue, 23 Aug 2022 23:06:11 +0200 Message-ID: <20220823210612.296922-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220823210612.296922-1-michal.winiarski@intel.com> References: <20220823210612.296922-1-michal.winiarski@intel.com> X-ClientProxiedBy: AS9PR04CA0055.eurprd04.prod.outlook.com (2603:10a6:20b:46a::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 621d0f55-39e0-4444-24fe-08da854b5a14 X-MS-TrafficTypeDiagnostic: SA2PR11MB5130:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QQEZa12bS/rCvxmxmYA736rDROkTrsCzJfso3y2gm/spF75dQEiIOJUmg++M5EJ7Z0AYxDhk13PEx5MQc2XM7S142z2sttU8Oo2ydl5EMgujo8WcMqJOOfdn5exveA6VJF+h2VtS464rRUGUR1VE4NniKPy3zk9z4HIb16ungmVb2+yfU55WaoWVLNwGs1ZqYm4kBbxWpxRxgcllAnhSqAxBEiHGJl8I7d1PF/zVSh6lJxIqwG/0NC9XF31Bv46TuxOlQyIdE9e6DzvTihhy5WGxc3gO1VpcQszT3eV+HzfVzEELQd/GHxMeyuRcp3eny5ybqBsBMMZ/wLv92VTlR0I76SA+0rrcxis60TELnsaFqUaYl/5mUJg5c/0xAuiAg3dCXNfnSHSREDW02XmiW3fhZpSpQoEBiYXyfjVttVSJfdqDSUgsOyvIK6IjOfBwHBFn2B2i+vVcs+w1JDNSu58KKFwlEJwEWfum/enSXaTxoC+SShg+mdMZcP4c2MsBzFr/yMxaFEdwtQQ6+8psjp+x0tE7smkql8Bmgk+3kghrwwGgnz4bRrR5xxp0PocVtI1ZquOIW1lEpmgq3MuF5nROY0cIw6mue5UlEOIojzi5Ngjng9B8aZ7z18WZLS8LxVXtoGBMisprfGQeagQg9YydSB0rNJfg2OEQAhmcPqmPpbYXP3D+lAkFafMR4Q9yHM25sVksiWAM7IWeQnEJdg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(39860400002)(136003)(346002)(366004)(396003)(6512007)(6666004)(5660300002)(186003)(1076003)(6506007)(2616005)(8936002)(36756003)(26005)(86362001)(41300700001)(83380400001)(478600001)(6486002)(38100700002)(82960400001)(6916009)(316002)(54906003)(2906002)(4326008)(66476007)(66556008)(66946007)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rcZTpx98bDRYVJ6uiSuQQU/tmVVl?= =?utf-8?q?ImNPgVWBTy33WO5F36dXXgZrhC/sRx5+DVe7XxcwpHop6ta0RpzWV+sLRXtMumk0e?= =?utf-8?q?hO1Lfm8tQDsIWA1xDOhbmlqd0Jr81f/AqXKqu2/rf9mpRpDjwaY/LNrPB50DZFF1z?= =?utf-8?q?3ztPfX8NFD+IoQenusx5Rve/j3MXtXRCRQ8a5PWHgHtuFD6cbASFrVSt2lTGzOvZK?= =?utf-8?q?6LNG1aA3T1KpmNk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PMfnEkutHAUJzqiZn6fPy8DJNFEs1cp+TW1oeEdJFuiQUrIeClXivt?= =?utf-8?q?l0FrozEgdNjeF/NA4WuSW+mTotLy9kkmSqXC9XbYSWAY9eEZDFMPU6ocY3HG/NwiU?= =?utf-8?q?pnkkAmubX2tesh8E3qhjHxuVwyv4bBoZ18mtOv3zHlzTb4Q1jzu/7233z9DJv8Ap4?= =?utf-8?q?yq2+0ttUVcn63t+74OJnJOapUkffWPR+HBOz9tH7OhomdAZpUqVB1b2rlRXad7LSR?= =?utf-8?q?+aIz/vZIUvCExeIjQFfevBzLADsgAFM7UlAOD1C6Ta3K57BhJMKuRzrOIIZBVJ1+6?= =?utf-8?q?7iU4z8J31/Cx1bWLo4ZCQGl2ZiuMIku091rmn+5SZ4IhwqNoVhG59Kfm+/NOQxIOx?= =?utf-8?q?1FfX4M9W6UnfRMyRqYnTdoGFjrJXZFsHPDH+Enk1/sjmo5NDE16/jD7tzP8rg7tJR?= =?utf-8?q?EbPi4jliXtU8NG/TE1p9Jhw0oBhT2DL+7g=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 621d0f55-39e0-4444-24fe-08da854b5a14 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2022 21:06:31.2750 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: X8xIYZ91YHSOql6Mck0HcN5XeMlTS2ITs5JflCWmoTJnCM7J8vKEckeI24XSDKuqMhk/wZaaaxuzY868u6gVhDnO1CRXO5f1YfB36uIoMBs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5130 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , David Airlie , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Having a limit of 64 DRM devices is not good enough for modern world where we have multi-GPU servers, SR-IOV virtual functions and virtual devices used for testing. Let's utilize full minor range for DRM devices. To avoid regressing the existing userspace, we're still maintaining the numbering scheme where 0-63 is used for primary, 64-127 is reserved (formerly for control) and 128-191 is used for render. This is continued for minors >= 192 (192-255 for primary, 256-319 reserved, 320-383 for render, and so on). Signed-off-by: Michał Winiarski Acked-by: Simon Ser --- drivers/gpu/drm/drm_drv.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 8214a0b1ab7f..b64b5c45cd80 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -113,7 +113,7 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; unsigned long flags; - int r; + int r, start, end; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); if (!minor) @@ -122,15 +122,19 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) minor->type = type; minor->dev = dev; - idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - r = idr_alloc(&drm_minors_idr, - NULL, - 64 * type, - 64 * (type + 1), - GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); - idr_preload_end(); + start = 64 * type; + end = 64 * (type + 1); + + do { + idr_preload(GFP_KERNEL); + spin_lock_irqsave(&drm_minor_lock, flags); + r = idr_alloc(&drm_minors_idr, NULL, start, end, GFP_NOWAIT); + spin_unlock_irqrestore(&drm_minor_lock, flags); + idr_preload_end(); + + start += 192; + end += 192; + } while ((r == -ENOSPC) && end <= (1 << MINORBITS)); if (r < 0) return r; From patchwork Tue Aug 23 21:06:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Winiarski?= X-Patchwork-Id: 12952615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D2163C32772 for ; Tue, 23 Aug 2022 21:07:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4483210FA0B; Tue, 23 Aug 2022 21:07:00 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0DD9410F9E0 for ; Tue, 23 Aug 2022 21:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661288802; x=1692824802; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=KujRH62m/y9LLjIm7A/+vANhJ+0dH40vHXOXMFuACs4=; b=TtH8aTSCxkh0Xpfk70hFW6WJl/ENatO3n4fPGEAOF2b2w3rY7X2eKM4R vjxq7OgKAXeEtjoCVKsLC3IRj0ERxPSlIVdZ7e2fRoWorg6/Ke0A6Gq5x Z/QVMU3SPJpGmmNSWm35ZEHopA082JS8KuIia/T6aXUCjJGp6x5dK8Ln4 ERtga+m54hEFtka9u9aTvdQwLTa312E37Dy/Ja18kr30zznjw+9vvbtjd 1IyGxyfP07/VRj6HQW5dBeE7D5jxE8cLfdQr/c80Us1+Ffiodk6ln27ds Qm21QQC8ddFt7SwfiKDOr8/YCYHNZO0vBnh52HA+BDY+FAi7v4cn6TY1T Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10448"; a="293795846" X-IronPort-AV: E=Sophos;i="5.93,258,1654585200"; d="scan'208";a="293795846" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 14:06:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,258,1654585200"; d="scan'208";a="785385316" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga005.jf.intel.com with ESMTP; 23 Aug 2022 14:06:40 -0700 Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:40 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:40 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 23 Aug 2022 14:06:40 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Tue, 23 Aug 2022 14:06:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ecI0bbsZlUlnb610N0x8j2ku1v7tXsyjuI66wi65vYVO+AFUX9a/w/NMHoDpjUr7FYxh/n8E5Vqw9zGjd+GpCCGOiFYWTeJRiwKRqDnKBQ82exO3ww4s2ZAAtJDi7eysRa+AKRGW6bvcXaX5q5PCRikuYv3RYym6XEvyHWhxyxWSKtu7glFDZaZ5dHnX+e/X3jpi1Jg4UqXJzsUEoEVHx9Y0imhOY/ResilIkdoyyoOGSrRnccu9L7OUcAqxXJNsv9hGiIlueaeQMNeym7C1IQF0J9NtJA0e0aYGK0lI1DjGAAviUSBtBN2q0GkIailx1c139PvcXL9vNouvT5POkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HHA4YXLTcRGi3zUCW+loQ82S4zIbXMM0MC4Hb1DVpDQ=; b=H9Lf31xlzGL72D6CcJlVk1vrb2f5tqIvVFzZmvONcRZDrfju/WKMvawauHSEosS8NereXbwKAddF4ny2/BFtPnMjXTf/bNUWO/X07/ec5sXsGyasBcyeGbf7M3NcAoQ90Dkrwy9cE7pXY0uhs0OERy0RQeiTA2gBOFAteARUIKCgUvAaq79w2dxChJtSGwhltr7N8rqVmb8FInq2ono1/3SXk8scXDa4/h3SX5SDuSXRkq6WyJTyCbmOX3UOSrV82aqCXjtZgIAF1WwT0vuGlTfaN/k6AWGx8ON8iPtgEs0hPWQXuE053l4SgrUQZsmURkeJ8J9h+wdbDQQVAawt5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) by SA2PR11MB5130.namprd11.prod.outlook.com (2603:10b6:806:11d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Tue, 23 Aug 2022 21:06:38 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::b04c:807c:4ea0:c62e]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::b04c:807c:4ea0:c62e%9]) with mapi id 15.20.5566.014; Tue, 23 Aug 2022 21:06:37 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: Subject: [PATCH v2 2/2] drm: Use mutex for minors Date: Tue, 23 Aug 2022 23:06:12 +0200 Message-ID: <20220823210612.296922-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220823210612.296922-1-michal.winiarski@intel.com> References: <20220823210612.296922-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR0P281CA0130.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:97::17) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4faab57-ee35-4600-7ec9-08da854b5e40 X-MS-TrafficTypeDiagnostic: SA2PR11MB5130:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FnUEiFP3tjSLTxtan/8I8PoWCEZ3m1z4/EazfhmDVxpw0cvlgPDJzNlSoCfZ4uuQzNzPkPn8kc+RuwOYgaKxDZCoyXlBeKmcfiTkZ6a6qxNcmXlv5ZFhyaRiLfO05Z5HoTsrhZhT8fTxQhmnCkKupMYwaltXGj91P9hvhY065dJzoOrueiT+wIX0AlgqM/qCp83qG4mhFTyH8ODCf1DR41lQT3/YkESSnfqPY3uauqPtkplnHCKycGWv3c8GX/gtRmyFIDwzOXENnNIVb8sLCdZjdfiEJHPucRGLIyywgiMKoT/BuNDLMc48w80o65uUMbK+m+D51YozQqXS5jSLdnG00TrbD8YQWr45k1Dssusxzm2ZJHhViAfG0XZUXKsxe/u1SlwNdKhu8bsq/Q6C8AnnWdDFtzH1uKYWHh5wqlCwMb5MgLaqFD8wjDI+BTRSIVqiS9RHAq6E8ZKy4HAgY/1+U8uTUlGvj0XtKCScHSP0DWYAuzLiG9EccIoDCkLi0OAtnjssqU5yE7RoZJEQG5eTlD+UTiGix0e5LC2quI9j6rDg2hG3gnnE6OtaHC6sdo51COWrlEL3UAwd0QtHRjpdqBAZIeVG877AMyZNRkZUYHoVBXqTwxtkYOPj9BhgrbpwQMVX6vUaRWfr9KEChNdYc5+IJeiDu/LnT90QaTi6MaCCvH7IF4xll0UrHYG+M5IZLXk8myhjg7NQLwX+HQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5373.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(39860400002)(136003)(346002)(366004)(396003)(6512007)(6666004)(5660300002)(186003)(1076003)(6506007)(2616005)(8936002)(36756003)(26005)(86362001)(41300700001)(83380400001)(478600001)(6486002)(38100700002)(82960400001)(6916009)(316002)(54906003)(2906002)(4326008)(66476007)(66556008)(66946007)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?p5P9Vnp9db8Wk3DOB0qHhjLNqCmN?= =?utf-8?q?W0TPatyo/ytCgEibWLVf4CO0TXQbo3RJp80sHU05skJr+SbWBU0pUfJJMpF0uIh9p?= =?utf-8?q?6YPjVr3dQe97QDTprXjgfM7j9dlhP9HzzLN0NtN1DkTAdpn47rkl+EJbsZwGsFTpy?= =?utf-8?q?XpGtCl9orJUo1Rg9jb26wAp7THu3bWiPnWLdB92rOgeNlPOLo06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d2JGAyybd+?= =?utf-8?q?xkhiLrns6Nel4axUF6PMHQB0wwjBhMdPqT0QSshRPWCenzTVlbbwNDL0zrpdNITIw?= =?utf-8?q?QYzGXmx41qls8KMy9vnEeXpQ3VSjNifFgHUsmncJjzUu2zpQEo6qQSIm8nwmX8IUh?= =?utf-8?q?uhcHM5dGNzs65Z2oT8BI+OIXgI7Qab7LjgIxYrajwMwDYgWEnCwJYwBU9fbnq4AUe?= =?utf-8?q?MGD5+67DNt6Dq63AyFn5p4e05xEdaNskyIKiNYTG5CcoqBzVx0j9ACixyB455DtN1?= =?utf-8?q?e1Hz4M+OZSxkBkUns+murzrG+iGimZthAcVKE2rmIj+OlCgClbOQQDn5Fv4BG/VGB?= =?utf-8?q?f0rZWo50+Kwvdel5EzWgaqd/QtqcA1x3K9s/NbypGDHgvMRMIIcU2S/jYIn74tVVz?= =?utf-8?q?toO+FXjFm122fkwcHA2j1HT3HOjdiAskOpY8EGaO04HCSWsqysR0lmZC6HnYJxCJE?= =?utf-8?q?IxxE3s5ttAxfBphVlQCzhbEWC9Z/mNyPLA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: d4faab57-ee35-4600-7ec9-08da854b5e40 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2022 21:06:37.8703 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BGnadXsI9Df3rmWHLHzAaxSGVfbtstmnzNuWkEoSDiT/MkTjjLaTeayX7Gk+NaHQHuz9qaiO+sUTQbGmmZSL38S+poLc/dt7E2x/jAS1Nj0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR11MB5130 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , David Airlie , Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Operating on drm minor is not done in IRQ context, which means that we could safely downgrade to regular non-irq spinlock. But we can also go further and drop the idr_preload tricks by just using a mutex. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/drm_drv.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index b64b5c45cd80..8706d846abb7 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -53,7 +53,7 @@ MODULE_AUTHOR("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl"); MODULE_DESCRIPTION("DRM shared core routines"); MODULE_LICENSE("GPL and additional rights"); -static DEFINE_SPINLOCK(drm_minor_lock); +static DEFINE_MUTEX(drm_minor_lock); static struct idr drm_minors_idr; /* @@ -98,21 +98,19 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, static void drm_minor_alloc_release(struct drm_device *dev, void *data) { struct drm_minor *minor = data; - unsigned long flags; WARN_ON(dev != minor->dev); put_device(minor->kdev); - spin_lock_irqsave(&drm_minor_lock, flags); + mutex_lock(&drm_minor_lock); idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + mutex_unlock(&drm_minor_lock); } static int drm_minor_alloc(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; - unsigned long flags; int r, start, end; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); @@ -126,11 +124,9 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) end = 64 * (type + 1); do { - idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - r = idr_alloc(&drm_minors_idr, NULL, start, end, GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); - idr_preload_end(); + mutex_lock(&drm_minor_lock); + r = idr_alloc(&drm_minors_idr, NULL, start, end, GFP_KERNEL); + mutex_unlock(&drm_minor_lock); start += 192; end += 192; @@ -156,7 +152,6 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) static int drm_minor_register(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; - unsigned long flags; int ret; DRM_DEBUG("\n"); @@ -176,9 +171,9 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) goto err_debugfs; /* replace NULL with @minor so lookups will succeed from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); + mutex_lock(&drm_minor_lock); idr_replace(&drm_minors_idr, minor, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + mutex_unlock(&drm_minor_lock); DRM_DEBUG("new minor registered %d\n", minor->index); return 0; @@ -191,16 +186,15 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) static void drm_minor_unregister(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; - unsigned long flags; minor = *drm_minor_get_slot(dev, type); if (!minor || !device_is_registered(minor->kdev)) return; /* replace @minor with NULL so lookups will fail from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); + mutex_lock(&drm_minor_lock); idr_replace(&drm_minors_idr, NULL, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + mutex_unlock(&drm_minor_lock); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -219,13 +213,12 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) struct drm_minor *drm_minor_acquire(unsigned int minor_id) { struct drm_minor *minor; - unsigned long flags; - spin_lock_irqsave(&drm_minor_lock, flags); + mutex_lock(&drm_minor_lock); minor = idr_find(&drm_minors_idr, minor_id); if (minor) drm_dev_get(minor->dev); - spin_unlock_irqrestore(&drm_minor_lock, flags); + mutex_unlock(&drm_minor_lock); if (!minor) { return ERR_PTR(-ENODEV);