From patchwork Tue Sep 6 20:16:27 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: 12968149 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 C1BEEC38145 for ; Tue, 6 Sep 2022 20:17:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4AA3F10EA82; Tue, 6 Sep 2022 20:17:15 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6C56A10EA82; Tue, 6 Sep 2022 20:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662495428; x=1694031428; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=sbKfQTg+CFMo3FiMihv9YnajB9h+ql7gf2rY835FJg0=; b=MeX+pEnh9lQ9R52/38dMgFRVVOzYhoZC2CeVAMMoen+8AqRfzLALhoyi Ia3tLdlweayygU9E6ABp+UgyxBUVMAbwM0/nuJDwyHBDaMLtU/olIyRKJ aCC2TE2xB9siadpVsN02vo6qD+J8h4vFuYfeiSIMVHbgW2NgBcYP1dCJO 9L4swSKiKSIeBtXXx/WvcvhyPKWe2rIqjJbSKTKKAJkCjkmiXr1GPPjpB COijN/StCQse5jQJMkw193IMGlCjhVhCEmtPcLGSqHRJ02i27Ou7yYm4T C8JhcgW5GVpUKvdrtHQmjIWJTmWH2MXA3+y9I2lqv4RcR8x+bEPLV6/KQ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10462"; a="297479848" X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="297479848" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2022 13:17:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,294,1654585200"; d="scan'208";a="610076379" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orsmga007.jf.intel.com with ESMTP; 06 Sep 2022 13:17:07 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) 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.2375.31; Tue, 6 Sep 2022 13:17:07 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) 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, 6 Sep 2022 13:17:06 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.109) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Tue, 6 Sep 2022 13:17:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FCBn+AoGF39gpxOtZ+N+GJD+X8I6PVRd9Pn/O+ZnXQyA5zI0aw9olIepRRaU/p83+L8e+RNLWjvWoRWztbG2nVwb5690QppOxy1/xLFe1vaPR2kHOJ8aP0YjGz1PApM2VIbqYC7W5+n8pxWHaJVuRQSixkeAPOaYFu4WNVJHXbkUyAkb+wZKMOgV0j2O0RBo6iRnGvbY7s6FtjTYa40/22Dbhe9qPe5eQdxF/aUotFfbucu2951SX9tjoMhRWrhMPHY9sRNbxHkwdIxVPMTTebF9vUctTKkMuooZ9109LpatSkW8zXdkVh/f5nla9xvwxjKlu1JirMbfIJnDpKll/w== 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=Os1VZYkjqlvvGr86DKSKUwsxFEaQ4MP+zgd8BGaa3do=; b=Li0RRzu+GxP4onMcHgj8vwXs6Q2STyi704tsBQQ5VeExu7GWaa17cP96Hqr76hRH1OMEx+IMdDj7QeFVF1a52icOrTya44rVpYUEMdz/kWUK9Z413Fsd3VJZrArCOxXtB+wb5Hb4FKrHjzKlOXD/agYGumkbcpvofeAoHpo9VZYQBGPmCR91YhY62JIenuftsuX5or15IjcS4lDjru9EQm2h9165U+rUUmwMpE0EoqQXgK0ueIXdJaSqaUQHm+fMtRHjSdtrrVN6dAG7N5/yGIz3bG1d2Dwa0Mv1nnBZxPUywj73O0T9sNSOMHBXGZj55zlYBmnggKNYD7f1two9lw== 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 CH0PR11MB5396.namprd11.prod.outlook.com (2603:10b6:610:bb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.12; Tue, 6 Sep 2022 20:17:04 +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.5588.018; Tue, 6 Sep 2022 20:17:04 +0000 From: =?utf-8?q?Micha=C5=82_Winiarski?= To: , , Date: Tue, 6 Sep 2022 22:16:27 +0200 Message-ID: <20220906201629.419160-2-michal.winiarski@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220906201629.419160-1-michal.winiarski@intel.com> References: <20220906201629.419160-1-michal.winiarski@intel.com> X-ClientProxiedBy: FR3P281CA0121.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::8) 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: 972bfaa2-37df-47e1-f1a7-08da9044c383 X-MS-TrafficTypeDiagnostic: CH0PR11MB5396:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DzWShhHTdeEcSa0Mk1C7uSM7/xek/XtdBqlXCis+miUwV7LCCl9e8qKUmzbhs35+2+nuLgJImUSy+iIu7KwRnC64e4l+SKC04P2JSI3KzEnl1whgefOGfjkDMeMtm3bgi4VcC04j5S9JXNuyTJiHm/bUCAzaB3uJtj3Ib9Qq7TU3SwX/EuZx7glm5mm06iNoikeUBCy7o0SZuATT+RNQjTTDJQ+otuq3+q/wXg1RAPCltBurU1YEHMSN6F1pNc1WW3YQJFTbQrxGO8f8WcgipqCQmr21v8fz5DK6E1d/K69QmIWhq8py8xV3INM0JyWkf05z9Zg+Mg8tGpVEprJS3/sxbrl+OxdWrlcMP7blsLzayzhfbmGdF5WRRKuZsjbFpxomd65k2mSCDFB+Y3zW2+AXb1cATPay2WBhzhxpBYWyVVqOu52UH5gU7XxRwDtchm0GrWNDW9jHtr21rjqDMi5cuW++Ppod/4wXbUc5JA0hCBxIvPFNWSaqct2ExqLB63tv9iYv0pWtR8yi9W5YJ1C/8uXrJMRP9oD8FgUed4LZ3rkzJLMdFnwnzGlusn0prnKzBunmIH/MxHDrGkx23uCeRxxxDIvnuY7ssFtgmQxHGboZK0zXHjSNiC7eDW9qbjA3jezkHTcZmWSksmoL21R+UGWgr6owgNZqt2R5LGYDqqjH+Xq/MjQZ4it6bhFw1Q9bmGSnzOzRJQ+2sHRo7g== 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)(396003)(346002)(136003)(39860400002)(366004)(316002)(54906003)(86362001)(82960400001)(36756003)(2906002)(38100700002)(5660300002)(8936002)(7416002)(66946007)(4326008)(66476007)(83380400001)(8676002)(6512007)(6486002)(2616005)(6666004)(186003)(1076003)(6506007)(478600001)(66556008)(41300700001)(26005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?36MmrgVcreRfL1saizwK2D5qcDaV?= =?utf-8?q?t0Z38VC/HYxHtkRbet4wuFIzElXEgXF2aUFptut7BuSlnwXEf0BUzF9w3pnb4seD2?= =?utf-8?q?08VI4PXCjkTdTFpUGiMnfz3TylFCSWNeOeMdR6rr7N46tuA06pt6t8rkGUkL4zvJI?= =?utf-8?q?yDEdOVG6GOUBRKXFVsn50boUfZ3IiD8G4ioSmTYm2O3cOi/Ly9Hkd5Bn5KiTEPeOH?= =?utf-8?q?CUXRRGW/pAZl1jnrVosru+dnuMK5a7S4NiXvzETijbaXRVq3Hlpj98XqEVHx58yCp?= =?utf-8?q?yiN1fD9HywdD2wD72hewLTuYsWUloV5EYXVULuVdmV01PG6+OxysLu7nuV0jW0Cmh?= =?utf-8?q?Won498npNBJBQkt9IFyHvWX0insK7ybqMTt/JYO958Sx20nWNBSCbqCIwdFJcLtCU?= =?utf-8?q?vW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cDjdJUPGftaMp9cb53arHEItqd5ceZ0Op5z6AJMZXP/4xWeKTzQclFUR?= =?utf-8?q?G5CjWC6jxwQn+Bwi+cXP0qwOzNMWmLaV6eSPa0RiTHezkaTONcEv/E0I+n7PgWi+J?= =?utf-8?q?v25rnH+NLyWK+3UtYLBM4FNsNWUExiB4gtFQTDpNQqrwh7Kgat7JyTJOXNRpxUdEY?= =?utf-8?q?nMRFj7vUqGw+CC5ogBMbCqbtsMSOfnp+kWVOoJKY2BnnvQvb8w6xKiFdKgS1ctmxg?= =?utf-8?q?9WRe6A+4nsinq8CNE96E7EGqlR9Y+1EMuQ=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 972bfaa2-37df-47e1-f1a7-08da9044c383 X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5373.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2022 20:17:04.1069 (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: hAUHbuah5dWnGGWtMWAW6MdOQWAoOLnppcnpXoNG7XIr+jTWXZjZtjkzMmZDg0XTWRWbttP4OWLzsY4Fm6ksVMdYpzrNwBVs5RDckeOgwLY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5396 X-OriginatorOrg: intel.com Subject: [Intel-gfx] [PATCH v4 1/3] drm: Use XArray instead of IDR for minors X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Micha=C5=82_Winiarski?= , Daniel Vetter , David Airlie , Simon Ser , Maxime Ripard , Matthew Wilcox , Thomas Zimmermann Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 | 49 ++++++++++++++------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 8214a0b1ab7f..41799e4d0432 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 @@ -53,8 +54,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, @@ -98,21 +98,18 @@ 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); - idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_release(&drm_minors_xa, minor->index); } static int drm_minor_alloc(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; - unsigned long flags; + u32 id; int r; minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL); @@ -122,20 +119,12 @@ 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(); - + r = xa_alloc(&drm_minors_xa, &id, NULL, + XA_LIMIT(64 * type, 64 * (type + 1) - 1), GFP_KERNEL); if (r < 0) return r; - minor->index = r; + minor->index = id; r = drmm_add_action_or_reset(dev, drm_minor_alloc_release, minor); if (r) @@ -152,7 +141,7 @@ 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; + void *entry; int ret; DRM_DEBUG("\n"); @@ -172,9 +161,12 @@ 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); - 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); return 0; @@ -187,16 +179,13 @@ 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); - idr_replace(&drm_minors_idr, NULL, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_erase(&drm_minors_xa, minor->index); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -215,13 +204,10 @@ 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); - minor = idr_find(&drm_minors_idr, minor_id); + minor = xa_load(&drm_minors_xa, minor_id); if (minor) drm_dev_get(minor->dev); - spin_unlock_irqrestore(&drm_minor_lock, flags); if (!minor) { return ERR_PTR(-ENODEV); @@ -1037,7 +1023,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); + xa_destroy(&drm_minors_xa); drm_connector_ida_destroy(); } @@ -1046,7 +1032,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();