Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2175701ybm; Thu, 23 May 2019 12:36:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdiB4bq8ExW7eiBqcAbpO3mcoXCqaTQStYv8ZckKxP6Eduhw9eht0cYz24WNJ7IdiV0Yvh X-Received: by 2002:a62:164f:: with SMTP id 76mr108196494pfw.172.1558640169452; Thu, 23 May 2019 12:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640169; cv=none; d=google.com; s=arc-20160816; b=TO1RZ/IX2cFDwimy0qDA2M6GPc2cWVC7cIPTAlVDHIenVs1O1W/Tq9Jih560yHcehu i07hushRgBUTauEOyRPMsyu+9OeZCSA1/XRXCbiAK4VxO8n+ddZBLy+PbmJHTeV2AfOL I3mfOfk3LC5PkiyJepoaGjWxkSJLLuWEZsgYO45CcnA/tD8e8E/82FpyGXUUZPZRkcR6 Dip1KluNSmacC6vvLq9fyAjJovtJADVGjpLPoNaxBDrCUzstFCBF2Z2+bjFABUo65Mke sl5IGKFMb6jKGuJSVU4d30XSuyaoZqtwGRKoEEfC6CMSEO2CD0gf0AYRgQmgfoIQY7fQ ITTg== 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=drPefTSFOu9S/xPJlj+e2D7ar5bwNc7mDRntlIyhmoI=; b=Ur7fMy4cunOCpx3+RYpjjSjTsJDIyicthFFW46LbHmyL7bUbtbn+Ndken6eX2ofZ4x maHLVQyqCi2H7rSO+2BpU71jtlV5D+5v9T7F/vtOnCbHAwB8WARLsLFXIs0iEb/x+uWS 6myb/w1c/dFqG9VPa9xIxBL36gy5tCmWC8AvUeXaDgWfubLTOXVlSeduTSIXJtoQ7C7v ermOJqjr5g23ZGmcm2geqWjT40mzY0WCkP8KPprC5lRnF7QWmc4vaFx31MlFXbcNcQt1 6IYY8AxinLyPMu1b8hkVmSG2c6qEbkanTzMRtzDKLMIDYOpI+D0RGyRZfqxv+dr2j2Mo LmDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bShqE1UD; 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 q16si402622pjc.23.2019.05.23.12.35.54; Thu, 23 May 2019 12:36:09 -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=bShqE1UD; 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 S2391900AbfEWT3N (ORCPT + 99 others); Thu, 23 May 2019 15:29:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:42190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391891AbfEWT3L (ORCPT ); Thu, 23 May 2019 15:29:11 -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 38079217D9; Thu, 23 May 2019 19:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639750; bh=a9UcbVbIAa9yFWsS81lStfkrnBa1VMhlC8V7xi8PUFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bShqE1UDZEsQnsUeaGDTzlwbZdarA44ejH2A5Ih9UDjukf7p9pR7n2SzcpEOXDkT/ 6NZSTbdtvMD7aQWZr/6L3dSwGkogx4agmllANOPXarqyczi+bYUIaUzAAD7DYJy+ML q9f/veXtf0BBxGMR+l3x8jhUOngBhAUSHpLRQQpc= 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 065/122] udlfb: introduce a rendering mutex Date: Thu, 23 May 2019 21:06:27 +0200 Message-Id: <20190523181713.287323463@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 babc250e278eac7b0e671bdaedf833759b43bb78 upstream. Rendering calls may be done simultaneously from the workqueue, dlfb_ops_write, dlfb_ops_ioctl, dlfb_ops_set_par and dlfb_dpy_deferred_io. The code is robust enough so that it won't crash on concurrent rendering. However, concurrent rendering may cause display corruption if the same pixel is simultaneously being rendered. In order to avoid this corruption, this patch adds a mutex around the rendering calls. Signed-off-by: Mikulas Patocka Cc: Bernie Thompson Cc: Ladislav Michl Cc: [b.zolnierkie: replace "dlfb:" with "uldfb:" in the patch summary] Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/udlfb.c | 41 ++++++++++++++++++++++++++++++----------- include/video/udlfb.h | 1 + 2 files changed, 31 insertions(+), 11 deletions(-) --- a/drivers/video/fbdev/udlfb.c +++ b/drivers/video/fbdev/udlfb.c @@ -596,7 +596,7 @@ static int dlfb_render_hline(struct dlfb static int dlfb_handle_damage(struct dlfb_data *dlfb, int x, int y, int width, int height) { - int i; + int i, ret; char *cmd; cycles_t start_cycles, end_cycles; int bytes_sent = 0; @@ -606,21 +606,29 @@ static int dlfb_handle_damage(struct dlf start_cycles = get_cycles(); + mutex_lock(&dlfb->render_mutex); + aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long)); width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long)); x = aligned_x; if ((width <= 0) || (x + width > dlfb->info->var.xres) || - (y + height > dlfb->info->var.yres)) - return -EINVAL; + (y + height > dlfb->info->var.yres)) { + ret = -EINVAL; + goto unlock_ret; + } - if (!atomic_read(&dlfb->usb_active)) - return 0; + if (!atomic_read(&dlfb->usb_active)) { + ret = 0; + goto unlock_ret; + } urb = dlfb_get_urb(dlfb); - if (!urb) - return 0; + if (!urb) { + ret = 0; + goto unlock_ret; + } cmd = urb->transfer_buffer; for (i = y; i < y + height ; i++) { @@ -654,7 +662,11 @@ error: >> 10)), /* Kcycles */ &dlfb->cpu_kcycles_used); - return 0; + ret = 0; + +unlock_ret: + mutex_unlock(&dlfb->render_mutex); + return ret; } static void dlfb_init_damage(struct dlfb_data *dlfb) @@ -782,17 +794,19 @@ static void dlfb_dpy_deferred_io(struct int bytes_identical = 0; int bytes_rendered = 0; + mutex_lock(&dlfb->render_mutex); + if (!fb_defio) - return; + goto unlock_ret; if (!atomic_read(&dlfb->usb_active)) - return; + goto unlock_ret; start_cycles = get_cycles(); urb = dlfb_get_urb(dlfb); if (!urb) - return; + goto unlock_ret; cmd = urb->transfer_buffer; @@ -825,6 +839,8 @@ error: atomic_add(((unsigned int) ((end_cycles - start_cycles) >> 10)), /* Kcycles */ &dlfb->cpu_kcycles_used); +unlock_ret: + mutex_unlock(&dlfb->render_mutex); } static int dlfb_get_edid(struct dlfb_data *dlfb, char *edid, int len) @@ -986,6 +1002,8 @@ static void dlfb_ops_destroy(struct fb_i cancel_work_sync(&dlfb->damage_work); + mutex_destroy(&dlfb->render_mutex); + if (info->cmap.len != 0) fb_dealloc_cmap(&info->cmap); if (info->monspecs.modedb) @@ -1682,6 +1700,7 @@ static int dlfb_usb_probe(struct usb_int dlfb->ops = dlfb_ops; info->fbops = &dlfb->ops; + mutex_init(&dlfb->render_mutex); dlfb_init_damage(dlfb); spin_lock_init(&dlfb->damage_lock); INIT_WORK(&dlfb->damage_work, dlfb_damage_work); --- a/include/video/udlfb.h +++ b/include/video/udlfb.h @@ -48,6 +48,7 @@ struct dlfb_data { int base8; u32 pseudo_palette[256]; int blank_mode; /*one of FB_BLANK_ */ + struct mutex render_mutex; int damage_x; int damage_y; int damage_x2;