Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2169739ybm; Thu, 23 May 2019 12:30:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4tPQwz9LQIWmwzIdp0wl15B925sZUTYTr7inRyxVumHNGprp8aphOrilrzqly84Z+uPqz X-Received: by 2002:a17:902:8f8d:: with SMTP id z13mr12618410plo.166.1558639832968; Thu, 23 May 2019 12:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558639832; cv=none; d=google.com; s=arc-20160816; b=d9lP7xjoEHjr0U+7A/CsyMScMTfSHZtogcxMJOxR0mVDrgH9/QwfZB4ggKQruVYJnS UGhRbMOmppxATOAwcJAKPZyWVGtPSy/GFW2V7FMRTdnSvmgYZi/MmUWR/ngSwB+slkAu ix52wzWyXfjDNNcjxspxWVV4DWzOqFFDdwlOmhiDUYm7GHG+munlwuMHXiKK9mu5AAVC gTsW7wMiw8rfKlFEX9HFz3avHyhw07FJmU344fA7Z5AbdRAYJ889cCB8qyhm2arcK1XA L+pKEMOOUaFNc4C7dpA9ODjip9bknvV6ek0akquDhZSgt0ERlItOeC8cSdpFhD4zZ/6v 96hA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yRceaCtfmqsEe1XiZHe/4LA6nxMDIX2D+sL/DMKVSlI=; b=w0GFdtMIIzhZq6/lA2AnMHnwJM8YZfXYEtmgnfcvzS9uRdLj1FKBmH0EFApyO6XbPt mBgqSxEC+q/LrkNh4/JCFn1qrqX4u6Ls6sYvgz3Ac4iRPij9FjBqUOjg3DbMna6/UyVX h85NIcVmunM8mMi9c2jDOynhBnd7Xsd0Zu5V7ArNaXTd6RkH5B9wKO18d3GbDBBx1b4W ysryEzmRX5KUQ2E+I946AOwcJMosbDyEEdTc7w1ct++SG170mFXQPowDu/CQdIw2dQ6v Qo2XgcsW3k2jXEGghuHn1d4QFgIwi1OzMrCbQQPQG4aseTIQFNx3qVh1CnNYkLwq4cxL HztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="z9/ojJAz"; 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 h7si510428pgk.379.2019.05.23.12.30.16; Thu, 23 May 2019 12:30:32 -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=pass header.i=@kernel.org header.s=default header.b="z9/ojJAz"; 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 S2391889AbfEWT3K (ORCPT + 99 others); Thu, 23 May 2019 15:29:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:42116 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391416AbfEWT3I (ORCPT ); Thu, 23 May 2019 15:29:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F4B3217D7; Thu, 23 May 2019 19:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639748; bh=eGjSZCeMlhs3mCdvp+rkNdXCGOMD6kWJsci1m1TlAcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z9/ojJAzgr+icF4P/kgbUQrtYGistxrAkr5InlcJPWHgrX6bis4GnvxfH7M3QSRjX V9JlsQLJ/FSJEhD4ZJSX1gIw9C0u3zMigGstnm7GLY8Iy8AB84rXBRIf/YCGHTX/8n SJ8z3cQbgcRC+5y9aEwC4N4Jfb5HXIo/Fe9uLFbk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Bernie Thompson , Ladislav Michl , Bartlomiej Zolnierkiewicz Subject: [PATCH 5.1 064/122] udlfb: fix sleeping inside spinlock Date: Thu, 23 May 2019 21:06:26 +0200 Message-Id: <20190523181713.201724775@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181705.091418060@linuxfoundation.org> References: <20190523181705.091418060@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 6b11f9d8433b471fdd3ebed232b43a4b723be6ff upstream. If a framebuffer device is used as a console, the rendering calls (copyarea, fillrect, imageblit) may be done with the console spinlock held. On udlfb, these function call dlfb_handle_damage that takes a blocking semaphore before acquiring an URB. In order to fix the bug, this patch changes the calls copyarea, fillrect and imageblit to offload USB work to a workqueue. A side effect of this patch is 3x improvement in console scrolling speed because the device doesn't have to be updated after each copyarea call. Signed-off-by: Mikulas Patocka Cc: Bernie Thompson Cc: Ladislav Michl Cc: Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/udlfb.c | 56 +++++++++++++++++++++++++++++++++++++++++--- include/video/udlfb.h | 6 ++++ 2 files changed, 59 insertions(+), 3 deletions(-) --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -657,6 +657,50 @@ error: return 0; } +static void dlfb_init_damage(struct dlfb_data *dlfb) +{ + dlfb->damage_x = INT_MAX; + dlfb->damage_x2 = 0; + dlfb->damage_y = INT_MAX; + dlfb->damage_y2 = 0; +} + +static void dlfb_damage_work(struct work_struct *w) +{ + struct dlfb_data *dlfb = container_of(w, struct dlfb_data, damage_work); + int x, x2, y, y2; + + spin_lock_irq(&dlfb->damage_lock); + x = dlfb->damage_x; + x2 = dlfb->damage_x2; + y = dlfb->damage_y; + y2 = dlfb->damage_y2; + dlfb_init_damage(dlfb); + spin_unlock_irq(&dlfb->damage_lock); + + if (x < x2 && y < y2) + dlfb_handle_damage(dlfb, x, y, x2 - x, y2 - y); +} + +static void dlfb_offload_damage(struct dlfb_data *dlfb, int x, int y, int width, int height) +{ + unsigned long flags; + int x2 = x + width; + int y2 = y + height; + + if (x >= x2 || y >= y2) + return; + + spin_lock_irqsave(&dlfb->damage_lock, flags); + dlfb->damage_x = min(x, dlfb->damage_x); + dlfb->damage_x2 = max(x2, dlfb->damage_x2); + dlfb->damage_y = min(y, dlfb->damage_y); + dlfb->damage_y2 = max(y2, dlfb->damage_y2); + spin_unlock_irqrestore(&dlfb->damage_lock, flags); + + schedule_work(&dlfb->damage_work); +} + /* * Path triggered by usermode clients who write to filesystem * e.g. cat filename > /dev/fb1 @@ -693,7 +737,7 @@ static void dlfb_ops_copyarea(struct fb_ sys_copyarea(info, area); - dlfb_handle_damage(dlfb, area->dx, area->dy, + dlfb_offload_damage(dlfb, area->dx, area->dy, area->width, area->height); } @@ -704,7 +748,7 @@ static void dlfb_ops_imageblit(struct fb sys_imageblit(info, image); - dlfb_handle_damage(dlfb, image->dx, image->dy, + dlfb_offload_damage(dlfb, image->dx, image->dy, image->width, image->height); } @@ -715,7 +759,7 @@ static void dlfb_ops_fillrect(struct fb_ sys_fillrect(info, rect); - dlfb_handle_damage(dlfb, rect->dx, rect->dy, rect->width, + dlfb_offload_damage(dlfb, rect->dx, rect->dy, rect->width, rect->height); } @@ -940,6 +984,8 @@ static void dlfb_ops_destroy(struct fb_i { struct dlfb_data *dlfb = info->par; + cancel_work_sync(&dlfb->damage_work); + if (info->cmap.len != 0) fb_dealloc_cmap(&info->cmap); if (info->monspecs.modedb) @@ -1636,6 +1682,10 @@ static int dlfb_usb_probe(struct usb_int dlfb->ops = dlfb_ops; info->fbops = &dlfb->ops; + dlfb_init_damage(dlfb); + spin_lock_init(&dlfb->damage_lock); + INIT_WORK(&dlfb->damage_work, dlfb_damage_work); + INIT_LIST_HEAD(&info->modelist); if (!dlfb_alloc_urb_list(dlfb, WRITES_IN_FLIGHT, MAX_TRANSFER)) { --- a/include/video/udlfb.h +++ b/include/video/udlfb.h @@ -48,6 +48,12 @@ struct dlfb_data { int base8; u32 pseudo_palette[256]; int blank_mode; /*one of FB_BLANK_ */ + int damage_x; + int damage_y; + int damage_x2; + int damage_y2; + spinlock_t damage_lock; + struct work_struct damage_work; struct fb_ops ops; /* blit-only rendering path metrics, exposed through sysfs */ atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */