Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1351568rwe; Sat, 27 Aug 2022 06:20:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR49pVJMnZgbG10cAP3g0XOLrYx0Ml5x+6HExQ9Em9QAGTL3UQ8Bfs4ASTea7HvRmZ9fIJaP X-Received: by 2002:a17:906:bc87:b0:73d:bacd:84e2 with SMTP id lv7-20020a170906bc8700b0073dbacd84e2mr7670424ejb.494.1661606408660; Sat, 27 Aug 2022 06:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661606408; cv=none; d=google.com; s=arc-20160816; b=Ov5aMMI2fOvqn1ySz7riNXeDHTf7yFwP1LrfgOziCtwahKuLrKSN1rKhQQD/uOy+mt GxYBIvth/UH6H8jKqXfFkjM0kbhVoTwDnLnEmg05XG4eO8bZhXfNB+otsyhW29Jt0k8W k39hTK4AaXU2847H6TDN5tLApaB/E7N7lbmsBftoRYDZKcUOFGFwNZ/izk/ysWY4wEfi ytBIGy3KO3UVoMSpbXGO7aLH14qwMyzuglq2OSbVwwIkNPgI4wjcqqT32XqVMhlC/8AP KpLavW5eFlf6Zy8V3Eb+mELJtf3DbZHXVbhLElLt9f3m8s1A5jRE1H8tFb/EpSru3BLl AYAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8oYLP+2x7Pkqzzkqq4VihKJhfPzpTwkNdBTIupOYQYo=; b=r+A/Q4xLbmfrgqqL3OpbKOEq6sd8GuwyCQo/tDhPsP7pCG5PxlgBcWMEsaidomeSL+ XWiWjGwH3rx8fNhJxk0qQgWrmxbl6vWX52pjSWdo4GD2CTKg3lOIKqpxuRb03GbQw47K ZMWjsHrXMueCZHwD3VF+DHoVopuiRXF/G1NJtu65qdxNUkGBDCzl7qxzmwKIupkJiIoy aVE8omJ+D//9enhRKVJ6/5GQhzNxqANBMa/Vgg3K3dwEabX4oarUCfZlLx+V+DN1n+iw wonKyBy0aBfZwzTmj5lmOiNf9RmKCVS7s4Mn+NL6g0hsR5OL1R7Qid3as21T4Ez9LQmG 5Efw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jIhhyxLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a170906768700b0073dc89e51b3si2739085ejm.87.2022.08.27.06.19.41; Sat, 27 Aug 2022 06:20:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jIhhyxLq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233236AbiH0NEH (ORCPT + 99 others); Sat, 27 Aug 2022 09:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232868AbiH0NEB (ORCPT ); Sat, 27 Aug 2022 09:04:01 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF4F930F78 for ; Sat, 27 Aug 2022 06:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661605439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8oYLP+2x7Pkqzzkqq4VihKJhfPzpTwkNdBTIupOYQYo=; b=jIhhyxLqPE9QhGYuXqSPW0R1+7XUNU8wXtbtq0jhjrfGpGN7maJid7q/MAEww39t7xWGIW /G+tGY6rAXDxZbOd3Mj4aOFA75Us9jG98TVQ+bTo6Je9U5XCdyYBTcdCNFZzrOYBx4O69W QdXcX4MQfZr8bfFmS0B47S14qUWJAMw= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-o9whNxK1N9C0xpAqrQg5Cg-1; Sat, 27 Aug 2022 09:03:56 -0400 X-MC-Unique: o9whNxK1N9C0xpAqrQg5Cg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67B313802B83; Sat, 27 Aug 2022 13:03:55 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.192.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id E79D6C15BC0; Sat, 27 Aug 2022 13:03:52 +0000 (UTC) From: Vitaly Kuznetsov To: linux-hyperv@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org, Bjorn Helgaas , Wei Liu , Deepak Rawat , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , Michael Kelley Subject: [PATCH v3 2/3] Drivers: hv: Always reserve framebuffer region for Gen1 VMs Date: Sat, 27 Aug 2022 15:03:44 +0200 Message-Id: <20220827130345.1320254-3-vkuznets@redhat.com> In-Reply-To: <20220827130345.1320254-1-vkuznets@redhat.com> References: <20220827130345.1320254-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vmbus_reserve_fb() tries reserving framebuffer region iff 'screen_info.lfb_base' is set. Gen2 VMs seem to have it set by EFI and/or by the kernel EFI FB driver (or, in some edge cases like kexec, the address where the buffer was moved, see https://lore.kernel.org/all/20201014092429.1415040-1-kasong@redhat.com/) but on Gen1 VM it depends on bootloader behavior. With grub, it depends on 'gfxpayload=' setting but in some cases it is observed to be zero. That being said, relying on 'screen_info.lfb_base' to reserve framebuffer region is risky. For Gen1 VMs, it should always be possible to get the address from the dedicated PCI device instead. Check for legacy PCI video device presence and reserve the whole region for framebuffer on Gen1 VMs. Reviewed-by: Michael Kelley Signed-off-by: Vitaly Kuznetsov --- drivers/hv/vmbus_drv.c | 46 +++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 23c680d1a0f5..536f68e563c6 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "hyperv_vmbus.h" @@ -2262,26 +2263,43 @@ static int vmbus_acpi_remove(struct acpi_device *device) static void vmbus_reserve_fb(void) { - int size; + resource_size_t start = 0, size; + struct pci_dev *pdev; + + if (efi_enabled(EFI_BOOT)) { + /* Gen2 VM: get FB base from EFI framebuffer */ + start = screen_info.lfb_base; + size = max_t(__u32, screen_info.lfb_size, 0x800000); + } else { + /* Gen1 VM: get FB base from PCI */ + pdev = pci_get_device(PCI_VENDOR_ID_MICROSOFT, + PCI_DEVICE_ID_HYPERV_VIDEO, NULL); + if (!pdev) + return; + + if (pdev->resource[0].flags & IORESOURCE_MEM) { + start = pci_resource_start(pdev, 0); + size = pci_resource_len(pdev, 0); + } + + /* + * Release the PCI device so hyperv_drm or hyperv_fb driver can + * grab it later. + */ + pci_dev_put(pdev); + } + + if (!start) + return; + /* * Make a claim for the frame buffer in the resource tree under the * first node, which will be the one below 4GB. The length seems to * be underreported, particularly in a Generation 1 VM. So start out * reserving a larger area and make it smaller until it succeeds. */ - - if (screen_info.lfb_base) { - if (efi_enabled(EFI_BOOT)) - size = max_t(__u32, screen_info.lfb_size, 0x800000); - else - size = max_t(__u32, screen_info.lfb_size, 0x4000000); - - for (; !fb_mmio && (size >= 0x100000); size >>= 1) { - fb_mmio = __request_region(hyperv_mmio, - screen_info.lfb_base, size, - fb_mmio_name, 0); - } - } + for (; !fb_mmio && (size >= 0x100000); size >>= 1) + fb_mmio = __request_region(hyperv_mmio, start, size, fb_mmio_name, 0); } /** -- 2.37.1