From patchwork Fri Aug 29 12:01:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4810371 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 49C4BC0338 for ; Fri, 29 Aug 2014 12:01:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 19FEC2011D for ; Fri, 29 Aug 2014 12:01:27 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2D37D2012D for ; Fri, 29 Aug 2014 12:01:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 28E626E6C4; Fri, 29 Aug 2014 05:01:21 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f179.google.com (mail-we0-f179.google.com [74.125.82.179]) by gabe.freedesktop.org (Postfix) with ESMTP id AA2DA6E6C4 for ; Fri, 29 Aug 2014 05:01:19 -0700 (PDT) Received: by mail-we0-f179.google.com with SMTP id t60so2039004wes.24 for ; Fri, 29 Aug 2014 05:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ojIaYoHVvaJU3L4lDR2GFyGmR0yvK1JYRtv0cSi5s40=; b=0/C+y32n/tn2zT1pbS6idyTIGsmcY5fUWiRr22GSdIRSJHDVJUxdNpdhMN5oHEiQHt L4eEhJzm26jSftnkQlB07ZsO5Ed43kmxRM6AlJ1RHUvZ3w7CJu93zxZwhKXkJUQuEKGw tvhvh+cN8HJ+qEyDf7asxfO/nS5alaiTAIQlc+ecuWpCMtaX22FwOzIczf/sS4jvadQh GnzUr5i/rfw31Uwf6b7qOEv/fppbFe/53UOA8mLtt8ZWMvP6GkBm6UHzOyQj6ReZ2POt ONwwfU+B0P/Y8e98ms/oNiDyYH1WDw6fP5DCfPV4qGtHofIdtyTW1c5EMcmXjg7N9NpI ErKw== X-Received: by 10.194.89.200 with SMTP id bq8mr12931001wjb.52.1409313677500; Fri, 29 Aug 2014 05:01:17 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d02e0c1.pool.mediaWays.net. [77.2.224.193]) by mx.google.com with ESMTPSA id cz3sm18089499wjb.23.2014.08.29.05.01.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Aug 2014 05:01:16 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm: don't recycle used modeset IDs Date: Fri, 29 Aug 2014 14:01:01 +0200 Message-Id: <1409313661-20696-2-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1409313661-20696-1-git-send-email-dh.herrmann@gmail.com> References: <1409313661-20696-1-git-send-email-dh.herrmann@gmail.com> Cc: Daniel Vetter , stable@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With MST, we now have connector hotplugging, yey! Pretty easy to use in user-space, but introduces some nasty races: * If a connector is removed and added again while a compositor is in background, it will get the same ID again. If the compositor wakes up, it cannot know whether its the same connector or a new one, thus they must re-read EDID information, etc. * possible_clones, possible_crtcs, etc. depend on indices, not IDs. So if an object is removed and a new one is added, those bitmasks are invalid and must be refreshed. This currently does not affect connectors, but only crtcs and encoders, but it's only a matter of time when this will change. The easiest way to protect against this, is to not recylce modeset IDs. Instead, always allocate a new, higher ID. All ioctls that affect modeset objects, take IDs. Thus, during hotplug races, those ioctls will simply fail if invalid IDs are passed. They will no longer silently run on a newly hotplugged object. Furthermore, hotplug-races during state sync can now be easily detected. A call to GET_RESOURCES returns a list of available IDs atomically. User-space can now start fetching all those objects via GET_* ioctls. If any of those fails, they know that the given object was unplugged. Thus, the "possible_*" bit-fields are invalidated. User-space can now decide whether to restart the sync all over or wait for the 'change' uevent that is sent on modeset object modifications (or, well, is supposed to be sent and probably will be at some point). With this in place, modeset object hotplugging should work fine for all modeset objects in the KMS API. CC'ing stable so we can rely on all kernels with MST to not recycle IDs. Cc: # 3.16+ Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_crtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 97eba56..ab0fe6d 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -286,7 +286,7 @@ static int drm_mode_object_get_reg(struct drm_device *dev, idr_preload(GFP_KERNEL); spin_lock_irq(&dev->mode_config.idr_lock); - ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_NOWAIT); + ret = idr_alloc_cyclic(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_NOWAIT); if (ret >= 0) { /* * Set up the object linking under the protection of the idr