Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4429924imu; Mon, 7 Jan 2019 23:26:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN44QzUqiygRT6WCLWG6xlxdIcca3wyIBsNfqKundm+Z5Gd+TaOrKEOb5iuXyT7kDzipyLoT X-Received: by 2002:a63:3e05:: with SMTP id l5mr549478pga.96.1546932411055; Mon, 07 Jan 2019 23:26:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546932411; cv=none; d=google.com; s=arc-20160816; b=ov3iq5b/rjm4A/hYM5VXnf1yRJcjjZAGkbPyEWFfA71KAogKOBhQIJHeHE5Q8ciOOs 6j+u6lbA5OjQP6fZeYR2C3ijRpPq8Eb+Joc7Z9d3zKs0Sakt1txks35Y2njJXQT//bCc A7BFJ9330YWf9SHqxAyqp1surGzXV0rA+KW8cSvPi+e/HKf4PZZ91Rp8STSBjwz60BNA roNSffF0b8N/+15ur2rBDc5tunLPbQlrnqMT/vjlaLInCZnc4WRJperoptK5tJWZT9d0 syPg+rNcflNSWVZ4SY22yKTv2GuXUS1yCCW3sa2pBVyUBuqf3EMtVOOL5gxw9n/fiRVw PnYQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bSk+FSxPxS6iMisbvB7H/rsju0PE7UdrYs5P4efdO58=; b=iREKijnNLH5yWVkvpx3CgaWuRSvU15qO7dthIZW8xeT++yE+ze08tfsplHIR7yQeS8 J+8gN5T3+VGXJWp6pUJ1KyijzCjC6EdE0oiJDMg7Tu54T0IzDVywZUBadkzjScczS2iR 3hOmuH8pZIoni7dAhbOfgng9AF7haY4NZ26skdC8iepwkDN/0PI+LeD0TgIQ0GqQsqj/ Ou2+lZnzVJzNJzGKA8YFv570mzrHuilJaJbuNLokVEH1qy3l4ZYWwrRJDL2A5swMpkoF +tIi7bGlgHBf3IghhQ4sBYzizgp+6G+tfNOcg5QZUuh5TNQytls+uaNUtG+lPKFIcbLD Doyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T0ek0Kaw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si5592620pgi.480.2019.01.07.23.26.35; Mon, 07 Jan 2019 23:26:51 -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=@gmail.com header.s=20161025 header.b=T0ek0Kaw; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbfAHHYi (ORCPT + 99 others); Tue, 8 Jan 2019 02:24:38 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38525 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727295AbfAHHYi (ORCPT ); Tue, 8 Jan 2019 02:24:38 -0500 Received: by mail-lj1-f196.google.com with SMTP id c19-v6so2526103lja.5; Mon, 07 Jan 2019 23:24:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bSk+FSxPxS6iMisbvB7H/rsju0PE7UdrYs5P4efdO58=; b=T0ek0KawjaJqyQm3qvMVk4a0QL78wVitE9x6v+Foyv5eEBn34mk9DUcT4XmgQB6Lyp IEvaQObeNNoO5sI+aBHOQpLjQkSuGbZ0Vpn1h29HxdrbnobOGjfYVtp2AprjlnlrsNFd mty5T2s2G1Z48p+s3xsE9y9aTC4tLLyRHUUunaRg2CUfeVrg2u4tudVzNZLd73tNUfJa aBApxo1ioorwxr1R1aUl/U1b5HYNoFuARVmAeQonm2zLmrzY7RxZSM33iPVhE8ZhgiEE TlleZtXva5AEhl2DEM4xOpNz+o+7scqn83wNBvbLQ8vudCyHoCbexcFVv2WmvomQ360M XxlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bSk+FSxPxS6iMisbvB7H/rsju0PE7UdrYs5P4efdO58=; b=W6g1jeWiFHK7obaI4Ei6ZSf0cvGpDVlRO1TsrvRGHSjJ9l7zeThezxVz+pJ5YbotUf Co973a/uW6e4T22q6NDFIuD636zNgQz9eU3z++p5efk1EdWx93k/5EK4W2XUsVi/REhJ dcSj6UX7Zma4Xzy26efuXfmkf1A7L+3wp++ag/9N/fY7SJCAhBVo2ezMI6IpAv456bNI EnWCTJPvGVPl+bW4sK7dm2r3jbR91+EHgl3swekmjvtwS+ii1fWMSPBFnwTqXdThQOw5 XYA046PeQFZ0BHpXvt9kaUTGKhPntuHmmdW8nbuIjaOO77L/M5ZVREU7rmaPVKphMqcQ laUg== X-Gm-Message-State: AJcUukdIcGdbjMUqurB/ippRPXVWkgRN0vr8nXPl9LFtVjm1wHevwGKR YdwFaF6K7wJ9komYkcOrivk= X-Received: by 2002:a2e:29d7:: with SMTP id p84-v6mr398448ljp.12.1546932274768; Mon, 07 Jan 2019 23:24:34 -0800 (PST) Received: from localhost.localdomain (pool-109-191-228-208.is74.ru. [109.191.228.208]) by smtp.gmail.com with ESMTPSA id t144sm12858447lff.53.2019.01.07.23.24.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Jan 2019 23:24:34 -0800 (PST) From: Ivan Mironov To: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , saahriktu , Eugeniy Paltsev , Ivan Mironov , stable@vger.kernel.org Subject: [PATCH v2 1/2] drm/fb-helper: Partially bring back workaround for bugs of SDL 1.2 Date: Tue, 8 Jan 2019 12:23:52 +0500 Message-Id: <20190108072353.28078-2-mironov.ivan@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190108072353.28078-1-mironov.ivan@gmail.com> References: <20190108072353.28078-1-mironov.ivan@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SDL 1.2 sets all fields related to the pixel format to zero in some cases[1]. Prior to commit db05c48197759 ("drm: fb-helper: Reject all pixel format changing requests"), there was an unintentional workaround for this that existed for more than a decade. First in device-specific DRM drivers, then here in drm_fb_helper.c. Previous code containing this workaround just ignores pixel format fields from userspace code. Not a good thing either, as this way, driver may silently use pixel format different from what client actually requested, and this in turn will lead to displaying garbage on the screen. I think that returning EINVAL to userspace in this particular case is the right option, so I decided to left code from problematic commit untouched instead of just reverting it entirely. Here is the steps required to reproduce this problem exactly: 1) Compile fceux[2] with SDL 1.2.15 and without GTK or OpenGL support. SDL should be compiled with fbdev support (which is on by default). 2) Create /etc/fb.modes with following contents (values seems not used, and just required to trigger problematic code in SDL): mode "test" geometry 1 1 1 1 1 timings 1 1 1 1 1 1 1 endmode 3) Create ~/.fceux/fceux.cfg with following contents: SDL.Hotkeys.Quit = 27 SDL.DoubleBuffering = 1 4) Ensure that screen resolution is at least 1280x960 (e.g. append "video=Virtual-1:1280x960-32" to the kernel cmdline for qemu/QXL). 5) Try to run fceux on VT with some ROM file[3]: # ./fceux color_test.nes [1] SDL 1.2.15 source code, src/video/fbcon/SDL_fbvideo.c, FB_SetVideoMode() [2] http://www.fceux.com [3] Example ROM: https://github.com/bokuweb/rustynes/blob/master/roms/color_test.nes Reported-by: saahriktu Suggested-by: saahriktu Cc: stable@vger.kernel.org Fixes: db05c48197759 ("drm: fb-helper: Reject all pixel format changing requests") Signed-off-by: Ivan Mironov --- drivers/gpu/drm/drm_fb_helper.c | 142 ++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 53 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index d3af098b0922..ed7e91423258 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1621,6 +1621,64 @@ static bool drm_fb_pixel_format_equal(const struct fb_var_screeninfo *var_1, var_1->transp.msb_right == var_2->transp.msb_right; } +static void drm_fb_helper_fill_pixel_fmt(struct fb_var_screeninfo *var, + u8 depth) +{ + switch (depth) { + case 8: + var->red.offset = 0; + var->green.offset = 0; + var->blue.offset = 0; + var->red.length = 8; /* 8bit DAC */ + var->green.length = 8; + var->blue.length = 8; + var->transp.offset = 0; + var->transp.length = 0; + break; + case 15: + var->red.offset = 10; + var->green.offset = 5; + var->blue.offset = 0; + var->red.length = 5; + var->green.length = 5; + var->blue.length = 5; + var->transp.offset = 15; + var->transp.length = 1; + break; + case 16: + var->red.offset = 11; + var->green.offset = 5; + var->blue.offset = 0; + var->red.length = 5; + var->green.length = 6; + var->blue.length = 5; + var->transp.offset = 0; + break; + case 24: + var->red.offset = 16; + var->green.offset = 8; + var->blue.offset = 0; + var->red.length = 8; + var->green.length = 8; + var->blue.length = 8; + var->transp.offset = 0; + var->transp.length = 0; + break; + case 32: + var->red.offset = 16; + var->green.offset = 8; + var->blue.offset = 0; + var->red.length = 8; + var->green.length = 8; + var->blue.length = 8; + var->transp.offset = 24; + var->transp.length = 8; + break; + default: + break; + } +} + /** * drm_fb_helper_check_var - implementation for &fb_ops.fb_check_var * @var: screeninfo to check @@ -1654,6 +1712,36 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var, return -EINVAL; } + /* + * Workaround for SDL 1.2, which is known to be setting all pixel format + * fields values to zero in some cases. We treat this situation as a + * kind of "use some reasonable autodetected values". + */ + if (!var->red.offset && !var->green.offset && + !var->blue.offset && !var->transp.offset && + !var->red.length && !var->green.length && + !var->blue.length && !var->transp.length && + !var->red.msb_right && !var->green.msb_right && + !var->blue.msb_right && !var->transp.msb_right) { + /* + * There is no way to guess the right value for depth when + * bits_per_pixel is 16 or 32. Instead of restoring the + * behaviour previously introduced here by commit 785b93ef8c309, + * we decided to just use the current depth and do not perform + * any guessing. + * + * Also, if requested bits_per_pixel differs from current, + * the next call to drm_fb_pixel_format_equal() will fail + * resulting in EINVAL error from ioctl(). + * + * However, this still leaves the theoretical possibility of + * situation when userspace app requests different pixel format + * and ioctl() call silently succeeds. Garbage will be displayed + * in this case. + */ + drm_fb_helper_fill_pixel_fmt(var, fb->format->depth); + } + /* * drm fbdev emulation doesn't support changing the pixel format at all, * so reject all pixel format changing requests. @@ -1967,59 +2055,7 @@ void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helpe info->var.yoffset = 0; info->var.activate = FB_ACTIVATE_NOW; - switch (fb->format->depth) { - case 8: - info->var.red.offset = 0; - info->var.green.offset = 0; - info->var.blue.offset = 0; - info->var.red.length = 8; /* 8bit DAC */ - info->var.green.length = 8; - info->var.blue.length = 8; - info->var.transp.offset = 0; - info->var.transp.length = 0; - break; - case 15: - info->var.red.offset = 10; - info->var.green.offset = 5; - info->var.blue.offset = 0; - info->var.red.length = 5; - info->var.green.length = 5; - info->var.blue.length = 5; - info->var.transp.offset = 15; - info->var.transp.length = 1; - break; - case 16: - info->var.red.offset = 11; - info->var.green.offset = 5; - info->var.blue.offset = 0; - info->var.red.length = 5; - info->var.green.length = 6; - info->var.blue.length = 5; - info->var.transp.offset = 0; - break; - case 24: - info->var.red.offset = 16; - info->var.green.offset = 8; - info->var.blue.offset = 0; - info->var.red.length = 8; - info->var.green.length = 8; - info->var.blue.length = 8; - info->var.transp.offset = 0; - info->var.transp.length = 0; - break; - case 32: - info->var.red.offset = 16; - info->var.green.offset = 8; - info->var.blue.offset = 0; - info->var.red.length = 8; - info->var.green.length = 8; - info->var.blue.length = 8; - info->var.transp.offset = 24; - info->var.transp.length = 8; - break; - default: - break; - } + drm_fb_helper_fill_pixel_fmt(&info->var, fb->format->depth); info->var.xres = fb_width; info->var.yres = fb_height; -- 2.20.1