From patchwork Thu May 16 15:46:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 10946833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AA9D112C for ; Thu, 16 May 2019 15:49:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 399E726AE3 for ; Thu, 16 May 2019 15:49:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D51C289D7; Thu, 16 May 2019 15:49:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C649F26AE3 for ; Thu, 16 May 2019 15:49:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hRIbz-0004zH-Ha; Thu, 16 May 2019 15:48:03 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hRIby-0004zB-Te for xen-devel@lists.xenproject.org; Thu, 16 May 2019 15:48:02 +0000 X-Inumbo-ID: fbe3ef72-77f1-11e9-9a75-3354952b17af Received: from new3-smtp.messagingengine.com (unknown [66.111.4.229]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id fbe3ef72-77f1-11e9-9a75-3354952b17af; Thu, 16 May 2019 15:48:00 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.nyi.internal (Postfix) with ESMTP id 6E370274D7; Thu, 16 May 2019 11:48:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 16 May 2019 11:48:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=pP7V3G/n2VfZwMSdhyeEn4iR7LTgvgvMvcTGMyE7B S0=; b=bmpN+t0zWmFXlwtZCvZj7MqrMODLUqx4gtv7oeei6Uguqca464Ie9YBA5 9IP5Fd5akFhkVJ9H5B7icM8p/M1IP0BW9j8pscIJFVCEJ7K3lvLb/zidi0uPb7Yj 5LfTJvyb21suqeIYTjAsECrks17mVDoDjnbwMALOqIvcjIJV2siVRJskhI0Qka1B ck/Sa1C3lC96lRLj0LBEFagAVfhMiXSL3XA9nGUsQuOlOWK3CcqLa5LY9IqjHiDQ HXaxmo6YnCc8NmVbUiAF+1x1jODEx/EpKKLNbUgIARDpPQNUzHAxuGKoc6nY8Ljx 3yQZC+dA1jpx9sG3JZA0Gb2ABWlXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddruddttddgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfgggtohfgsehtkeertdertdejnecuhfhrohhmpeforghr vghkucforghrtgiihihkohifshhkihdqifpkrhgvtghkihcuoehmrghrmhgrrhgvkhesih hnvhhishhisghlvghthhhinhhgshhlrggsrdgtohhmqeenucffohhmrghinhepughomhdt rdhinhhfohenucfkphepledurdeihedrfeegrdeffeenucfrrghrrghmpehmrghilhhfrh homhepmhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomhen ucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from localhost.localdomain (ip5b412221.dynamic.kabel-deutschland.de [91.65.34.33]) by mail.messagingengine.com (Postfix) with ESMTPA id 6D26B103D2; Thu, 16 May 2019 11:47:58 -0400 (EDT) From: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xenproject.org Date: Thu, 16 May 2019 17:46:55 +0200 Message-Id: <20190516154655.20162-1-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190516154513.GS1502@mail-itl> References: <20190516154513.GS1502@mail-itl> MIME-Version: 1.0 Organization: Invisible Things Lab Subject: [Xen-devel] [PATCH v4] xen: fix handling framebuffer located above 4GB X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , =?utf-8?q?Marek_Marczykowski-G?= =?utf-8?q?=C3=B3recki?= , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On some machines (for example Thinkpad P52), UEFI GOP reports framebuffer located above 4GB (0x4000000000 on that machine). This address does not fit in {xen,dom0}_vga_console_info.u.vesa_lfb.lfb_base field, which is 32bit. The overflow here cause all kind of memory corruption when anything tries to write something on the screen, starting with zeroing the whole framebuffer in vesa_init(). Fix this similar to how it's done in Linux: add ext_lfb_base field at the end of the structure, to hold upper 32bits of the address. Since the field is added at the end of the structure, it will work with older Linux versions too (other than using possibly truncated address - no worse than without this change). Thanks to ABI containing size of the structure (start_info.console.dom0.info_size), Linux can detect when this field is present and use it appropriately then. Since this change public interface and use __XEN_INTERFACE_VERSION__, bump __XEN_LATEST_INTERFACE_VERSION__. Note: if/when backporting this change to Xen <= 4.12, #if in xen.h needs to be extended with " || defined(__XEN__)". Signed-off-by: Marek Marczykowski-Górecki Reviewed-by: Jan Beulich --- Changes in v2: - guard ext_lfb_base with #if __XEN_INTERFACE_VERSION__, but always include whe building Xen itself - add a helper function for lfb_base Changes in v3: - add padding field - add parentheses around << - unwrap format string per coding style, restore 0x - drop #if defined(__XEN__) needed only in backport - bump __XEN_LATEST_INTERFACE_VERSION__ Changes in v4: - fix parentheses - fix padding --- xen/arch/x86/efi/efi-boot.h | 1 + xen/drivers/video/vesa.c | 14 +++++++++----- xen/include/public/xen-compat.h | 2 +- xen/include/public/xen.h | 5 +++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 5789d2cb70..7a13a30bc0 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -550,6 +550,7 @@ static void __init efi_arch_video_init(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, vga_console_info.u.vesa_lfb.bytes_per_line = (mode_info->PixelsPerScanLine * bpp + 7) >> 3; vga_console_info.u.vesa_lfb.lfb_base = gop->Mode->FrameBufferBase; + vga_console_info.u.vesa_lfb.ext_lfb_base = gop->Mode->FrameBufferBase >> 32; vga_console_info.u.vesa_lfb.lfb_size = (gop->Mode->FrameBufferSize + 0xffff) >> 16; } diff --git a/xen/drivers/video/vesa.c b/xen/drivers/video/vesa.c index 26d4962b0e..fd2cb1312d 100644 --- a/xen/drivers/video/vesa.c +++ b/xen/drivers/video/vesa.c @@ -40,6 +40,11 @@ static int __init parse_font_height(const char *s) } custom_param("font", parse_font_height); +static inline paddr_t lfb_base(void) +{ + return ((paddr_t)vlfb_info.ext_lfb_base << 32) | vlfb_info.lfb_base; +} + void __init vesa_early_init(void) { unsigned int vram_vmode; @@ -97,15 +102,14 @@ void __init vesa_init(void) lfbp.text_columns = vlfb_info.width / font->width; lfbp.text_rows = vlfb_info.height / font->height; - lfbp.lfb = lfb = ioremap(vlfb_info.lfb_base, vram_remap); + lfbp.lfb = lfb = ioremap(lfb_base(), vram_remap); if ( !lfb ) return; memset(lfb, 0, vram_remap); - printk(XENLOG_INFO "vesafb: framebuffer at %#x, mapped to 0x%p, " - "using %uk, total %uk\n", - vlfb_info.lfb_base, lfb, + printk(XENLOG_INFO "vesafb: framebuffer at 0x%" PRIpaddr ", mapped to 0x%p, using %uk, total %uk\n", + lfb_base(), lfb, vram_remap >> 10, vram_total >> 10); printk(XENLOG_INFO "vesafb: mode is %dx%dx%u, linelength=%d, font %ux%u\n", vlfb_info.width, vlfb_info.height, @@ -167,7 +171,7 @@ void __init vesa_mtrr_init(void) /* Try and find a power of two to add */ do { - rc = mtrr_add(vlfb_info.lfb_base, size_total, type, 1); + rc = mtrr_add(lfb_base(), size_total, type, 1); size_total >>= 1; } while ( (size_total >= PAGE_SIZE) && (rc == -EINVAL) ); } diff --git a/xen/include/public/xen-compat.h b/xen/include/public/xen-compat.h index 6fabca1889..6708132394 100644 --- a/xen/include/public/xen-compat.h +++ b/xen/include/public/xen-compat.h @@ -27,7 +27,7 @@ #ifndef __XEN_PUBLIC_XEN_COMPAT_H__ #define __XEN_PUBLIC_XEN_COMPAT_H__ -#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040a00 +#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040d00 #if defined(__XEN__) || defined(__XEN_TOOLS__) /* Xen is built with matching headers and implements the latest interface. */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index ccdffc0ad1..cb2917e74b 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -922,6 +922,11 @@ typedef struct dom0_vga_console_info { uint32_t gbl_caps; /* Mode attributes (offset 0x0, VESA command 0x4f01). */ uint16_t mode_attrs; + uint16_t pad; +#endif +#if __XEN_INTERFACE_VERSION__ >= 0x00040d00 + /* high 32 bits of lfb_base */ + uint32_t ext_lfb_base; #endif } vesa_lfb; } u;