Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3108219imm; Tue, 29 May 2018 00:50:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrdp0ueF5qqlUnuYMZdepmACnpDuWiIJkCu9kPRLnhMi387rJhbBXTQ1K4oWUn2E04X88GF X-Received: by 2002:a17:902:a512:: with SMTP id s18-v6mr16493931plq.223.1527580220686; Tue, 29 May 2018 00:50:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527580220; cv=none; d=google.com; s=arc-20160816; b=xGKzN4u9aDx6EtrFs1H7uMTs8+2aXyZqyNstntbiu9NHU36qnjSe/65GJGnu5xvRyr eyDQDvc4CVfLIiyiCjbv6OnGHrIrZwgQa803SFJr6cMcyc+htBPVhK64JVFo3hlpBtZx LwqMRYF2NAn8YwzT9TLVYsV147Reun+6VwuM5fFtE95liA8u5Qn825GinnDLptcIA4uB FyFFcK6/fPNDRiRiWP0qUOj0qnhliVOLlwh8TpqLiPy9y1IFAm+qcI0Iw/Yql57NAsMa N63/Nm0p25G1pYTIsJOWzGgqoy1z4GiUqKPiweB8zxtloAxo1PdNKOWqM+STSw6jvDjN wLzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=/o56rEpS7KshqUf+ZyxZquftK766glqvOfDCtBm0pAE=; b=Aaf2aWMulFy9M5RgKNWE+1XHpOQahH13H9vgCYuyzl2SC7+UzfRsm761MZkIm77PC1 0AhWC94JxO/VYmOdHKUMWZqs3KzLkXUfSeG0e/SVPZVTAx8SDOeViyoxV62SEv1ikhgR ywoN3aF7DrRNMeCP5NTyKMrLEtJypyU12i62+1/N9lv30ogUSGwTKB9HJEOKsEu3V+zL lCiZduGE4r4IsJ5Wg+AE+aSBIPaFVpYvMjwby1xgNIzxcAKnhU0/4GBEXi3FGpByyLZg 0RZzBvsDVgjAKRYFp1A6nyrGxOOBg2opJWfOz08QYuaijQeWfmmvIgwQGMjbBG8EYQs1 Sc9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=IHxpwYsn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12-v6si22380993pgf.653.2018.05.29.00.50.06; Tue, 29 May 2018 00:50:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=IHxpwYsn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932232AbeE2Htj (ORCPT + 99 others); Tue, 29 May 2018 03:49:39 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:56103 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932081AbeE2Hth (ORCPT ); Tue, 29 May 2018 03:49:37 -0400 Received: by mail-wm0-f65.google.com with SMTP id a8-v6so37692461wmg.5 for ; Tue, 29 May 2018 00:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/o56rEpS7KshqUf+ZyxZquftK766glqvOfDCtBm0pAE=; b=IHxpwYsnqioAgJ0ZOcpdn7TqEfNJm7GJMsUxBeRHLleE6FxVOTajsawr+jTrS/BovB Ntky3CyXT61Jrj3hHyBdKHBkPoF/5paoGmUHIQ6C9Nq0Lrdd95sW0RXuLfqUsriJZxFr sY1YEqAzmxfLNDVvlNgTiJmp1xVfIK7+RcBSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/o56rEpS7KshqUf+ZyxZquftK766glqvOfDCtBm0pAE=; b=lA7QiHoVhEvWR0gomn1QPpRbdxJW/t0VmakRvT7AoBRhaxAtPyydDVPiy+t5O21JVn DZvncEbIAjfbfL/lnwG3JSAKqkKWvSM1/x73ww7K1uVHHHxOF63fclqNS1M2V1lI1bS4 8rArAwLs7EzPqkle/v2BEQ+Hm9OQN+TPyeTaGAcqwJA6CbIQ/7gOWjXG5JNR3F8maM3D n1zlU16IR7ugwVFka1ZYIx5CtBeeObAixItl6nuQmsmoVLZUoGrw4UOiVoVL8F/591GX jUAL902jjumEo2R1THD0+Jtf5Mj+JOwvEIGyhQVLzR3bRD0iPtDg4TsywmPHK3FEoHCS NT6A== X-Gm-Message-State: ALKqPweFWW1ZrTocHA3E6tt6sHWXycPI/NpNKjIZSG0NRRnjrNhQu1pA mSm/F27UA2ydb48q/9Wbx7ACLA== X-Received: by 2002:a50:a926:: with SMTP id l35-v6mr18456684edc.106.1527580176471; Tue, 29 May 2018 00:49:36 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:5628:0:d0c7:bcda:eea:9e5d]) by smtp.gmail.com with ESMTPSA id d6-v6sm7178811edo.18.2018.05.29.00.49.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 00:49:35 -0700 (PDT) Date: Tue, 29 May 2018 09:49:33 +0200 From: Daniel Vetter To: Oleksandr Andrushchenko Cc: "Oleksandr_Andrushchenko@epam.com" , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, daniel.vetter@intel.com, seanpaul@chromium.org, gustavo@padovan.org, Noralf =?iso-8859-1?Q?Tr=F8nnes?= Subject: Re: [PATCH] drm: Fix possible race conditions while unplugging DRM device Message-ID: <20180529074933.GY3438@phenom.ffwll.local> Mail-Followup-To: Oleksandr Andrushchenko , "Oleksandr_Andrushchenko@epam.com" , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, airlied@linux.ie, daniel.vetter@intel.com, seanpaul@chromium.org, gustavo@padovan.org, Noralf =?iso-8859-1?Q?Tr=F8nnes?= References: <20180522141304.18646-1-andr2000@gmail.com> <20180529070200.GW3438@phenom.ffwll.local> <3427121e-ddd9-d2ba-b684-61338f0207ce@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3427121e-ddd9-d2ba-b684-61338f0207ce@gmail.com> X-Operating-System: Linux phenom 4.15.0-3-amd64 User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 10:09:57AM +0300, Oleksandr Andrushchenko wrote: > On 05/29/2018 10:02 AM, Daniel Vetter wrote: > > On Tue, May 22, 2018 at 05:13:04PM +0300, Oleksandr Andrushchenko wrote: > > > 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" > > Nice catch. > > > > Reviewed-by: Daniel Vetter > > > > I think you need to push this to drm-misc-next-fixes to make sure it's on > > the 4.17 train. > Sure, after I have r-b from Noralf Noralf's occasionally occupied with other things and doesn't have time to look at patches. I think it's ok to just push after a few more days, even if he doesn't respond. Same holds for other people really. -Daniel > > -Daniel > > > > > --- > > > 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); > > > -- > > > 2.17.0 > > > > > > _______________________________________________ > > > dri-devel mailing list > > > dri-devel@lists.freedesktop.org > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch