Received: by 10.192.165.148 with SMTP id m20csp1828088imm; Thu, 26 Apr 2018 02:54:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx48t89Qm8KMKVWUb89pkUIpUz5C3Nkrq/Bk3m3q4XsVOPv7IPD2RP7e/J8qW22m9TqqOG/c6 X-Received: by 10.99.116.8 with SMTP id p8mr26461377pgc.327.1524736476908; Thu, 26 Apr 2018 02:54:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524736476; cv=none; d=google.com; s=arc-20160816; b=hEO4lrhmEMbZc5O5SvPxHBDZiZKH7hC8QZ5NrBkaCcGSu9JmDNb3tt0sgfxa762PYo LOUTDunr3/5DpXMJoGtsdFrvFVpbiEDGOIvHtdhKEBRJMfZrQgTMcNzv/FdVaILkZcbA grqdPRnpUEIQSLlcJ+T5w8em+ZJpLvF+oa0QmsYObmJV0r0KXP+oTM827uK+ycM/bSvu rHeKlMJxdlNhaSiiT5KRxRqduYKeBEg5PeP8IRZns5F+zDvhsGeoOn9niD+sddYQI44P Ta7dNxDvWiSAHqZFGwyRlpMnx91PZsyEmUnfcbJc9hxCHtHJ3Et5b8KTGCaIMByJjVet 9Tdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=qE+LWCYUyio3BQcyVVBF4JSkEu/2sSr0h0Yv/0qUo+M=; b=hlfHbBKv61LRBuFCLzzWIKcHadDCJ4xYVu1sW1Yy8ec9DN7BXIC3aTVdiJJ74Xldk4 ebvh9PvhKW7NqgHJOhlueZ0mldHmpCXdtfuEITDbrOaFfHppHNxq8Sc9UIXMjF5gese6 pcCFvkaKhOmFIPNKxjrwrePFIWfk7V0h9/Wu5j3BAd4+dvFU4xRDIjWFUgGMIkdFl96G BC/TuUxJ2QZV9qq7je7BXMkVQxzNL7frYAU09SfkaZSLUwmM4XFaoj+7L9vsAeIuRLJp vYjEtLNEMWOZstB8NVzrIXz2kH0F0pHK9QnchFmZOwT+dTFfkVeyYExjTeTUO6IDpm67 m/Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=IuLeWbPj; 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 z17si11819250pge.271.2018.04.26.02.54.23; Thu, 26 Apr 2018 02:54:36 -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=IuLeWbPj; 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 S1755376AbeDZJvF (ORCPT + 99 others); Thu, 26 Apr 2018 05:51:05 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:39313 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755176AbeDZJuC (ORCPT ); Thu, 26 Apr 2018 05:50:02 -0400 Received: by mail-it0-f68.google.com with SMTP id c3-v6so8909114itj.4 for ; Thu, 26 Apr 2018 02:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=qE+LWCYUyio3BQcyVVBF4JSkEu/2sSr0h0Yv/0qUo+M=; b=IuLeWbPjVzG4pmsVS9liihuiMZ2bdFhBvNMMvrXoYbuU7YtQjrA6lH9MkpKALQAHDm RpWMdICWre8B8o+7hFfi0P2bMbLs/eg0FT9am+UTbO42IoQ/cg4atwd5Ci4nOx8R3uTm w537M3QelcCVO1dwV69lzMY+2sNQwgeK/lsys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=qE+LWCYUyio3BQcyVVBF4JSkEu/2sSr0h0Yv/0qUo+M=; b=Wp7AJRvNNpeRlekT74+GcX9aButcvHcF57LdCOvaYWCmE75KYZq2EpL1q7WipqAhJQ 7M8kPaeSjjaJeMhosGBak1grjb3IH4drnhCMg6lYZq2kiXl5bZR42Di6ASdR9mf2GxJh ixg4NS9o9HtXP7AbaMeT/+UNEzSjNJkeLhDsGBUfQ1G5o+ETEzMrQmDykFIsn85MuMTM PYCGIT0O6D1K5mGZq3sGT92+vD1dK3k9ABBUlJN2271dtHxrYwgkcSpHi+V4uzAP9QPz JOAIrlQymj1yM4m4a86LNnl7cWZalaf3icZTZQN3q0s3+FMFDuesKb4PcZtdEmopKzKS zUFw== X-Gm-Message-State: ALQs6tBEyk0kgNlPQSQDWd7UXeMF1Tmc4mJbaaYIhsdzp28UJ+b7mj2A eaL59uXk2XFDcD/5RS4vxBVyeqQqKeQpNlpM5+qb8g== X-Received: by 2002:a24:468a:: with SMTP id j132-v6mr25466818itb.23.1524736201886; Thu, 26 Apr 2018 02:50:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:f0d3:0:0:0:0:0 with HTTP; Thu, 26 Apr 2018 02:50:01 -0700 (PDT) X-Originating-IP: [2a02:168:5635:0:39d2:f87e:2033:9f6] In-Reply-To: References: <20180420115001.161745-1-lndmrk@chromium.org> <20180420135532.GH73214@art_vandelay> <20180424130445.GD31310@phenom.ffwll.local> From: Daniel Vetter Date: Thu, 26 Apr 2018 11:50:01 +0200 X-Google-Sender-Auth: KyBi9PyD_QDkXfJca_M5a1Ks5hA Message-ID: Subject: Re: [PATCH] drm: udl: Destroy framebuffer only if it was initialized To: =?UTF-8?Q?St=C3=A9phane_Marchesin?= Cc: Sean Paul , Emil Lundmark , Dave Airlie , Linux Kernel list , dri-devel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 26, 2018 at 12:56 AM, St=C3=A9phane Marchesin wrote: > On Tue, Apr 24, 2018 at 6:04 AM, Daniel Vetter wrote: >> On Fri, Apr 20, 2018 at 09:55:32AM -0400, Sean Paul wrote: >>> On Fri, Apr 20, 2018 at 01:50:01PM +0200, Emil Lundmark wrote: >>> > This fixes a NULL pointer dereference that can happen if the UDL >>> > driver is unloaded before the framebuffer is initialized. This can >>> > happen e.g. if the USB device is unplugged right after it was plugged >>> > in. >>> > >>> >>> JFYI, in future, if someone makes a suggestion on how to fix a bug, it'= s good >>> practice to add a Suggested-by tag to give credit. >>> >>> Reviewed-by: Sean Paul >> >> I think a bit more detail in the commit message on why this is even >> possible would be good. I think it can only happen when you only plug in >> the udl, without anything connected. > > Hehe, I was just reviewing this code internally, so I can answer that one= :) > > It happens when fbdev is disabled (which is the case for Chrome OS). > Even though intialization of the fbdev part is optional (it's done in > udlfb_create which is the callback for fb_probe()), the teardown isn't > optional (udl_driver_unload -> udl_fbdev_cleanup -> > udl_fbdev_destroy). > > Note that udl_fbdev_cleanup *tries* to be conditional (you can see it > does if (!udl->fbdev)) but that doesn't work, because udl->fbdev is > always set during udl_fbdev_init. Ah right, that's another scenario where fbdev never gets fully initialized, totally forgot about it :-) It's a bit unfortunately that we don't have a simple fix for this, i915 has a bunch of messy such checks too. Hopefully Noralf's work to make fbdev emulation look more like a normal kms client (which just happens to run within the kernel) will help here in the long run. -Daniel > > St=C3=A9phane > > >> >> In that case fbdev setup will be delayed until something shows up (so we >> don't pin a too small fb for it, a feature requested by soc people). Thi= s >> can easily be tested: >> First: >> - plug in udl device >> - wait a minute or so (to make it clear it's not a race) >> - unplug >> >> And then: >> - plug in an udl device, but with something connected. >> - unplug right away. >> >> I expect that in the first case you'll always blow up, but in the 2nd on= e >> you'll never blow up (no matter how fast you unplug). >> >> Cheers, Daniel >> >> >> >>> >>> > Signed-off-by: Emil Lundmark >>> > --- >>> > drivers/gpu/drm/udl/udl_fb.c | 8 +++++--- >>> > 1 file changed, 5 insertions(+), 3 deletions(-) >>> > >>> > diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_f= b.c >>> > index 2ebdc6d5a76e..5754e37f741b 100644 >>> > --- a/drivers/gpu/drm/udl/udl_fb.c >>> > +++ b/drivers/gpu/drm/udl/udl_fb.c >>> > @@ -426,9 +426,11 @@ static void udl_fbdev_destroy(struct drm_device = *dev, >>> > { >>> > drm_fb_helper_unregister_fbi(&ufbdev->helper); >>> > drm_fb_helper_fini(&ufbdev->helper); >>> > - drm_framebuffer_unregister_private(&ufbdev->ufb.base); >>> > - drm_framebuffer_cleanup(&ufbdev->ufb.base); >>> > - drm_gem_object_put_unlocked(&ufbdev->ufb.obj->base); >>> > + if (ufbdev->ufb.obj) { >>> > + drm_framebuffer_unregister_private(&ufbdev->ufb.base); >>> > + drm_framebuffer_cleanup(&ufbdev->ufb.base); >>> > + drm_gem_object_put_unlocked(&ufbdev->ufb.obj->base); >>> > + } >>> > } >>> > >>> > int udl_fbdev_init(struct drm_device *dev) >>> > -- >>> > 2.17.0.484.g0c8726318c-goog >>> > >>> >>> -- >>> Sean Paul, Software Engineer, Google / Chromium OS >>> _______________________________________________ >>> 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 >> _______________________________________________ >> 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 --=20 Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch