Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2392427ybl; Mon, 20 Jan 2020 02:01:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzHMho43K3wndyaOfXj1S2NXe+IUK6a0HXbUfN+5lUCS3HzwpUcoprSht2/c1iDu1EXi2ov X-Received: by 2002:a05:6830:1442:: with SMTP id w2mr15880138otp.143.1579514494567; Mon, 20 Jan 2020 02:01:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579514494; cv=none; d=google.com; s=arc-20160816; b=cXILtzE0Ll6PfJWjbu7EVC6ivxDkJ4QD4Ko6kw3LE670LYo0m2M44hwGPDxQvrpnza RAyw1o9vMV+yGiePVO9DG3kTRkdNP1j11ze/b184OLmoxEYDsneItNurVthrPH5kmgFw OR0JRk1QQmty1QYwhv+7hEOm/DTD4Duc60BCNVixy/ULf+VKaMYzmIrXBPkimJwLuQXy yaCQAGDzf+U1X5y0IRCMsyg6vJST7QpzyNVN+/qibgbxO2l2hdesmblQB8IdPnes0kyE M3F9awMxkISPT0cbIbZS58cHrNY7N37Mh6dhg7wmLzLVLnGDy9DCrcVOmM1POHw2HdMT jU0Q== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=A5GcFGtVAQWVAj/IjmTO+b/muvDYD9pVj8U6MMH/3YE=; b=M2fY8poV1sWoCeSoaTcsFyfGbIuHqLkoYxDw33B2Tc0tTm/PAAkQE39z51P3p3ErAO C/kpBDanbFOLnzGWCGXtmCqmFwqdohYGM6D3t+bRx05K+AxchbTRULrkTd9wXA2f9g60 ThdiVTPuiNMyglR1NmpeT3PNnCo/O7G35myF4dS/+b6hoiBzSlNbJlFQAzRS1diXfdFB u/+Z8lL19v1CEkqVV1Qv0vghBhNVBRNxSTqYNGKtY/VSsmXu8gV3fgO40hkMGq0eFRbu 3+VikukAGyvlhD1PFY6AV3i4oZA4XUYZvRZxmfslYAI+WSzSejgUTQoCjV5etyjWK7GP Hhgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NC42xYd9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w68si18604540oia.223.2020.01.20.02.01.21; Mon, 20 Jan 2020 02:01:34 -0800 (PST) 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=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NC42xYd9; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgATKAY (ORCPT + 99 others); Mon, 20 Jan 2020 05:00:24 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44303 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726125AbgATKAX (ORCPT ); Mon, 20 Jan 2020 05:00:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579514422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=A5GcFGtVAQWVAj/IjmTO+b/muvDYD9pVj8U6MMH/3YE=; b=NC42xYd9N+jq7GCvssjVvkbHqA/j/WnlyYgxAEVF7h9/j3qYiSotPBRrY9gxx3yrWoVuDq za/VWA79JsM+qLwof3q2oXq5rd46pALC6v6cq+6lEbIz+A7O4Vk0FIgG56HeY/nKUlDdA7 7ZOvhKymFcat4x43JEepVu8NMs4fq1s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-YPaqEMN3PyiBcHX6c_McOw-1; Mon, 20 Jan 2020 05:00:19 -0500 X-MC-Unique: YPaqEMN3PyiBcHX6c_McOw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39584800590; Mon, 20 Jan 2020 10:00:18 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-106.ams2.redhat.com [10.36.116.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id C398910013A7; Mon, 20 Jan 2020 10:00:14 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 124DB16E36; Mon, 20 Jan 2020 11:00:14 +0100 (CET) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: marmarek@invisiblethingslab.com, Gerd Hoffmann , Bartlomiej Zolnierkiewicz , linux-fbdev@vger.kernel.org (open list:FRAMEBUFFER LAYER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] fbdev: wait for references go away Date: Mon, 20 Jan 2020 11:00:13 +0100 Message-Id: <20200120100014.23488-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Problem: do_unregister_framebuffer() might return before the device is fully cleaned up, due to userspace having a file handle for /dev/fb0 open. Which can result in drm driver not being able to grab resources (and fail initialization) because the firmware framebuffer still holds them. Reportedly plymouth can trigger this. Fix this by trying to wait until all references are gone. Don't wait forever though given that userspace might keep the file handle open. Reported-by: Marek Marczykowski-G=C3=B3recki Signed-off-by: Gerd Hoffmann --- drivers/video/fbdev/core/fbmem.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/= fbmem.c index d04554959ea7..2ea8ac05b065 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -35,6 +35,7 @@ #include #include #include +#include =20 #include =20 @@ -1707,6 +1708,8 @@ static void unlink_framebuffer(struct fb_info *fb_i= nfo) =20 static void do_unregister_framebuffer(struct fb_info *fb_info) { + int limit =3D 100; + unlink_framebuffer(fb_info); if (fb_info->pixmap.addr && (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT)) @@ -1726,6 +1729,10 @@ static void do_unregister_framebuffer(struct fb_in= fo *fb_info) fbcon_fb_unregistered(fb_info); console_unlock(); =20 + /* try wait until all references are gone */ + while (atomic_read(&fb_info->count) > 1 && --limit > 0) + msleep(10); + /* this may free fb info */ put_fb_info(fb_info); } --=20 2.18.1