From patchwork Mon Jun 6 17:53:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 12870736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31E22C43334 for ; Mon, 6 Jun 2022 17:53:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A5C418920E; Mon, 6 Jun 2022 17:53:30 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4185111BC52 for ; Mon, 6 Jun 2022 17:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538008; 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=IfD1tbvBdtS906lBuWttr7mz/0+ljzq4D8mcZKfR97o=; b=RgdQeNsybHbQR5TViplrz3IT3putidA/20VQXpT+PuH4cpT0Ot7h6CzC1ao+6z4QW7h1Vj iucOewHC8uB13DkyrqENwORI8FQIBWJNLJjnLjlUTQmC1lUxNEAxqBK0WSzsVqKu/j+RM9 pQ6gOKXO5KWzAa+K+WY1EUH2AbYyyh0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-qFqYIho4N0G1S-XqmJmQmA-1; Mon, 06 Jun 2022 13:53:24 -0400 X-MC-Unique: qFqYIho4N0G1S-XqmJmQmA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3A72801E6B; Mon, 6 Jun 2022 17:53:23 +0000 (UTC) Received: from [172.30.41.16] (unknown [10.22.35.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0A411121314; Mon, 6 Jun 2022 17:53:22 +0000 (UTC) Subject: [PATCH 1/2] drm/aperture: Split conflicting platform driver removal From: Alex Williamson To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch Date: Mon, 06 Jun 2022 11:53:22 -0600 Message-ID: <165453800256.3592816.10844562232615146019.stgit@omen> In-Reply-To: <165453797543.3592816.6381793341352595461.stgit@omen> References: <165453797543.3592816.6381793341352595461.stgit@omen> User-Agent: StGit/1.5.dev2+g9ce680a52bd9 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Laszlo Ersek , Gerd Hoffmann , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Split the removal of platform drivers conflicting with PCI resources from drm_aperture_remove_conflicting_pci_framebuffers() to support both non-DRM callers and better modularity. This is intended to support the vfio-pci driver, which can acquire ownership of PCI graphics devices, but is not itself a DRM or FB driver, and therefore has no Kconfig dependencies. The remaining actions of drm_aperture_remove_conflicting_pci_framebuffers() are already exported from their respective subsystems, therefore this allows vfio-pci to separate each set of conflicts independently based on the configured features. Reported-by: Laszlo Ersek Tested-by: Laszlo Ersek Suggested-by: Gerd Hoffmann Signed-off-by: Alex Williamson --- drivers/gpu/drm/drm_aperture.c | 33 ++++++++++++++++++++++++--------- include/drm/drm_aperture.h | 2 ++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_aperture.c b/drivers/gpu/drm/drm_aperture.c index 74bd4a76b253..5b2500f7fb8b 100644 --- a/drivers/gpu/drm/drm_aperture.c +++ b/drivers/gpu/drm/drm_aperture.c @@ -313,6 +313,28 @@ int drm_aperture_remove_conflicting_framebuffers(resource_size_t base, resource_ } EXPORT_SYMBOL(drm_aperture_remove_conflicting_framebuffers); +/** + * drm_aperture_detach_platform_drivers - detach platform drivers conflicting with PCI device + * @pdev: PCI device + * + * This function detaches platform drivers with resource conflicts to the memory + * bars of the provided @pdev. + */ +void drm_aperture_detach_platform_drivers(struct pci_dev *pdev) +{ + resource_size_t base, size; + int bar; + + for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) { + if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) + continue; + base = pci_resource_start(pdev, bar); + size = pci_resource_len(pdev, bar); + drm_aperture_detach_drivers(base, size); + } +} +EXPORT_SYMBOL(drm_aperture_detach_platform_drivers); + /** * drm_aperture_remove_conflicting_pci_framebuffers - remove existing framebuffers for PCI devices * @pdev: PCI device @@ -328,16 +350,9 @@ EXPORT_SYMBOL(drm_aperture_remove_conflicting_framebuffers); int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const struct drm_driver *req_driver) { - resource_size_t base, size; - int bar, ret = 0; + int ret = 0; - for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) { - if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) - continue; - base = pci_resource_start(pdev, bar); - size = pci_resource_len(pdev, bar); - drm_aperture_detach_drivers(base, size); - } + drm_aperture_detach_platform_drivers(pdev); /* * WARNING: Apparently we must kick fbdev drivers before vgacon, diff --git a/include/drm/drm_aperture.h b/include/drm/drm_aperture.h index 7096703c3949..53fd36fa258e 100644 --- a/include/drm/drm_aperture.h +++ b/include/drm/drm_aperture.h @@ -15,6 +15,8 @@ int devm_aperture_acquire_from_firmware(struct drm_device *dev, resource_size_t int drm_aperture_remove_conflicting_framebuffers(resource_size_t base, resource_size_t size, bool primary, const struct drm_driver *req_driver); +void drm_aperture_detach_platform_drivers(struct pci_dev *pdev); + int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev, const struct drm_driver *req_driver); From patchwork Mon Jun 6 17:53:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 12870738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F1BFC433EF for ; Mon, 6 Jun 2022 17:53:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 093C810EFEC; Mon, 6 Jun 2022 17:53:37 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id 56BB310F037 for ; Mon, 6 Jun 2022 17:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654538014; 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=iA2aAWueYemnyJQ4dmqeSAUKTpTcIZlRBOZbhOhKWRA=; b=guYsIe++XFuq7A24hHyytvk12J5hpGeMbxG7wtD8UZR4yA41/XL3UqAeigOvMGtdaoIlek w3yht5Cfv/qoZdwfMkpSAF/WLYtI1mKgGvMQ2EZ93rilihuXsZtLYPf+IfoxLfUlNROJmW 6Or+592ps+rLjDixtVBLlFUiUVdlaIo= 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-86-wQ4XU06yNX2snpDddsb96g-1; Mon, 06 Jun 2022 13:53:30 -0400 X-MC-Unique: wQ4XU06yNX2snpDddsb96g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C32573979680; Mon, 6 Jun 2022 17:53:29 +0000 (UTC) Received: from [172.30.41.16] (unknown [10.22.35.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 139F840336E; Mon, 6 Jun 2022 17:53:29 +0000 (UTC) Subject: [PATCH 2/2] vfio/pci: Remove console drivers From: Alex Williamson To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch Date: Mon, 06 Jun 2022 11:53:28 -0600 Message-ID: <165453800875.3592816.12944011921352366695.stgit@omen> In-Reply-To: <165453797543.3592816.6381793341352595461.stgit@omen> References: <165453797543.3592816.6381793341352595461.stgit@omen> User-Agent: StGit/1.5.dev2+g9ce680a52bd9 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Laszlo Ersek , Gerd Hoffmann , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Console drivers can create conflicts with PCI resources resulting in userspace getting mmap failures to memory BARs. This is especially evident when trying to re-use the system primary console for userspace drivers. Attempt to remove all nature of conflicting drivers as part of our VGA initialization. Reported-by: Laszlo Ersek Tested-by: Laszlo Ersek Suggested-by: Gerd Hoffmann Signed-off-by: Alex Williamson --- drivers/vfio/pci/vfio_pci_core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index a0d69ddaf90d..e0cbcbc2aee1 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ #include +#include + #define DRIVER_AUTHOR "Alex Williamson " #define DRIVER_DESC "core driver for VFIO based PCI devices" @@ -1793,6 +1796,20 @@ static int vfio_pci_vga_init(struct vfio_pci_core_device *vdev) if (!vfio_pci_is_vga(pdev)) return 0; +#if IS_REACHABLE(CONFIG_DRM) + drm_aperture_detach_platform_drivers(pdev); +#endif + +#if IS_REACHABLE(CONFIG_FB) + ret = remove_conflicting_pci_framebuffers(pdev, vdev->vdev.ops->name); + if (ret) + return ret; +#endif + + ret = vga_remove_vgacon(pdev); + if (ret) + return ret; + ret = vga_client_register(pdev, vfio_pci_set_decode); if (ret) return ret;