Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4419763pxa; Mon, 10 Aug 2020 08:39:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZbrR+EMSKcF7iYRcaQcuyfCuRfcvjAZzUQpNUcisNdmRU/pURJXC2T7v8aJNkiOuNF6wl X-Received: by 2002:a17:906:e115:: with SMTP id gj21mr21603409ejb.505.1597073980519; Mon, 10 Aug 2020 08:39:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073980; cv=none; d=google.com; s=arc-20160816; b=hSP91RYLku5Iku/tm+x//b7JEFUacsNipklomEkLKO1k2TbvWMfh8l3ueL8p8Zjjn3 Wdi9yrOP4i0VOt7JJPMYOwDJYGVyBC63KyKUzZhMB8ED9GHddlU/0pxnlEFCpfVNAg7l IKytRGJBdJBZBvGZf7tv2iMs8e5JP67dPYlrQp09iMx39F9s1FdmnpYGDnmnDVNSPpZH xzLNCUA1bhWRiih82uS/NEBZOrmHzOBuFo7g/YvrjA0XmbgVLLcJtPj5hgKQDPltw5A5 FHr07WlLdzpr0MTNvr2hVoJJWuXjaxxWxha2A9t8t1l6CbbOrv00lCR/QPzqMxTQvvqz rwRA== 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=bwcooPA8Oz/pLZzoEf4sDlEoT1kNOWx2TMUOw+RliTI=; b=KrrWBdRj1rZzQLns925zgC3fXn5E4+Sym7+RPfODQDH2zgR5cRSZNwXUwZ4NQ9TAZH CYK3fCECmdD5D16Al7oKA3Fknn086faaxI/C/P9Z8IA3B2ovs0iV1yciQzaA8BdivvUv i5v1LrZWKCOYfVuNsNOqsVzMsceJ2oSN2IeTpBM9k4qoWcMJS3TLi4dCFFCDeslFL7xe MH8dTd8BouEld9a0APdzNxgmDqWdg34LELfZmBs41NBEFiSrhSPEBQTaMaYUbCBgjHoJ zPGjjdj0BD8idixAibMO0vMEne6ISdFGpTcwNRhuZhWyvKqHxIL8GYhAI84HZC8e+l8a IrEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TmKUCHCm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si11003718edv.40.2020.08.10.08.39.17; Mon, 10 Aug 2020 08:39:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TmKUCHCm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728077AbgHJPgk (ORCPT + 99 others); Mon, 10 Aug 2020 11:36:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:33172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728718AbgHJP1S (ORCPT ); Mon, 10 Aug 2020 11:27:18 -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 7E49722BF3; Mon, 10 Aug 2020 15:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073238; bh=OEBUnwPDQFvaeUZp01qeNkT2HHlvDwLzUY81pbDigtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TmKUCHCm5Yhu2wXcr/88E8oK7WdGJYnulrGeWDM9FQag66gGBKlEIe1v7o3luRgtE YJmkPUzk45cl+xgOe/N9pH1Z/dqR2ooeUMLLNzSA9V5s74F0TZyPVoN5D8RmrCQREV L2wqltEOz6pa4dPlqd2R/acycIvgVwUUmilNasAg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sam Ravnborg , Mark Cave-Ayland , kernel test robot , Daniel Vetter , Thomas Zimmermann , Gerd Hoffmann , "David S. Miller" , sparclinux@vger.kernel.org, Sasha Levin Subject: [PATCH 5.4 35/67] drm/drm_fb_helper: fix fbdev with sparc64 Date: Mon, 10 Aug 2020 17:21:22 +0200 Message-Id: <20200810151811.171538668@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151809.438685785@linuxfoundation.org> References: <20200810151809.438685785@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: Sam Ravnborg [ Upstream commit 2a1658bf922ffd9b7907e270a7d9cdc9643fc45d ] Recent kernels have been reported to panic using the bochs_drm framebuffer under qemu-system-sparc64 which was bisected to commit 7a0483ac4ffc ("drm/bochs: switch to generic drm fbdev emulation"). The backtrace indicates that the shadow framebuffer copy in drm_fb_helper_dirty_blit_real() is trying to access the real framebuffer using a virtual address rather than use an IO access typically implemented using a physical (ASI_PHYS) access on SPARC. The fix is to replace the memcpy with memcpy_toio() from io.h. memcpy_toio() uses writeb() where the original fbdev code used sbus_memcpy_toio(). The latter uses sbus_writeb(). The difference between writeb() and sbus_memcpy_toio() is that writeb() writes bytes in little-endian, where sbus_writeb() writes bytes in big-endian. As endian does not matter for byte writes they are the same. So we can safely use memcpy_toio() here. Note that this only fixes bochs, in general fbdev helpers still have issues with mixing up system memory and __iomem space. Fixing that will require a lot more work. v3: - Improved changelog (Daniel) - Added FIXME to fbdev_use_iomem (Daniel) v2: - Added missing __iomem cast (kernel test robot) - Made changelog readable and fix typos (Mark) - Add flag to select iomem - and set it in the bochs driver Signed-off-by: Sam Ravnborg Reported-by: Mark Cave-Ayland Reported-by: kernel test robot Tested-by: Mark Cave-Ayland Reviewed-by: Daniel Vetter Cc: Mark Cave-Ayland Cc: Thomas Zimmermann Cc: Gerd Hoffmann Cc: "David S. Miller" Cc: sparclinux@vger.kernel.org Link: https://patchwork.freedesktop.org/patch/msgid/20200709193016.291267-1-sam@ravnborg.org Link: https://patchwork.freedesktop.org/patch/msgid/20200725191012.GA434957@ravnborg.org Signed-off-by: Sasha Levin --- drivers/gpu/drm/bochs/bochs_kms.c | 1 + drivers/gpu/drm/drm_fb_helper.c | 6 +++++- include/drm/drm_mode_config.h | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c index 02a9c1ed165bb..fa50ab2523d4b 100644 --- a/drivers/gpu/drm/bochs/bochs_kms.c +++ b/drivers/gpu/drm/bochs/bochs_kms.c @@ -194,6 +194,7 @@ int bochs_kms_init(struct bochs_device *bochs) bochs->dev->mode_config.preferred_depth = 24; bochs->dev->mode_config.prefer_shadow = 0; bochs->dev->mode_config.prefer_shadow_fbdev = 1; + bochs->dev->mode_config.fbdev_use_iomem = true; bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; bochs->dev->mode_config.funcs = &bochs_mode_funcs; diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 8d193a58363d4..6b8502bcf0fd3 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -390,7 +390,11 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, unsigned int y; for (y = clip->y1; y < clip->y2; y++) { - memcpy(dst, src, len); + if (!fb_helper->dev->mode_config.fbdev_use_iomem) + memcpy(dst, src, len); + else + memcpy_toio((void __iomem *)dst, src, len); + src += fb->pitches[0]; dst += fb->pitches[0]; } diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index 3bcbe30339f04..198b9d0600081 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -865,6 +865,18 @@ struct drm_mode_config { */ bool prefer_shadow_fbdev; + /** + * @fbdev_use_iomem: + * + * Set to true if framebuffer reside in iomem. + * When set to true memcpy_toio() is used when copying the framebuffer in + * drm_fb_helper.drm_fb_helper_dirty_blit_real(). + * + * FIXME: This should be replaced with a per-mapping is_iomem + * flag (like ttm does), and then used everywhere in fbdev code. + */ + bool fbdev_use_iomem; + /** * @quirk_addfb_prefer_xbgr_30bpp: * -- 2.25.1