From patchwork Tue May 22 14:13:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 10418705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F370060224 for ; Tue, 22 May 2018 14:13:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E16E8223A4 for ; Tue, 22 May 2018 14:13:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5D7C27E63; Tue, 22 May 2018 14:13:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 624C9223A4 for ; Tue, 22 May 2018 14:13:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0670D6E18D; Tue, 22 May 2018 14:13:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 05C586E18D for ; Tue, 22 May 2018 14:13:20 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id w194-v6so192309wmf.2 for ; Tue, 22 May 2018 07:13:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EjYInDPr33WDwWzCeMWH7UuNSp7NlVL7PkMtYFHupUs=; b=AtFRR2LhS1CrOwd3GI2qrzY2GpncyizAb3RfcdJd+NH35wapVmTMgzIqJvea5Xpq70 05kaKE2ycrotqt2ZKfGregkxaFABD17O7cWjfp+9sMyqdzW7bZE2dVm860Qljodau9oi teU7XoMceiSWPIAKwcob6F0bEaofgBqBLy3V5QqzxmFaUBYIwyWSF+rHqb3Q8x16aEkW uXjrNV6ape8++T/TT2Izw8Izm7QlR7ZsnIhXg+o5qe2/xM6lsGHDRa9gAOiJqCRPip2q nlVurRBVMBAaGXYr+8OYrFyouQanfuarY0vjzLsswpCo46ukkJxmw70bhz4gl6oJqkj2 x93A== X-Gm-Message-State: ALKqPwch1suJ3nJ5pW2cZWbsphSBy5vRnnGwoRFtwQ+lC631mAcHBbHC ezkrioSvsfvUL86pMUddnrA= X-Google-Smtp-Source: AB8JxZpzpp7Z2RV5AuE/2Rt46Sz4VeCpPI3gQ+B1j0Om171QF9/A/ZvOBKc7uJJw/4Am73dZgFCLUQ== X-Received: by 2002:a2e:8993:: with SMTP id c19-v6mr15602191lji.123.1526998398560; Tue, 22 May 2018 07:13:18 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-54.209.223.85.sovam.net.ua. [85.223.209.54]) by smtp.gmail.com with ESMTPSA id k127-v6sm3956016lfe.21.2018.05.22.07.13.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 May 2018 07:13:17 -0700 (PDT) From: Oleksandr Andrushchenko To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, daniel.vetter@intel.com, seanpaul@chromium.org, gustavo@padovan.org Subject: [PATCH] drm: Fix possible race conditions while unplugging DRM device Date: Tue, 22 May 2018 17:13:04 +0300 Message-Id: <20180522141304.18646-1-andr2000@gmail.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: andr2000@gmail.com, Oleksandr Andrushchenko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko When unplugging a hotpluggable DRM device we first unregister it with drm_dev_unregister and then set drm_device.unplugged flag which is used to mark device critical sections with drm_dev_enter()/ drm_dev_exit() preventing access to device resources that are not available after the device is gone. But drm_dev_unregister may lead to hotplug uevent(s) fired to user-space on card and/or connector removal, thus making it possible for user-space to try accessing a disconnected device. Fix this by first making sure device is properly marked as disconnected and only then unregister it. Fixes: bee330f3d672 ("drm: Use srcu to protect drm_device.unplugged") Signed-off-by: Oleksandr Andrushchenko Reported-by: Andrii Chepurnyi Cc: "Noralf Trønnes" Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_drv.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index b553a6f2ff0e..7af748ed1c58 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -369,13 +369,6 @@ EXPORT_SYMBOL(drm_dev_exit); */ void drm_dev_unplug(struct drm_device *dev) { - drm_dev_unregister(dev); - - mutex_lock(&drm_global_mutex); - if (dev->open_count == 0) - drm_dev_put(dev); - mutex_unlock(&drm_global_mutex); - /* * After synchronizing any critical read section is guaranteed to see * the new value of ->unplugged, and any critical section which might @@ -384,6 +377,13 @@ void drm_dev_unplug(struct drm_device *dev) */ dev->unplugged = true; synchronize_srcu(&drm_unplug_srcu); + + drm_dev_unregister(dev); + + mutex_lock(&drm_global_mutex); + if (dev->open_count == 0) + drm_dev_put(dev); + mutex_unlock(&drm_global_mutex); } EXPORT_SYMBOL(drm_dev_unplug);