From patchwork Mon Jul 24 21:14:25 2023 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: 13325330 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 32997C001B0 for ; Mon, 24 Jul 2023 21:15:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA64A10E35B; Mon, 24 Jul 2023 21:15:22 +0000 (UTC) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F1B810E35B; Mon, 24 Jul 2023 21:15:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690233321; x=1721769321; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=rhtNiYYVteziVFqrrQ6PoJGiyXUfob6EsfrQkEYBa3E=; b=T8DJ9B/fxGw3I3Xo79SGcJCcd4FKqv+N5Ef4hlncm56r+2VXX5PUkW1e RjOTwO+v7xuoCw5waHQINBdQNQokOqShnC2aHp0bmss2eId1TrCWCYu33 SGvC4QBmjbSRFfJsOFp+ZOJqwzDqmu3IUqg55afSKBQSZ3Utdi62+jt1T vr6MQaRs7EQ7Ni2FlJ1gQYriXlKNEw7BInBlaMjYRMHEdqoj0TW9MKEQi Gyl3ZJx+EhveCv6Q5Ywx6BPLjvSIb+3+GtwrOdmMrIS6klQ3qPiR0qvAE P51zFnzDLdEtSSlJYPqIv1MehseyTDtz8VChrlb1c+P0qU339QkHsqGJ8 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="453931075" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="453931075" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 14:15:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="1056569339" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="1056569339" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga005.fm.intel.com with ESMTP; 24 Jul 2023 14:15:19 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) 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.2507.27; Mon, 24 Jul 2023 14:15:19 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Mon, 24 Jul 2023 14:15:19 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.108) 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.2507.27; Mon, 24 Jul 2023 14:15:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dBUlf3hSNxW3ay3fAuKJMln/8y3mrAYst5TdgkurJCpom7Su0xBCcCC7KZCAw/SDjr+IpqW0NBV9AbBH98wcBtb2qo/ry2oT8/Djty+hY0hSGsy6GRBsqKT5U8CVBZb5g1Co6K+zXOz4ZxEFKpMFWNbScYL0O5XOaOhJiYUpPF5cD/J7KNL/JUkY6/LxlGvu4X0XjmFRy0BT2pv3NLtOWadYXMiONT4/d+XgDhLkQ41cMqXY4Tqso+XLsQ28mBv28/1e3jaCmukh8fff4yp3lQ2PxfLNg24WV+96tFbkGbST9XyOvCeBY/TCXQlu2ubz2SZ+DZRbNZvdhT2Vf3VwPA== 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=SAQjAU/oQDuqdibu8w6peKc1dtCBsSy6GPLMGiJD/a0=; b=QKGSoKo6Zb5+5BVuJU6Ch4wUcwf4e6T+jYDnpM2boWfbei2IXRR6JZpXyWblIKtofPzxombIncuQ/bFP4CpaPxDeGEm5r5kFvZ6S62p4/RgsczuBGIm7UpR7tcAL3SvaWoVc+vXuZB/LPOBk7+aiDYld0fnvSKUi/XX/4SX1KYERGofMqiZU07A3Q4hYgX3UcvgdQTTmjLhvGOt05AUhOosgySQtfmzO+CxtsvVyJc7112VY0/PLWLhtswscOzjkrBCWln0XJvUCWCjQSGvfnGSWodRQ99larSrjoe825MVQunE7+XMLgTGJ/ZKEZ6xlbNJSOErQywgy70bIIgZFVg== 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 MW5PR11MB5809.namprd11.prod.outlook.com (2603:10b6:303:197::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 21:15:16 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1%5]) with mapi id 15.20.6609.031; Mon, 24 Jul 2023 21:15:16 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v6 1/4] drm: Use XArray instead of IDR for minors Date: Mon, 24 Jul 2023 23:14:25 +0200 Message-ID: <20230724211428.3831636-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724211428.3831636-1-michal.winiarski@intel.com> References: <20230724211428.3831636-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR0P281CA0147.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:96::11) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW5PR11MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: ef3ff2a9-ff21-4954-cbdc-08db8c8b13b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ulmgBOlYXeBgg4WDtpKRrg69uU5vqhsZXE4SvzpBdnnamJPxtgdCwTzC/nd8v6a5fCC1ABCrYPBZcWkQs/g99tTNYWoxhfItvRNz1Up4Lq9t1d1JdhIrpjUQ4f//enjacbZmEKcWikuKSEaeMwtu77kPyhdZ9FqNGrimHiea/LGblJdxFQmD6V0gmLlT9WGnjh2Tp8i+Myrg8h0m++jqzOZu7N/QAuMFzD31gKko/aYThC8vLpWwgOj/XEd28Nnnr74UrBqvA+i+Ji8Hh3Y1Z5yoYoCBJDg4ykHyqwGKVSKMg1sCWAWdvlO5OPuUPlE3MhYXji/trL1gpcYrYdfV/NnI2GES/WYomDy/E9reHlF2InzyzN3DOUmwESUbo5HZopAa32H0gYi4oFEGAyLQsr3Q5PjaNEsmb/h23LnYBJAa5GJ73eSFH496kcvCDovFwMnf+wACntyqFs5roCNPuU8VQ3HsWRn+/x5Kf/uBQ6FKNS6G9BD19fh+KbOgkjreZLatf9E4l/Otl/efWY46fu4pMWbh/6HSuNP4DPd1vUO7H8AUGu87flmB5j3hPiP4 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:(13230028)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(83380400001)(38100700002)(36756003)(82960400001)(86362001)(54906003)(2906002)(186003)(6506007)(1076003)(26005)(6666004)(6512007)(6486002)(8936002)(5660300002)(8676002)(7416002)(478600001)(316002)(41300700001)(66476007)(66946007)(66556008)(4326008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qSJKUetv0SWghLaPVzHAwwMouwo2?= =?utf-8?q?Ds/0Hfj+YTrES8JOfETcA7IEKBCmFqdbrqHtObtKPYael1KE+Wh8OcsmgrhekbsZS?= =?utf-8?q?TZIjWuT74wGuaS3Vb/17c/dT1NDIY84Ux290iSEMafAdW/j6fz5DLZCaOcPTWU17g?= =?utf-8?q?/2Zon0ZXfDJlTvaJxW0QjrFB52O6MW2FnIyOHeGCyyfsoz722zoNqB3yX9+WTtgSJ?= =?utf-8?q?CLmMIjh0JinGMp8TUNPa8IwG/G1WijeuvuYukbvmfybNckDA0MnFQ18DPawyc4g2Z?= =?utf-8?q?BskhShtYeScWPLRBNKP3ZY9q0knPVMiXaLKXesGd7I5nWNb5JjZxZOHQL3pKyMnvF?= =?utf-8?q?N3J5bullt7PCvQE2Sh+vDCZfJxrQ7xtPYnVZAi60frTcgMXjmdc2L/V4V0wSffkzE?= =?utf-8?q?12DPKHquTr4H0LqBf1OsMkKDPR+em0Ia5L21X2RgHqa6VcEfNPZQWZxEmfS6dVyUD?= =?utf-8?q?onD959WUj/JdO0kBtNZWYS9IipSwJcFHIpiBA7INUVgZppIXrBccvs+YU4c7l/zNA?= =?utf-8?q?PtJ98RFpwf0bz1ayz3JxywxdxeY1vYKL5wAX+ERx7MjK8Q4BxL2O2m0DVQ+aPrYKO?= =?utf-8?q?sN8p76bpjj0LcOecefujLmyYH7gG6O8C8ut3QaPIBEko69bsmPD0UuXQil5ek3GS9?= =?utf-8?q?dMSZZaZrwNkJwG9YQEuAPo5ePvn0UWuISW6zcoS1ZuATyi2pituwCag+ogeMQF5Rv?= =?utf-8?q?mTOMGMrVlU5CVbi7StaLqL0fUwpZqfFQH8dkPTcwDqnUPqp13bg92s8MyXCqqsotB?= =?utf-8?q?tlHd0YgBvBYJlRTZ8Xk3Jg9felKrq143hh0EqvWnewD53lMlLU5Gw9nmrPZxYDiWH?= =?utf-8?q?bZ40RstKpb6Rc47t15RuX+PwCmq/qHeWyydssy7HDv6OrGhLCHT3qNpwjaiQnko/y?= =?utf-8?q?ELLZ2JFSwLZz/FfvBbP19zszOyStMqEs26JXnfJ62rMtbSgRAUdk1nNipRTU2K4ad?= =?utf-8?q?N3ojsWnMGWjgpG1smwozQm+lkEXeCal4AJvJLKU4GwUSEE+STOt4xvzbiDjn+oG7+?= =?utf-8?q?42T/n7CvzfI+aw/gMJxwIfWmsHr6rarWN5aDAejrFEuI4HGwC7uJrq6G63AcQBgKH?= =?utf-8?q?itsOyLtX4FiyaPzQNzr/AUjyKl4d+WW/H9EcFFYtNwcs4V+RMJOuXOMF27qLI/9GP?= =?utf-8?q?+hybdCbm1kL07mjdXyW4bYJErI7qM4ZycN1SzLARln2FKoGRcnCOEF8eg2liYXWn/?= =?utf-8?q?YE5WfigVR2g7RZXtxkzQctLhbt+oNj2T8Coyb1/f3vAxNnQWAnqKocsgTE26/fJ+Y?= =?utf-8?q?JT3MlkM/dpMHlrXGvGhaxv+6yjlRDOmt2BNEU6hRIqShU1NBP5UViuww2D4ij7b0f?= =?utf-8?q?cmfw1ypOTnGuq/eqmhbm40P9NJkklgWQyHK+Y/VVrkRs/xze+YdhpJmYG1swB0fjg?= =?utf-8?q?ihnWuAg+jkRFpIbDII8oiWNxKQbujFkfJ//ADTXHEiI1REuNp6K6h0bx0vXS2zHT3?= =?utf-8?q?+zWr+vZ0awOqCkeBePO2n4dPRA2ybANE5RI/8hZBHoO0xp3m9d4Nrp0n31DnWVW5u?= =?utf-8?q?BddGxJqqVu/4kPMJ21V1BhCg8hoHfD4tDA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: ef3ff2a9-ff21-4954-cbdc-08db8c8b13b7 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 21:15:16.3583 (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: KgjCtM807tkgDF2zkSAgfGuONWUFBOmXosXi3Zb2gtPPDhFCO6hvUwIW5SxnIxHwPG2HCLryySPIxt+ntjT0pi3yPWgeasljxW89pEWGP2w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5809 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: Pekka Paalanen , David Airlie , Oded Gabbay , Maxime Ripard , Emil Velikov , Matthew Wilcox , Thomas Zimmermann , =?utf-8?q?Micha=C5=82_Winiarski?= , James Zhu , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" IDR is deprecated, and since XArray manages its own state with internal locking, it simplifies the locking on DRM side. Additionally, don't use the IRQ-safe variant, since operating on drm minor is not done in IRQ context. Signed-off-by: Michał Winiarski Suggested-by: Matthew Wilcox --- drivers/gpu/drm/drm_drv.c | 63 ++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 3eda026ffac6..3faecb01186f 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -54,8 +55,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 struct idr drm_minors_idr; +static DEFINE_XARRAY_ALLOC(drm_minors_xa); /* * If the drm core fails to init for whatever reason, @@ -101,26 +101,23 @@ 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); - if (minor->type == DRM_MINOR_ACCEL) { + if (minor->type == DRM_MINOR_ACCEL) accel_minor_remove(minor->index); - } else { - spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); - } + else + xa_erase(&drm_minors_xa, minor->index); } +#define DRM_MINOR_LIMIT(t) ({ typeof(t) _t = (t); XA_LIMIT(64 * _t, 64 * _t + 63); }) + static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) { struct drm_minor *minor; - unsigned long flags; - int r; + int index, r; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); if (!minor) @@ -129,24 +126,17 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) minor->type = type; minor->dev = dev; - idr_preload(GFP_KERNEL); if (type == DRM_MINOR_ACCEL) { r = accel_minor_alloc(); + index = r; } else { - 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); + r = xa_alloc(&drm_minors_xa, &index, NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); } - idr_preload_end(); if (r < 0) return r; - minor->index = r; + minor->index = index; r = drmm_add_action_or_reset(dev, drm_minor_alloc_release, minor); if (r) @@ -163,7 +153,7 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) { struct drm_minor *minor; - unsigned long flags; + void *entry; int ret; DRM_DEBUG("\n"); @@ -190,9 +180,12 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) if (minor->type == DRM_MINOR_ACCEL) { accel_minor_replace(minor, minor->index); } else { - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, minor, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + entry = xa_store(&drm_minors_xa, minor->index, minor, GFP_KERNEL); + if (xa_is_err(entry)) { + ret = xa_err(entry); + goto err_debugfs; + } + WARN_ON(entry); } DRM_DEBUG("new minor registered %d\n", minor->index); @@ -206,20 +199,16 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type 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 */ - if (minor->type == DRM_MINOR_ACCEL) { + if (minor->type == DRM_MINOR_ACCEL) accel_minor_replace(NULL, minor->index); - } else { - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, NULL, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); - } + else + xa_store(&drm_minors_xa, minor->index, NULL, GFP_KERNEL); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -238,13 +227,12 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ struct drm_minor *drm_minor_acquire(unsigned int minor_id) { struct drm_minor *minor; - unsigned long flags; - spin_lock_irqsave(&drm_minor_lock, flags); - minor = idr_find(&drm_minors_idr, minor_id); + xa_lock(&drm_minors_xa); + minor = xa_load(&drm_minors_xa, minor_id); if (minor) drm_dev_get(minor->dev); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_unlock(&drm_minors_xa); if (!minor) { return ERR_PTR(-ENODEV); @@ -1067,7 +1055,7 @@ static void drm_core_exit(void) unregister_chrdev(DRM_MAJOR, "drm"); debugfs_remove(drm_debugfs_root); drm_sysfs_destroy(); - idr_destroy(&drm_minors_idr); + WARN_ON(!xa_empty(&drm_minors_xa)); drm_connector_ida_destroy(); } @@ -1076,7 +1064,6 @@ static int __init drm_core_init(void) int ret; drm_connector_ida_init(); - idr_init(&drm_minors_idr); drm_memcpy_init_early(); ret = drm_sysfs_init(); From patchwork Mon Jul 24 21:14:26 2023 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: 13325331 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 05C01C001DE for ; Mon, 24 Jul 2023 21:15:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC75210E35F; Mon, 24 Jul 2023 21:15:28 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id E342110E35D; Mon, 24 Jul 2023 21:15:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690233325; x=1721769325; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=xxxbPCzILB+ORtjnLQS237W707qJrozmzmmQety2tGA=; b=V1u8+GLbEo5IetJRxYiyT2042MT+2frtHQ7zwSe7OM6bwUFpXs6T2tBP BMmHPPZicnIED45v0lmRTTBNjAG7TZkceHoNnCLv+gFgsn2ZE0zz8i6eF Vd+QvTw3Jd7XeFDgR+KKPjWOzXU8KI3b0QlLHlizNfsUTANmKIrc13Eyv hp3F+V7tWLP+t0A5CyMiyCWR8D49GaqCHdpP8L6pZGsQN+TjfVrXF85M7 h+MajIrJFr5iDvdpidDamIhvMvymSk1Hv9oFoImYAhwaeyxl41rNajvLf a6G8U50rwLBNE/ZTulIHft7CaQxGO+MKLvnZh/M5xY2Hy7z30fmi4qX8X g==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="347830085" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="347830085" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 14:15:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="719815887" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="719815887" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga007.jf.intel.com with ESMTP; 24 Jul 2023 14:15:24 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 14:15:24 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 14:15:24 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Mon, 24 Jul 2023 14:15:23 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.108) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Mon, 24 Jul 2023 14:15:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FklTcyXx9LsfuaaPQ7vfSxDnpr2oc8PZvoYZgSkQGq+tfv0w8lQBxMy6J9DLVbWhmRRmak9o2Eysj3bU8v5I7F1iNoKI22A728XEheRnIig4t+Az70vp8cS5KSCn496l8WOg01ZmuNgbDShbJ7J4ItKYiUeBbNiTlN/gXrBwQCqzKCgnNuwC/PFN7ZA6vVL2ZIfgFY91qv6zj35rWTgnJVqKO9dMVpNNNBghch/ufl5swNpDjg45LGRP56Ej1rELLdPmwmiG7sbJnCWQ5SBBVXaH/kpYuR/78wwzMlvzHdQ8HSghQj8Qu5zA967nDxglb+8mg5ALYn6iZqTM5p6kDw== 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=+EA3oS/E2UCW5sP165cfWbyMjvpO7ndnK3w1c7wQzx4=; b=kcSw+Ub1h3Xc5edXbHAjgFw24vsnrZkEqHlEQW3VHWPedQ8azJ6/aKqsDbE58wEFo0mHHiUPwB7k66oJlZjXKPCnxmYgDDLw3ogpaBPmfiq9ZuttJld4t00Ctg8ing0URxd3atUG5S1z5VbtnRtpd4XUz6GnSbyc+QAVJwHvnbwQVuYazJ4Msy6H7HyICboGpFbvKDFMH7iiSHDVWxszTPd4kAaYd5g14TB18vd7h7YJ16lw3TVC382pJPnta1fsG6iITJj6MEiWePaZ5YdLJ9A9iX4kHqjv9uTlWgu6GT0m2G4WC9ltxA9HCYMMvRMyQx+A+EviVSSvAvRLijsEqw== 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 MW5PR11MB5809.namprd11.prod.outlook.com (2603:10b6:303:197::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 21:15:20 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1%5]) with mapi id 15.20.6609.031; Mon, 24 Jul 2023 21:15:20 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v6 2/4] accel: Use XArray instead of IDR for minors Date: Mon, 24 Jul 2023 23:14:26 +0200 Message-ID: <20230724211428.3831636-3-michal.winiarski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724211428.3831636-1-michal.winiarski@intel.com> References: <20230724211428.3831636-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR2P281CA0059.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:93::13) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW5PR11MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f495a29-fec7-4165-8fd7-08db8c8b1642 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JHSnb+Gf3K2so5Ct2tasrkBwUmDOGKeuI7lGA7vCloJJ30oQNG6kFLK0UmIO+7U7nD6oAgbcuYw2p+60AHd9awkuUqqR8YIntKNpD4DBio7v+lI/3hAnEpbvnfWxxoS3ODW+WXQbzeQlN0m62RrjkqbC0UPbHCkMpclc7LTDotlWhFIMOgpJGqeDu9GiKqd+g+88aVa+wAUS3sWyILklVclH7WVeiedX3R1GTw9kUg1LZ2aQXioq2SACfEUIOwmEHpwi9NqSIrxJY13MyCA1iUXT/NITnRsgcbWl4wUNiDjCzbffniyhUbU+SRIkz+qQlgdUNLhPegylmD0cyqaBNsMviWEmRSQBk4hHaWqlxplcoS/zE0QEVgHNtNMAQI/J81WMgZEO5PK3XG2EkdSjv3gW15ChW9TEHGBpWHn/0lCQPjKJuLjsSsdfjELA7IzSOO85SnvXf4ILd7aXrmvSdGyHHZShkY5QF6L3ZmkGopo833iTg4de66zFAoFQPaH8EPTODV/owlMFL7KR3NXj5JFMRzR2qkJ5YpDXw3jE+GCXK1FHApI09LYDFCkjErQB 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:(13230028)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(83380400001)(38100700002)(36756003)(82960400001)(86362001)(54906003)(30864003)(2906002)(186003)(6506007)(1076003)(26005)(6512007)(6486002)(8936002)(5660300002)(8676002)(7416002)(478600001)(316002)(41300700001)(66476007)(66946007)(66556008)(4326008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SjMmpwzl4jAXzJPhPiIetSsD/cJR?= =?utf-8?q?Gm5s34iFmIX8y1UNod8YC1XOB8jF6x0sH7Aoprz4oBBoMCnJ/EjPiBYCQxuoBm+X8?= =?utf-8?q?d96Bg3roRzLwh1amEfm7tqw+J7LYSZ8OuobfIrIYIe9WnpL8IPKPIRZBV6W14wRxP?= =?utf-8?q?F64pAVsi6uIPawWr5uRcCJ4Lhe/0tPOgKa9mxFitiQU311H6Z4JAASiZtbCiEWdR5?= =?utf-8?q?45cRPHbCZEidHBncWtW93SWS34OkeBRmd19UTDaSaDR8+MAsK/NUR0O9vUsdBWC64?= =?utf-8?q?W5glVUeYN9Ctm7UGdmqQ3lGN/GziWPfStWgeQH2gm2cOG+7youJVglcFzLKnTL7v+?= =?utf-8?q?+72bNgd+yfGAPVB1sZOE3iFCzsq8oN87L8ZM/Le2OtF6N7d+1iqqv8msirYkII/Xs?= =?utf-8?q?mb4bhA+rZADtrnWWMzU1rYXOO22dNGWjlBTArWkcuX5M3wfsXi/Ltf99C2AIffwgT?= =?utf-8?q?78opHjEhjnVGz4Jr0A+8nRkKqXRXJtJ4z0a1Bwo2Jj0VnC+OgcLoC7Eszaa+5YYts?= =?utf-8?q?AT3pJTRE+hZD7Inb1hQxiALAh/YuGSY/9r6frQ0f6oGIXJyAp+Ywylc1BfXj7LugA?= =?utf-8?q?VuNaDKROvricHKKVikdev7kYnwI3t3dw2+lyrrbgxgOoFWuyzV8TUbmyj49e9bbPn?= =?utf-8?q?YdVXw8tG1aQVHPyKZ04ISdpHavtcbo38R9c9r+QRgbbSEtR5lJCaq2xowCRNQytfl?= =?utf-8?q?sFYVJnsrbWCV8RW+z/f93e8rdaZep7c7G7/UbolB+2oZmM75Rh7FdHk+bsLNUZUZg?= =?utf-8?q?rNEfWGHpDTBn+yHkUyoQfUQ8QCKcvjkelP6M87lUQhVrhaTST8x65Y5LSuhati3Q7?= =?utf-8?q?kqrTHM5V4QCbw4kPc/qzl7nZBkH2I3dU0WtRKZuFF1D0n212tg6Zl3SfKMl2RxHPk?= =?utf-8?q?xs8TQUxyUPdo87TGzveRA/hHkqL75UlZ3upRWmkNtkjcBzLn+uiElsbqrdn0wUrO+?= =?utf-8?q?2Pw4CI1KQl7TF2SpKlFV3WGA4XX0+vXFb5HiGzw3bQ6jV3lGEqwvQCPnlPeX745II?= =?utf-8?q?hGQk4sFxgOwIb6tUFlGgb+nxcp9xk1fiwKWUxTYmLEwL0dLKXiz99WT8qBBVYtJYd?= =?utf-8?q?xmIJXEVKmavcRl1WpLlEZtM8aKxgKzobaNpyByr+vKgMVrRmUh6ZnmruKTdLGfTMU?= =?utf-8?q?IVQ1FJLkpHEoBAAEEtclXYvOt/T/3gNLI3BTxJ75pMt4PsnUkhSyFh7aqv5z/oVjd?= =?utf-8?q?acX1HgVslvYEI4M6dO8ikGhiAGnCKla0+DsRRHCs5sfQ67Gwxas5HbWTCmbSSOO4W?= =?utf-8?q?lco1vTMcaJv7EejdXyfWUb+Tmrn8DEgJSvlzOE0yBAhZKC7VYDtOUrM1ZCMQLHLUO?= =?utf-8?q?BCGfdSM/gV8nWMurCAdBIrYy6bTkO/D9/opg/tt9r5BKRMgWG4z8jbXHnAd9MvMVu?= =?utf-8?q?k5+He2YejdELgUdXZrN2N7frOcvFkbjct8lARI/COqNsVRzPxK24EFbcfS1Yj9/in?= =?utf-8?q?2fZsLWEtf7wR8WWSUxMeD8jrwvhdVDRDV4RNOTZQSzUHRhmTn15k9ETGwBk3zs3uq?= =?utf-8?q?3RNRv6+cqY+M/7x8l71Y+GSinipa4NNYew=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 9f495a29-fec7-4165-8fd7-08db8c8b1642 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 21:15:20.7168 (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: 7MrdX5LpfXpd9nKQtAfBUegXyfO18W3Pf/WUyKVmR9DUol+giVARQwjutK059Q9kflDT0uhymK6iydkOsoNL7ItQU2DIRL1ygsoGatS+dUo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5809 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: Pekka Paalanen , David Airlie , Oded Gabbay , Maxime Ripard , Emil Velikov , Matthew Wilcox , Thomas Zimmermann , =?utf-8?q?Micha=C5=82_Winiarski?= , James Zhu , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Accel minor management is based on DRM (and is also using struct drm_minor internally), since DRM is using XArray for minors, it makes sense to also convert accel. As the two implementations are identical (only difference being the underlying xarray), move the accel_minor_* functionality to DRM. Signed-off-by: Michał Winiarski --- drivers/accel/drm_accel.c | 110 +++------------------------------ drivers/gpu/drm/drm_drv.c | 66 ++++++++++---------- drivers/gpu/drm/drm_file.c | 2 +- drivers/gpu/drm/drm_internal.h | 4 -- include/drm/drm_accel.h | 18 +----- include/drm/drm_file.h | 5 ++ 6 files changed, 47 insertions(+), 158 deletions(-) diff --git a/drivers/accel/drm_accel.c b/drivers/accel/drm_accel.c index 4a9baf02439e..8827cb78ca9d 100644 --- a/drivers/accel/drm_accel.c +++ b/drivers/accel/drm_accel.c @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -17,8 +17,7 @@ #include #include -static DEFINE_SPINLOCK(accel_minor_lock); -static struct idr accel_minors_idr; +DEFINE_XARRAY_ALLOC(accel_minors_xa); static struct dentry *accel_debugfs_root; static struct class *accel_class; @@ -120,99 +119,6 @@ void accel_set_device_instance_params(struct device *kdev, int index) kdev->type = &accel_sysfs_device_minor; } -/** - * accel_minor_alloc() - Allocates a new accel minor - * - * This function access the accel minors idr and allocates from it - * a new id to represent a new accel minor - * - * Return: A new id on success or error code in case idr_alloc failed - */ -int accel_minor_alloc(void) -{ - unsigned long flags; - int r; - - spin_lock_irqsave(&accel_minor_lock, flags); - r = idr_alloc(&accel_minors_idr, NULL, 0, ACCEL_MAX_MINORS, GFP_NOWAIT); - spin_unlock_irqrestore(&accel_minor_lock, flags); - - return r; -} - -/** - * accel_minor_remove() - Remove an accel minor - * @index: The minor id to remove. - * - * This function access the accel minors idr and removes from - * it the member with the id that is passed to this function. - */ -void accel_minor_remove(int index) -{ - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - idr_remove(&accel_minors_idr, index); - spin_unlock_irqrestore(&accel_minor_lock, flags); -} - -/** - * accel_minor_replace() - Replace minor pointer in accel minors idr. - * @minor: Pointer to the new minor. - * @index: The minor id to replace. - * - * This function access the accel minors idr structure and replaces the pointer - * that is associated with an existing id. Because the minor pointer can be - * NULL, we need to explicitly pass the index. - * - * Return: 0 for success, negative value for error - */ -void accel_minor_replace(struct drm_minor *minor, int index) -{ - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - idr_replace(&accel_minors_idr, minor, index); - spin_unlock_irqrestore(&accel_minor_lock, flags); -} - -/* - * Looks up the given minor-ID and returns the respective DRM-minor object. The - * refence-count of the underlying device is increased so you must release this - * object with accel_minor_release(). - * - * The object can be only a drm_minor that represents an accel device. - * - * As long as you hold this minor, it is guaranteed that the object and the - * minor->dev pointer will stay valid! However, the device may get unplugged and - * unregistered while you hold the minor. - */ -static struct drm_minor *accel_minor_acquire(unsigned int minor_id) -{ - struct drm_minor *minor; - unsigned long flags; - - spin_lock_irqsave(&accel_minor_lock, flags); - minor = idr_find(&accel_minors_idr, minor_id); - if (minor) - drm_dev_get(minor->dev); - spin_unlock_irqrestore(&accel_minor_lock, flags); - - if (!minor) { - return ERR_PTR(-ENODEV); - } else if (drm_dev_is_unplugged(minor->dev)) { - drm_dev_put(minor->dev); - return ERR_PTR(-ENODEV); - } - - return minor; -} - -static void accel_minor_release(struct drm_minor *minor) -{ - drm_dev_put(minor->dev); -} - /** * accel_open - open method for ACCEL file * @inode: device inode @@ -230,7 +136,7 @@ int accel_open(struct inode *inode, struct file *filp) struct drm_minor *minor; int retcode; - minor = accel_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&accel_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); @@ -249,7 +155,7 @@ int accel_open(struct inode *inode, struct file *filp) err_undo: atomic_dec(&dev->open_count); - accel_minor_release(minor); + drm_minor_release(minor); return retcode; } EXPORT_SYMBOL_GPL(accel_open); @@ -260,7 +166,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp) struct drm_minor *minor; int err; - minor = accel_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&accel_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); @@ -277,7 +183,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp) err = 0; out: - accel_minor_release(minor); + drm_minor_release(minor); return err; } @@ -293,15 +199,13 @@ void accel_core_exit(void) unregister_chrdev(ACCEL_MAJOR, "accel"); debugfs_remove(accel_debugfs_root); accel_sysfs_destroy(); - idr_destroy(&accel_minors_idr); + WARN_ON(!xa_empty(&accel_minors_xa)); } int __init accel_core_init(void) { int ret; - idr_init(&accel_minors_idr); - ret = accel_sysfs_init(); if (ret < 0) { DRM_ERROR("Cannot create ACCEL class: %d\n", ret); diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 3faecb01186f..34b60196c443 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -55,7 +55,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_XARRAY_ALLOC(drm_minors_xa); +DEFINE_XARRAY_ALLOC(drm_minors_xa); /* * If the drm core fails to init for whatever reason, @@ -83,6 +83,18 @@ DEFINE_STATIC_SRCU(drm_unplug_srcu); * registered and unregistered dynamically according to device-state. */ +static struct xarray *drm_minor_get_xa(enum drm_minor_type type) +{ + if (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER) + return &drm_minors_xa; +#if IS_ENABLED(CONFIG_DRM_ACCEL) + else if (type == DRM_MINOR_ACCEL) + return &accel_minors_xa; +#endif + else + return ERR_PTR(-EOPNOTSUPP); +} + static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, enum drm_minor_type type) { @@ -106,18 +118,18 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) put_device(minor->kdev); - if (minor->type == DRM_MINOR_ACCEL) - accel_minor_remove(minor->index); - else - xa_erase(&drm_minors_xa, minor->index); + xa_erase(drm_minor_get_xa(minor->type), minor->index); } -#define DRM_MINOR_LIMIT(t) ({ typeof(t) _t = (t); XA_LIMIT(64 * _t, 64 * _t + 63); }) +#define DRM_MINOR_LIMIT(t) ({ \ + typeof(t) _t = (t); \ + _t == DRM_MINOR_ACCEL ? XA_LIMIT(0, ACCEL_MAX_MINORS) : XA_LIMIT(64 * _t, 64 * _t + 63); \ +}) static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) { struct drm_minor *minor; - int index, r; + int r; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); if (!minor) @@ -126,18 +138,11 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) minor->type = type; minor->dev = dev; - if (type == DRM_MINOR_ACCEL) { - r = accel_minor_alloc(); - index = r; - } else { - r = xa_alloc(&drm_minors_xa, &index, NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); - } - + r = xa_alloc(drm_minor_get_xa(type), &minor->index, + NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); if (r < 0) return r; - minor->index = index; - r = drmm_add_action_or_reset(dev, drm_minor_alloc_release, minor); if (r) return r; @@ -177,16 +182,12 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type) goto err_debugfs; /* replace NULL with @minor so lookups will succeed from now on */ - if (minor->type == DRM_MINOR_ACCEL) { - accel_minor_replace(minor, minor->index); - } else { - entry = xa_store(&drm_minors_xa, minor->index, minor, GFP_KERNEL); - if (xa_is_err(entry)) { - ret = xa_err(entry); - goto err_debugfs; - } - WARN_ON(entry); + entry = xa_store(drm_minor_get_xa(type), minor->index, minor, GFP_KERNEL); + if (xa_is_err(entry)) { + ret = xa_err(entry); + goto err_debugfs; } + WARN_ON(entry); DRM_DEBUG("new minor registered %d\n", minor->index); return 0; @@ -205,10 +206,7 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ return; /* replace @minor with NULL so lookups will fail from now on */ - if (minor->type == DRM_MINOR_ACCEL) - accel_minor_replace(NULL, minor->index); - else - xa_store(&drm_minors_xa, minor->index, NULL, GFP_KERNEL); + xa_store(drm_minor_get_xa(type), minor->index, NULL, GFP_KERNEL); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -224,15 +222,15 @@ static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type typ * minor->dev pointer will stay valid! However, the device may get unplugged and * unregistered while you hold the minor. */ -struct drm_minor *drm_minor_acquire(unsigned int minor_id) +struct drm_minor *drm_minor_acquire(struct xarray *minor_xa, unsigned int minor_id) { struct drm_minor *minor; - xa_lock(&drm_minors_xa); - minor = xa_load(&drm_minors_xa, minor_id); + xa_lock(minor_xa); + minor = xa_load(minor_xa, minor_id); if (minor) drm_dev_get(minor->dev); - xa_unlock(&drm_minors_xa); + xa_unlock(minor_xa); if (!minor) { return ERR_PTR(-ENODEV); @@ -1020,7 +1018,7 @@ static int drm_stub_open(struct inode *inode, struct file *filp) DRM_DEBUG("\n"); - minor = drm_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&drm_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index 883d83bc0e3d..20c9afe0f5a5 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -413,7 +413,7 @@ int drm_open(struct inode *inode, struct file *filp) int retcode; int need_setup = 0; - minor = drm_minor_acquire(iminor(inode)); + minor = drm_minor_acquire(&drm_minors_xa, iminor(inode)); if (IS_ERR(minor)) return PTR_ERR(minor); diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index d7e023bbb0d5..cb46f4c61991 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -77,10 +77,6 @@ void drm_prime_destroy_file_private(struct drm_prime_file_private *prime_fpriv); void drm_prime_remove_buf_handle(struct drm_prime_file_private *prime_fpriv, uint32_t handle); -/* drm_drv.c */ -struct drm_minor *drm_minor_acquire(unsigned int minor_id); -void drm_minor_release(struct drm_minor *minor); - /* drm_managed.c */ void drm_managed_release(struct drm_device *dev); void drmm_add_final_kfree(struct drm_device *dev, void *container); diff --git a/include/drm/drm_accel.h b/include/drm/drm_accel.h index d4955062c77e..f93e23985f4e 100644 --- a/include/drm/drm_accel.h +++ b/include/drm/drm_accel.h @@ -51,11 +51,10 @@ #if IS_ENABLED(CONFIG_DRM_ACCEL) +extern struct xarray accel_minors_xa; + void accel_core_exit(void); int accel_core_init(void); -void accel_minor_remove(int index); -int accel_minor_alloc(void); -void accel_minor_replace(struct drm_minor *minor, int index); void accel_set_device_instance_params(struct device *kdev, int index); int accel_open(struct inode *inode, struct file *filp); void accel_debugfs_init(struct drm_minor *minor, int minor_id); @@ -72,19 +71,6 @@ static inline int __init accel_core_init(void) return 0; } -static inline void accel_minor_remove(int index) -{ -} - -static inline int accel_minor_alloc(void) -{ - return -EOPNOTSUPP; -} - -static inline void accel_minor_replace(struct drm_minor *minor, int index) -{ -} - static inline void accel_set_device_instance_params(struct device *kdev, int index) { } diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index 010239392adf..7fc09460051f 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -45,6 +45,8 @@ struct drm_printer; struct device; struct file; +extern struct xarray drm_minors_xa; + /* * FIXME: Not sure we want to have drm_minor here in the end, but to avoid * header include loops we need it here for now. @@ -420,6 +422,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv) return file_priv->minor->type == DRM_MINOR_ACCEL; } +struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id); +void drm_minor_release(struct drm_minor *minor); + int drm_open(struct inode *inode, struct file *filp); int drm_open_helper(struct file *filp, struct drm_minor *minor); ssize_t drm_read(struct file *filp, char __user *buffer, From patchwork Mon Jul 24 21:14:27 2023 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: 13325333 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 D0D94C001B0 for ; Mon, 24 Jul 2023 21:15:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9884E10E35E; Mon, 24 Jul 2023 21:15:38 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A4B610E360; Mon, 24 Jul 2023 21:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690233329; x=1721769329; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=kUXpil+EcubVXuJnN+4CExkCdaMO2sx5fW3H8oEPG/A=; b=HggiBl6W7RI474Eama9ikkHxfBjzMXG5gc6oN337k1czNFXvCwe55Q7K pvKgMcrMO9o3pvrOS8DjxPeldGx7rhVEovFt7QYsAi6w9lgR9LQFAN8+d 9/OiAtETMmIDVbUnootwm0T6xBxhzagBceiKfg0AJPboBNHCAfhCBcVlV ace1engj3mHbzPxgPvWojErACVBebNTsiY2GiApEPQCUC02IdCZoszaiJ mcigu3tiLCBrQ4gVE3993rBsVZMqXM3QkdJSqLEgF9nY7w6vIW7Cvn0pA UKvxPRime1XmTVQ/C8qmo+87LahOum1Clr/Gl3wZWIb7QNNWwhXGSQJhh g==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="347830106" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="347830106" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 14:15:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="719815891" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="719815891" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga007.jf.intel.com with ESMTP; 24 Jul 2023 14:15:27 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 24 Jul 2023 14:15:27 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Mon, 24 Jul 2023 14:15:26 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.101) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Mon, 24 Jul 2023 14:15:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C5vkG8uxR9l2NCCCrcOo2PLyPQC9NtAL3CKo17athrqfKtUddWTcUqcQzblVUQcAHgFcrCNfnpRvyEjCwgHfHwpvbwPte9aX1+c8V73zYCzWS3KibupQc4pMfE/b2itSIb34e9D8akUpewlSJxS+kRNJg7TrdUkkbHIzBX7zYn8f2Fn+nUYlEWwBqH/4e4+AfB/hVH9k3xLn7Q4dWXZt1ZhgclAxjR7xJ9zXC/PIZUPHCrnOUvzIj8wZThWNaWs3VDZFJIbpquEaJqxc7hMohyEExlZ/9toZpQn044msyMinssrCP3ic5GTwvZXqsc5ib9qI/9cmwLAac18TooQvfg== 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=UsXm8Qul64IFOWsASHDJgaS6S9yTtKU6nE/rDRuoU5Q=; b=ip8eAQvF6CulTgx9rmhTwj1YThwLItRqQ4hIgRQuG7Ut8o3OJTycvqX9uxbuGneGDKDTHE2+dIjn6BBGPlHHpWl7luKN2m6b4TrYjxJuv7j73k5wDYzOHhIfY4Igly47wLoPzN+aaFmVKVV78+uAGJLrwC6Jy9PfdKpEEV88bweSOJvB+AYSsI/0dmxcw00xxzjBQLlW5OkcWTYBj4Hw8HqiF/d4OBN9QRQQQimtrZP4Lnh/bOICbmJxPBTBMOf86csJ1eCDlTPHsMPizgjMdVg/fVLrjtNRcSS1VNP6EnL68HCUY/SByRdcKpqvBsqipE8ljYP30xF1lbO+6PDsQQ== 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 MW5PR11MB5809.namprd11.prod.outlook.com (2603:10b6:303:197::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 21:15:24 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1%5]) with mapi id 15.20.6609.031; Mon, 24 Jul 2023 21:15:24 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v6 3/4] drm: Expand max DRM device number to full MINORBITS Date: Mon, 24 Jul 2023 23:14:27 +0200 Message-ID: <20230724211428.3831636-4-michal.winiarski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724211428.3831636-1-michal.winiarski@intel.com> References: <20230724211428.3831636-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR2P281CA0137.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::12) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW5PR11MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: f78ade33-7299-44fe-f1c3-08db8c8b18ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iRa+9irpUpOX/LmxBviGnEDfzDmiAhALFjmHBZ16RdY5EC4giqdt6ByjdsPk1J2F0VeGfJLcLljfzijTf15dCyuT/0J635javhLQ6y7vFhe/1GR/ZMzj/Vz9rmvp/gUKriqclpdEb6jPQ6tRQ+qCE4FAHOcdDnHICwF3y3GIEt5ojxIFKmuKEYOwvvzCiiCJI92jBUWlwVyzmI4gkuLE1UJPc3MGwirVHlzxjgbWJblQHRBTHUpUhZAefGt+/IgcbuvMrr+hIHVSalU3iwaZRSaj3PM3HjuGCw8YnqzAEieWpgnRR2MfDv2iziZLdhSGxSemrpdIsRHfdPOf4W0dMc8D66edAWVPSUqEAIBpYliOSXXUmrZHtFj2QVy1vbbYIYkJsZzqLziHix7d+181rWPAxKGFPEoep7zf2F5BQhPSUgYjUg4L6KGgiM96IkmSwpMnr+o/FJhDNgtjlcVzycn9y77SJqFEcwg3vg6bw77iPLV1hB9KjP2vpmSsOm8lQBlHIxm3yvwVU4/aE5jlVKBpxyFhn6HcPuRCHheYWwaAfq43dlC9Dj8jRbdcDU68 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:(13230028)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(83380400001)(38100700002)(36756003)(82960400001)(86362001)(54906003)(2906002)(186003)(6506007)(1076003)(26005)(6512007)(6486002)(8936002)(5660300002)(8676002)(7416002)(478600001)(316002)(41300700001)(66476007)(66946007)(66556008)(4326008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rZTz3pugEQ6+ef4Mlj0OIvj3/K5O?= =?utf-8?q?zM3Wqzt19Qv2TztAxTwbEil8vaSY1SpWbxp3FEK5UJgT1DZ+hBG/QNMbZYLDjTf9E?= =?utf-8?q?sMDzgp/jhEz1ejUgwV1RnowABHHGV89obLki44MdHph8vIwNmDukpbQ5iVOaNqTSu?= =?utf-8?q?5NQFbBFu/zDPpUTxS4TvyAZnmng1ojnHccALBt4YKxq4Y/BgS4I8vLJZXeSUBQa9N?= =?utf-8?q?qwZ/SGxfExyj7qcDHX8mVKh8Ohl1m7IbBVIV1+B0Rn+aK7wdhcO2eMWqqlcOOuz46?= =?utf-8?q?IJg1fKfDATE9BH8JWToE+BwI8mZZIuzWphIufC0WuoJkeHE0WbtUwfRr6D+6f2gVW?= =?utf-8?q?dU4BhtiLJhDO8aFnd23lktjYwNYFJ8CoxV6JvE4FVl5IC9uwzNS+ty0MtEEsUlo9F?= =?utf-8?q?OIE5GFWpm6qM20T8FCPuIVspt8bRnqM07vMXa5kYncBWKC6pj+E+7KpdfBM9XJJSx?= =?utf-8?q?c8pe7CSHn+wLE2WlxRl9scANYPqHU/iNca+nDhIZ6h8TLPVAEPQ7Dlxwlr1PrO066?= =?utf-8?q?IdA70lSh8v0f8pfhHLsctROVa+TBr9VA/Bs505cPCcN6ECIN25nnkAUpsGQ0n9U2n?= =?utf-8?q?LO5I0hSEZJp3t+If6wokjRkmh9g9dFqi1ETpLWckYcIiE4Kxp3/Fdw5pQByYoZ2OH?= =?utf-8?q?QNbonvjls45JSkh6/RCFIiogWRjOrt1PSzGkAppCNcMiaxXSoawkT2Yomvy5TLFEA?= =?utf-8?q?y9SkmnGk6z1QlSNy55hIwxzjtFYmDmaollx9v4dfTXGFqKEkt7c76hE4B42iCALEZ?= =?utf-8?q?KPaE9HXd0c4MH46VwHHveSSrRTD6hSi1Yz5c1julB4jHwrqfnm4gV7z0e7C4wvKw+?= =?utf-8?q?8dGYs5bk26n6PFKSg5gEUDh6LnQmYd+IgJpnTlyKOQ7S98ALkxeoUZYsTu3NQcx0b?= =?utf-8?q?wpYhGOvxv4feHB7f3rxU/yEcTCdSPmYTwQ62dr6HmR/ep0iM4yh31vRBPFfnZV8Or?= =?utf-8?q?czAAfTHVo0JKFjT+5XLQF+aF/8MeeZWVONV9jY+Q78FxAB15qLFN2tSWAtjTkLIrb?= =?utf-8?q?RM8t5gECuWbiiKlF++0WUWG7h7BL3W1kNboweJb9cElIr6n4Y1Za9IhtnK5ddKJ78?= =?utf-8?q?jOpU+GLre3BmOm0ZANlasi+cFkAdgCPvxtRFqKfBgVQ6xcEfe/Sr+98hX4RuVFnFO?= =?utf-8?q?s0B5ZmfXF6xRa+tonw8RJ2/axdwGmebaDrj7oWBTWHaRpa73yi9NvExRQib5LfUbE?= =?utf-8?q?uhDJWn/3VdmzPz7nIaSU+Xtb5MDDVbmqwZoxx0wdmxPuRCUOUUny3AMB/fMZ2ahMe?= =?utf-8?q?Eev+UohtXTEo+Zoq4cplxhccSoRrtpgoKJIN8WAy9HtdAchfEpfcU/04AoR9MTfjc?= =?utf-8?q?Ci9qtLwrl5tA71iVMy2355HJxZzFw9ao3qvR7TVO00aDhKruvqGcZGDCTB5yrKVxg?= =?utf-8?q?B58KkLq5EextTHGJi0vqETukN/XJ1GN8xYkvrPNM5ZGjIdcf7+c82ITvXA3HSXGAB?= =?utf-8?q?Bnv2vo9VnqFs98cQhXVlWvt5CiLPumomDTFl5B4kFpuFSyD1Ew6C/wx5GSfah3xuv?= =?utf-8?q?QOeCqY7emzQlBhtJWTCnbWms399w3RqPEg=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f78ade33-7299-44fe-f1c3-08db8c8b18ca X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 21:15:24.8348 (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: vCui1SnYORZj/kKIzR6zWfUC9rQJc9o+2IS1269RfITFmxYuoFcmqISGkwlpCui5JWdbNTzhEotWVVyUECTqYkXrF3PLWPLMv0/LKSyBT9I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5809 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: Pekka Paalanen , David Airlie , Oded Gabbay , Maxime Ripard , Emil Velikov , Matthew Wilcox , Thomas Zimmermann , =?utf-8?q?Micha=C5=82_Winiarski?= , James Zhu , =?utf-8?q?Christian_K=C3=B6nig?= 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. For minors >= 192, we're allocating minors dynamically on a first-come, first-served basis. Signed-off-by: Michał Winiarski --- drivers/gpu/drm/drm_drv.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 34b60196c443..c2c6e80e6b31 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -121,10 +121,19 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) xa_erase(drm_minor_get_xa(minor->type), minor->index); } +/* + * DRM used to support 64 devices, for backwards compatibility we need to maintain the + * minor allocation scheme where minors 0-63 are primary nodes, 64-127 are control nodes, + * and 128-191 are render nodes. + * After reaching the limit, we're allocating minors dynamically - first-come, first-serve. + * Accel nodes are using a distinct major, so the minors are allocated in continuous 0-MAX + * range. + */ #define DRM_MINOR_LIMIT(t) ({ \ typeof(t) _t = (t); \ _t == DRM_MINOR_ACCEL ? XA_LIMIT(0, ACCEL_MAX_MINORS) : XA_LIMIT(64 * _t, 64 * _t + 63); \ }) +#define DRM_EXTENDED_MINOR_LIMIT XA_LIMIT(192, (1 << MINORBITS) - 1) static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) { @@ -140,6 +149,9 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) r = xa_alloc(drm_minor_get_xa(type), &minor->index, NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); + if (r == -EBUSY && (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER)) + r = xa_alloc(&drm_minors_xa, &minor->index, + NULL, DRM_EXTENDED_MINOR_LIMIT, GFP_KERNEL); if (r < 0) return r; From patchwork Mon Jul 24 21:14:28 2023 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: 13325332 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 4EAC0EB64DD for ; Mon, 24 Jul 2023 21:15:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58D4910E364; Mon, 24 Jul 2023 21:15:37 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3675C10E362; Mon, 24 Jul 2023 21:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690233333; x=1721769333; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=ObQZPnTgYJctsRRFRwsoPbyiHauT+kzDucv7KMJN27k=; b=OQBXO8TIp4IU+aiCcxhXMHx8UzUj/ezh+CQjZ1He2CkVOB8KFZKhcKQS MQAJnYKn2C/QGNu2yWysESBVAFnTkCL3xDOwPAtuFUfApt5wxkz+OPI5N EMt2Jly8WAr7j8+oJfHDMr2YsfgQDbR9PbSlLRT+Z4I7jxy4TVIATzgc/ 4roXJdK00jnPWIK2dfpVBPz+NkLQrnrDUWUcVyn1xs40NQqK8xVVNTmLl slr3gj5XEoHGERDQGRbkAOly+OHjLHz2f9dLuTonvyPX2GywXDEbe7IYL sxlBJi7usparvadHC8moQb0Xm3Cd/SlKQqWKKRl0LSaRviG1R/yLV5o1S w==; X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="365014832" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="365014832" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 14:15:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10781"; a="899660532" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="899660532" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga005.jf.intel.com with ESMTP; 24 Jul 2023 14:15:32 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) 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.2507.27; Mon, 24 Jul 2023 14:15:31 -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.2507.27 via Frontend Transport; Mon, 24 Jul 2023 14:15:31 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.103) 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.2507.27; Mon, 24 Jul 2023 14:15:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oA9rcH3JA8NnjP0JNMNfW6OJ0RmtLTLIUN+raHJoKOlfx3K3p97O6E0ucODaAxzePSb8on73FPve7QXPosqT3LFYVZ8yIy9R2u2aht90XRCze0SfJCaO2VcIaCk+5KpfPXIHVQ/c/x78pGBsIjsKYZvZv8sck7s2MnvR+Ufg2y3rrt9mI9qa7ZJidezyfOTIEcjqqMh2eYpis5DiI/A0MTmQC6JN4Da3vQnBjbKMOzpIuv/cHJNqBiZLsxQhz/MCBd62r/RiHeH8A/MD300hLqG8pADO33i4L7PLMBmPGjNAIqpsqBhjsXIyvzJL95HlkUR32vcOPoBNSANLrgbFQA== 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=p0RJm4ACZ5sQ7/Kawds8GvOcxSjjtxeRPVodKaexpq0=; b=DnXr948wRYYCzCCtr7F0WfPev+LjoSUctlpOOlwGwRG04kJ3ukKXpnDq6vfkKEsq0NfNjpfDEoTGOl5Tavo9eJp59dZg7taJerC+oxQH6qqRFTMd/+fIH7IQW6FQ58GY48W8JKusFZ2PPGr0/mGduXOAM71RdrDBFxqO/x8sWfBAWDMrulylew/ZeQvHVodZSp/ypYjGY3l9XYpm8fpbA2JhyIjcGef8hfP6N8iXNsddME2Y14FLwfP+AN3vYG1TJ9CSf8I45jG90F8KDdHzWQmKjLkjedBHKQcxyOCv5fdWLYDR/rdXnwo4gf+hkXBpKoofxK6js85vbI3HMvqkLw== 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 MW5PR11MB5809.namprd11.prod.outlook.com (2603:10b6:303:197::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 21:15:29 +0000 Received: from DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1]) by DM4PR11MB5373.namprd11.prod.outlook.com ([fe80::1127:c109:d888:f6d1%5]) with mapi id 15.20.6609.031; Mon, 24 Jul 2023 21:15:29 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Subject: [PATCH v6 4/4] drm: Introduce force_extended_minors modparam Date: Mon, 24 Jul 2023 23:14:28 +0200 Message-ID: <20230724211428.3831636-5-michal.winiarski@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724211428.3831636-1-michal.winiarski@intel.com> References: <20230724211428.3831636-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR2P281CA0132.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::6) To DM4PR11MB5373.namprd11.prod.outlook.com (2603:10b6:5:394::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR11MB5373:EE_|MW5PR11MB5809:EE_ X-MS-Office365-Filtering-Correlation-Id: f9106c75-42f6-481f-0320-08db8c8b1b64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 460Li8QNaRhIJlVVYiATDiKjl/mPbHsjsyopBhK+tkMbQm7crmN7p/gxqjuSdyEv3pT9IUJJcsVFjZBdFiMJnHNP9zJMFeECl7zs1Ycve8EVNjYIXgFBpznxHMuHM/gte8gnHRK5e4WGpQBiPKH7pKbvDDK2gnLXPW+bx8cxjreoIgYsIos8iNQ/q+91NhZ0LjYgvWYL3BeqjQJ9vA04qXIcwIzykufacw3R184gC8m3L3FDAK3n+f9gS1XEgP6G9mfQH9aykQPHVJQCr/xddVdFvV1jC3sg/bKo1bguczZ8eQ/vPvbhq/OdFT03uO8pOPwNSCS8J3Y3/Wi/06E0occ+vfLc43U4eeYujs3ZsogidLBt4uKKwWfVP8EF+mrqBss6rDjGFYJ1YsAAsE1NVyM8p7fXsvH54LnIrILubG0nMTLSACGvbheh1eM6S0IvJyhLh2MlIEDCsSdz3+ucnEzFauQ6YvrqsxouEgDDbOAt60VdVQxMqB8YdIDBBZQcpjP8tKShybk2dGja87vCUsfPYKn5Nypaw+FbmhVh131FhuM3CvICP46YX9iTo0ND 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:(13230028)(136003)(346002)(376002)(39860400002)(396003)(366004)(451199021)(83380400001)(38100700002)(36756003)(82960400001)(86362001)(54906003)(2906002)(186003)(6506007)(1076003)(26005)(6512007)(6486002)(8936002)(5660300002)(8676002)(7416002)(478600001)(316002)(41300700001)(66476007)(66946007)(66556008)(4326008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?aWP+W84Ty5h+e2Vl3FEsyQ1PT7+e?= =?utf-8?q?i3Iwy5JD/2rs4z808PXG25WoSZnvoRcg4nElCFHMsjN4csyxbzMSrBEO0JIZnI0xI?= =?utf-8?q?JkAWeCIDbV3Vr8FdANP/vd7qFg9OHHZZXuM38dZYB/EEkzAM07T95phAtH9gfMQyH?= =?utf-8?q?GTdEa7eLXRlwBDWjlYx+h7Lcnv13Um2echuWfPGAX2zqTrSg14lX/+u+gVUWR7X7b?= =?utf-8?q?dBMB1aNOvUVhb4ydwj6u3L5STc0B9n6vpSuaupWAll6Xr1IY0kKSLdzGimGGVMUAy?= =?utf-8?q?/wCSmD8HhCZcXFjzAshj7qYxaZUP2Ko+BbM+SPZXwWTerk6Wr3zotRbivo0CoBC2t?= =?utf-8?q?jQwcUxdjpUAW0ymapIMDnbZU51ZzibVj8SlwDQOHFgyUQec+FXBhUFNteLtClS1Cn?= =?utf-8?q?eiAZTyyHmrpBFw8VG7UK4ThUR89EpN4uvwyJyVc0bg6RtN/dG/iBHlLLoSWVz3ai6?= =?utf-8?q?/1E2Y31k4srsI/iv8T16bffckjHomIeMagA/VuLMeSLI9n/WMr3t2i+43g0nUmpLC?= =?utf-8?q?m2Y/m69Rmpcicnc1nqBpvbB0Kknxe+f4EPgPPDaVBwJpZvb1TKVKRJE6hHzDaO4Pr?= =?utf-8?q?TH1ZKCe/rbY7fSQml7b0rJHSCHU4O9ZyI7pB5lHo7Vd2yoUcOZY7ZeVigd4DTymxj?= =?utf-8?q?jWGiot7B7w2wTcT4sho9v+1OECLFzjnLlmE1NMmuiFwOCHqUHNRAh8YH1nGrfDazR?= =?utf-8?q?fi6kpNvKP1BGgUzr/R0bp/4t+8c98wZC/3OUCSfGp0Vetm0rCiSp0jWAURnkyBNBY?= =?utf-8?q?qqEX7wYUc5un+VvB4LYYic20pohlhLAgdKhFPAALqb40lrqlSJ/x+5YVlywysMssl?= =?utf-8?q?S7j63Gh+3Lv7Fiexc0kdIHPG+p2iGXeHv8K9lfvWZAWILo3pgmAwhbF4xzSns0DpS?= =?utf-8?q?5VpD4GDlvjqAf5rid5szYrGXBXXFrXHkf1y4Q49YMnbiHkO3g5lVdOVEfewXuNuwv?= =?utf-8?q?2HJu2liFtF/6JAbzyLO4qUuaiPxyRDnAAKkf4d6W7pij6VtmdWhLA7eaRxaFEvdfd?= =?utf-8?q?abn7T5kCiFqCc0BsdfgWJxMfScXvYpKbD8Tjn2EaA5C9Him9pkWqoC/Dii7aNdxS0?= =?utf-8?q?Mh/ThyXmNvScHzFzyvLyqNP3cBj7Xoxc58DFOW9MDv768+7b5fwsWE9oh2r7dr1Al?= =?utf-8?q?1CdHG8GIByVsH48U1p9J1SBF0DzdfKL6RH8y8gGvUKNN+sUWhaZmmBpOFkqWul0zw?= =?utf-8?q?Sv2ASxRd7m9hsh7jm/b0dhxRMLjiU3FdFnZv6r+Giwk43PGaYIQUPCb+dQYsFX/nR?= =?utf-8?q?vCyYPQjp3MQ61Fz0ePBGoLliTZkKqEXHmmTRJVR8IGl2YLPd9tcPAXLQC69By257t?= =?utf-8?q?FzxdAnaOU5k3yDVdRtoiR9ICbwJEE+qsL4vI01DnXK5NjGiFBSYQEyc4bsEfoXJOu?= =?utf-8?q?qr/d1E5p5fd5KuNxoIC9sJieET9aLJsFLpsIOQqFYbbW/Afu2KZELcXCKkT7j95gE?= =?utf-8?q?Sxv131pN3tHRI2Pf+yd+P7bII0F+pfGmdbhTpzynRpuMRDFv0s0vUKZsEHkKKZs7m?= =?utf-8?q?9a6RO7Ds3w8CSaryZ7Lu2XYDm8Jl7MYafA=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: f9106c75-42f6-481f-0320-08db8c8b1b64 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 21:15:29.2023 (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: UA/g8e58F49tcl/CsOVYBMorCL2mo3kzePvE0frBw5NNXnrGFixDsOn75g5nOzDNbzqkkXTvkQ8lmXJFeV9Um8ugr9LI7I4lGBtF+RYuYv4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR11MB5809 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: Pekka Paalanen , David Airlie , Oded Gabbay , Maxime Ripard , Emil Velikov , Matthew Wilcox , Thomas Zimmermann , =?utf-8?q?Micha=C5=82_Winiarski?= , James Zhu , =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" While there is support for >64 DRM devices on kernel side, existing userspace may still have some hardcoded assumptions and it's possible that it will require changes to be able to use more than 64 devices. Add a modparam to simplify testing and development of >64 devices support on userspace side by allocating minors from the >=192 range (without the need of having >64 physical devices connected). Signed-off-by: Michał Winiarski --- drivers/gpu/drm/drm_drv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index c2c6e80e6b31..ef6d7b498784 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -57,6 +57,11 @@ MODULE_LICENSE("GPL and additional rights"); DEFINE_XARRAY_ALLOC(drm_minors_xa); +static bool force_extended_minors; +module_param_unsafe(force_extended_minors, bool, 0400); +MODULE_PARM_DESC(force_extended_minors, + "Don't allocate minors in 0-192 range. This can be used for testing userspace support for >64 drm devices (default: false)"); + /* * If the drm core fails to init for whatever reason, * we should prevent any drivers from registering with it. @@ -138,7 +143,7 @@ static void drm_minor_alloc_release(struct drm_device *dev, void *data) static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) { struct drm_minor *minor; - int r; + int r = -EBUSY; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); if (!minor) @@ -147,8 +152,9 @@ static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type) minor->type = type; minor->dev = dev; - r = xa_alloc(drm_minor_get_xa(type), &minor->index, - NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); + if (type == DRM_MINOR_ACCEL || !force_extended_minors) + r = xa_alloc(drm_minor_get_xa(type), &minor->index, + NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL); if (r == -EBUSY && (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER)) r = xa_alloc(&drm_minors_xa, &minor->index, NULL, DRM_EXTENDED_MINOR_LIMIT, GFP_KERNEL);