Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp788970rwb; Mon, 26 Sep 2022 06:01:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CCQDu2e0IcThAQuRX8LmlFKFOTrpIwwnE6md52805ERUXLWAKy+p4PDfTnKwh0aGnBruD X-Received: by 2002:a17:907:7e88:b0:783:305:8cac with SMTP id qb8-20020a1709077e8800b0078303058cacmr8810459ejc.439.1664197294095; Mon, 26 Sep 2022 06:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197294; cv=none; d=google.com; s=arc-20160816; b=Nfw60wq1iDVby8GVGMSVCWnXnr0hDugKH0wNEXUaepvjRiWXdyeeDhqYENzCnlYOKe bkhU7HJ/Hcgo5VOYUD00Gf85kSmpZ+pdwbchvXFpsiw054Mnz/xjBUzqbTrQeNY/HzUh z+Skk97LXdw7b6XGa4JTSsYGnsA8MJsQqUcBvUo8dDrim8i3GuUqOW+sDJPTaF9Ip5oK Apo7jJqdIvTvfjGCXNqmMFvaP999vZ/Lf11/njXVENivYdJwdlY6ovmodRJB4TZdtrw7 hoH7o20jYqBKJSQZqx6h9pZo2H1CGHaYQ4e5P+qUErWMSAR7P0PthWhdUJRQ3qcT6r/U kSMQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LxlBHQONtZtJKZ5F9Kp+a0V8KLOG+XQ47UiUFCdG6/A=; b=JXKYJ7IEKxgTqDMMi6D6ZG2U+l89AzmmisCUR1u5OUAhi5wwg1l1c6AGFp8Zkh+rRF F9tCOnp5q/oHOj20lYcX31wjX9kYsSJn/w0N7dv8WPVcsyth5+wWSqJNNS2y5+x9Axjw PkrrInnm9UTE0aGwYmwUOSRiObA7JTtfPo3z1Vfv7zqhCQu/2d3fKrsZw2WXzrqnMxio i5UatxkhrX4axoPhmhRAiDXL9JA1L5d8EFwASyILJ3lI86T8a5jtIYdmxvULcvBn5G25 mTKl9fEvAhCYnBnCEYPcK8qGgcFxiZpTp7JlWpkRlaFpfj6s2hjxjIf03+grf8ULpd4J AWug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q72+3cSR; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g39-20020a056402322700b00443088b40b7si7387027eda.123.2022.09.26.06.00.59; Mon, 26 Sep 2022 06:01:34 -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=@linuxfoundation.org header.s=korg header.b=q72+3cSR; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238040AbiIZLfK (ORCPT + 99 others); Mon, 26 Sep 2022 07:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238120AbiIZLeI (ORCPT ); Mon, 26 Sep 2022 07:34:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD0926DF8E; Mon, 26 Sep 2022 03:43:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 937F760A55; Mon, 26 Sep 2022 10:41:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C3AFC433D6; Mon, 26 Sep 2022 10:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188887; bh=E18brjcFXfPgkUGnMgoSp6ARZIt9tLyOR0rwKgBw5Ck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q72+3cSRsAcXKY39wenHh4Xpz8BfcHA9bShSRTLzSJtp3rz3G9xkvzCpOezJfdHyN zBN2wEKXJTuAMHQnl4hKK1n76wmLbKWRiwrUB1Y7mmnzXLk6XCwfBafWmConlw+d6y 31gYrNLQZBxL/Z+78a/mBfj8zhf17w19dcbVC1CQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kelley , Vitaly Kuznetsov , Wei Liu , Sasha Levin Subject: [PATCH 5.15 124/148] Drivers: hv: Never allocate anything besides framebuffer from framebuffer memory region Date: Mon, 26 Sep 2022 12:12:38 +0200 Message-Id: <20220926100800.800340303@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Vitaly Kuznetsov [ Upstream commit f0880e2cb7e1f8039a048fdd01ce45ab77247221 ] Passed through PCI device sometimes misbehave on Gen1 VMs when Hyper-V DRM driver is also loaded. Looking at IOMEM assignment, we can see e.g. $ cat /proc/iomem ... f8000000-fffbffff : PCI Bus 0000:00 f8000000-fbffffff : 0000:00:08.0 f8000000-f8001fff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe ... fe0000000-fffffffff : PCI Bus 0000:00 fe0000000-fe07fffff : bb8c4f33-2ba2-4808-9f7f-02f3b4da22fe fe0000000-fe07fffff : 2ba2:00:02.0 fe0000000-fe07fffff : mlx4_core the interesting part is the 'f8000000' region as it is actually the VM's framebuffer: $ lspci -v ... 0000:00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA (prog-if 00 [VGA controller]) Flags: bus master, fast devsel, latency 0, IRQ 11 Memory at f8000000 (32-bit, non-prefetchable) [size=64M] ... hv_vmbus: registering driver hyperv_drm hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Synthvid Version major 3, minor 5 hyperv_drm 0000:00:08.0: vgaarb: deactivate vga console hyperv_drm 0000:00:08.0: BAR 0: can't reserve [mem 0xf8000000-0xfbffffff] hyperv_drm 5620e0c7-8062-4dce-aeb7-520c7ef76171: [drm] Cannot request framebuffer, boot fb still active? Note: "Cannot request framebuffer" is not a fatal error in hyperv_setup_gen1() as the code assumes there's some other framebuffer device there but we actually have some other PCI device (mlx4 in this case) config space there! The problem appears to be that vmbus_allocate_mmio() can use dedicated framebuffer region to serve any MMIO request from any device. The semantics one might assume of a parameter named "fb_overlap_ok" aren't implemented because !fb_overlap_ok essentially has no effect. The existing semantics are really "prefer_fb_overlap". This patch implements the expected and needed semantics, which is to not allocate from the frame buffer space when !fb_overlap_ok. Note, Gen2 VMs are usually unaffected by the issue because framebuffer region is already taken by EFI fb (in case kernel supports it) but Gen1 VMs may have this region unclaimed by the time Hyper-V PCI pass-through driver tries allocating MMIO space if Hyper-V DRM/FB drivers load after it. Devices can be brought up in any sequence so let's resolve the issue by always ignoring 'fb_mmio' region for non-FB requests, even if the region is unclaimed. Reviewed-by: Michael Kelley Signed-off-by: Vitaly Kuznetsov Link: https://lore.kernel.org/r/20220827130345.1320254-4-vkuznets@redhat.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/hv/vmbus_drv.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 50d9113f5402..ecfc299834e1 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2340,7 +2340,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, bool fb_overlap_ok) { struct resource *iter, *shadow; - resource_size_t range_min, range_max, start; + resource_size_t range_min, range_max, start, end; const char *dev_n = dev_name(&device_obj->device); int retval; @@ -2375,6 +2375,14 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, range_max = iter->end; start = (range_min + align - 1) & ~(align - 1); for (; start + size - 1 <= range_max; start += align) { + end = start + size - 1; + + /* Skip the whole fb_mmio region if not fb_overlap_ok */ + if (!fb_overlap_ok && fb_mmio && + (((start >= fb_mmio->start) && (start <= fb_mmio->end)) || + ((end >= fb_mmio->start) && (end <= fb_mmio->end)))) + continue; + shadow = __request_region(iter, start, size, NULL, IORESOURCE_BUSY); if (!shadow) -- 2.35.1