Skip to contentSkip to conversation

Improve vfio-pci primary GPU assignment behavior

PATCH Superseded Thomas Zimmermann 1 participant 5 messages Jun 22, 2022 – Jul 4, 2022

Subsystems (8)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v3 cover Improve vfio-pci primary GPU assignment behavior

(I'm taking over this patchset from Alex, [1] as we agreed that it should go through the drm-misc tree.)

When assigning a primary graphics device to VM through vfio-pci device assignment, users often prevent binding of the native PCI graphics driver to avoid device initialization conflicts, however firmware console drivers may still be attached to the device which can often be cumbersome to manually unbind or exclude via cmdline options.

This series proposes to move the DRM aperture helpers out to drivers/video/ to make it more accessible to drivers like vfio-pci, which have neither dependencies on DRM code nor a struct drm_driver to present to existing interfaces. vfio-pci can then trivially call into the aperture helpers to remove conflicting drivers, rather than open coding it ourselves as was proposed with a new symbol export in v1 of this series. [2]

v3:
* add aperture_ prefix to all interfaces (Javier)
* improved documentation (Javier)
* update MAINTAINERS [3] and add aperture helpers

[1] https://lore.kernel.org/all/165541020563.1955826.16350888595945658159.stgit@omen/
[2] https://lore.kernel.org/all/165453797543.3592816.6381793341352595461.stgit@omen/
[3] https://lore.kernel.org/all/[email protected]/

Alex Williamson (1):
vfio/pci: Remove console drivers

Thomas Zimmermann (2):
MAINTAINERS: Broaden scope of simpledrm entry
drm: Implement DRM aperture helpers under video/

 Documentation/driver-api/aperture.rst |  13 +
 Documentation/driver-api/index.rst    |   1 +
 MAINTAINERS                           |   6 +-
 drivers/gpu/drm/drm_aperture.c        | 178 +------------
 drivers/gpu/drm/tiny/Kconfig          |   1 +
 drivers/vfio/pci/vfio_pci_core.c      |   5 +
 drivers/video/Kconfig                 |   6 +
 drivers/video/Makefile                |   2 +
 drivers/video/aperture.c              | 351 ++++++++++++++++++++++++++
 drivers/video/console/Kconfig         |   1 +
 drivers/video/fbdev/Kconfig           |   7 +-
 include/linux/aperture.h              |  56 ++++
 12 files changed, 456 insertions(+), 171 deletions(-)
 create mode 100644 Documentation/driver-api/aperture.rst
 create mode 100644 drivers/video/aperture.c
 create mode 100644 include/linux/aperture.h

base-commit: 7025c1f111b7a057243de45bd56c14b906242a53

Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH v3 1/3 MAINTAINERS: Broaden scope of simpledrm entry

There will be more DRM drivers for firmware-provided framebuffers. Use the existing entry for simpledrm instead of adding a new one for each driver. Also add DRM's aperture helpers, which are part of the driver's infrastructure.

---
 MAINTAINERS | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
MAINTAINERS +3 -1
index a0275a0b4fe6..d4c091739db2 100644
@@ -6466,13 +6466,15 @@ S:	Orphan / Obsolete
 F:	drivers/gpu/drm/savage/
 F:	include/uapi/drm/savage_drm.h
 
-DRM DRIVER FOR SIMPLE FRAMEBUFFERS
+DRM DRIVER FOR FIRMWARE FRAMEBUFFERS
 M:	Thomas Zimmermann <[email protected]>
 M:	Javier Martinez Canillas <[email protected]>
 L:	[email protected]
 S:	Maintained
 T:	git git://anongit.freedesktop.org/drm/drm-misc
+F:	drivers/gpu/drm/drm_aperture.c
 F:	drivers/gpu/drm/tiny/simpledrm.c
+F:	include/drm/drm_aperture.h
 
 DRM DRIVER FOR SIS VIDEO CARDS
 S:	Orphan / Obsolete
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

PATCH v3 2/3 drm: Implement DRM aperture helpers under video/

In reply to Thomas Zimmermann

Implement DRM's aperture helpers under video/ for sharing with other sub-systems. Remove DRM-isms from the interface. The helpers track the ownership of framebuffer apertures and provide hand-over from firmware, such as EFI and VESA, to native graphics drivers.

Other subsystems, such as fbdev and vfio, also have to maintain ownership of framebuffer apertures. Moving DRM's aperture helpers to a more public location allows all subsystems to interact with each other and share a common implementation.

The aperture helpers are selected by the various firmware drivers within DRM and fbdev, and the VGA text-console driver.

The original DRM interface is kept in place for use by DRM drivers.

v3:
* prefix all interfaces with aperture_ (Javier)
* rework and simplify documentation (Javier)
* rename struct dev_aperture to struct aperture_range
* rebase onto latest DRM
* update MAINTAINERS entry

---
 Documentation/driver-api/aperture.rst |  13 +
 Documentation/driver-api/index.rst    |   1 +
 MAINTAINERS                           |   2 +
 drivers/gpu/drm/drm_aperture.c        | 178 +------------
 drivers/gpu/drm/tiny/Kconfig          |   1 +
 drivers/video/Kconfig                 |   6 +
 drivers/video/Makefile                |   2 +
 drivers/video/aperture.c              | 351 ++++++++++++++++++++++++++
 drivers/video/console/Kconfig         |   1 +
 drivers/video/fbdev/Kconfig           |   7 +-
 include/linux/aperture.h              |  56 ++++
 11 files changed, 448 insertions(+), 170 deletions(-)
 create mode 100644 Documentation/driver-api/aperture.rst
 create mode 100644 drivers/video/aperture.c
 create mode 100644 include/linux/aperture.h
Documentation/driver-api/aperture.rst new file +13 -0
new file mode 100644
index 000000000000..d173f4e7a7d9
@@ -0,0 +1,13 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Managing Ownership of the Framebuffer Aperture
+==============================================
+
+.. kernel-doc:: drivers/video/aperture.c
+   :doc: overview
+
+.. kernel-doc:: include/linux/aperture.h
+   :internal:
+
+.. kernel-doc:: drivers/video/aperture.c
+   :export:
Documentation/driver-api/index.rst +1 -0
index a6d525cd9fc4..d3a58f77328e 100644
@@ -27,6 +27,7 @@ available subsections can be seen below.
    component
    message-based
    infiniband
+   aperture
    frame-buffer
    regulator
    reset
MAINTAINERS +2 -0
index d4c091739db2..e86817b0ea1b 100644
@@ -6474,7 +6474,9 @@ S:	Maintained
 T:	git git://anongit.freedesktop.org/drm/drm-misc
 F:	drivers/gpu/drm/drm_aperture.c
 F:	drivers/gpu/drm/tiny/simpledrm.c
+F:	drivers/video/aperture.c
 F:	include/drm/drm_aperture.h
+F:	include/linux/aperture.h
 
 DRM DRIVER FOR SIS VIDEO CARDS
 S:	Orphan / Obsolete
drivers/gpu/drm/drm_aperture.c +9 -169

211 lines not on this page · raw message

drivers/gpu/drm/tiny/Kconfig +1 -0
index 627d637a1e7e..027cd87c3d0d 100644
@@ -69,6 +69,7 @@ config DRM_PANEL_MIPI_DBI
 config DRM_SIMPLEDRM
 	tristate "Simple framebuffer driver"
 	depends on DRM && MMU
+	select APERTURE_HELPERS
 	select DRM_GEM_SHMEM_HELPER
 	select DRM_KMS_HELPER
 	help
drivers/video/Kconfig +6 -0
index 427a993c7f57..0587e21abad9 100644
@@ -5,6 +5,12 @@
 
 menu "Graphics support"
 
+config APERTURE_HELPERS
+	bool
+	help
+	  Support tracking and hand-over of aperture ownership. Required
+	  by graphics drivers for firmware-provided framebuffers.
+
 if HAS_IOMEM
 
 config HAVE_FB_ATMEL
drivers/video/Makefile +2 -0
index df7650adede9..5bb6b452cc83 100644
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_APERTURE_HELPERS)    += aperture.o
 obj-$(CONFIG_VGASTATE)            += vgastate.o
 obj-$(CONFIG_HDMI)                += hdmi.o
 
drivers/video/aperture.c new file +351 -0

351 lines not on this page · raw message

drivers/video/console/Kconfig +1 -0
index 40c50fa2dd70..22cea5082ac4 100644
@@ -10,6 +10,7 @@ config VGA_CONSOLE
 	depends on !4xx && !PPC_8xx && !SPARC && !M68K && !PARISC &&  !SUPERH && \
 		(!ARM || ARCH_FOOTBRIDGE || ARCH_INTEGRATOR || ARCH_NETWINDER) && \
 		!ARM64 && !ARC && !MICROBLAZE && !OPENRISC && !S390 && !UML
+	select APERTURE_HELPERS if (DRM || FB || VFIO_PCI_CORE)
 	default y
 	help
 	  Saying Y here will allow you to use Linux in text mode through a
drivers/video/fbdev/Kconfig +6 -1
index f2a6b81e45c4..cfc55273dc5d 100644
@@ -455,6 +455,7 @@ config FB_ATARI
 config FB_OF
 	bool "Open Firmware frame buffer device support"
 	depends on (FB = y) && PPC && (!PPC_PSERIES || PCI)
+	select APERTURE_HELPERS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
 	select FB_CFB_IMAGEBLIT
@@ -527,6 +528,7 @@ config FB_IMSTT
 config FB_VGA16
 	tristate "VGA 16-color graphics support"
 	depends on FB && (X86 || PPC)
+	select APERTURE_HELPERS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
 	select FB_CFB_IMAGEBLIT
@@ -551,7 +553,7 @@ config FB_STI
 	  BIOS routines contained in a ROM chip in HP PA-RISC based machines.
 	  Enabling this option will implement the linux framebuffer device
 	  using calls to the STI BIOS routines for initialisation.
-	
+
 	  If you enable this option, you will get a planar framebuffer device
 	  /dev/fb which will work on the most common HP graphic cards of the
 	  NGLE family, including the artist chips (in the 7xx and Bxxx series),
@@ -617,6 +619,7 @@ config FB_UVESA
 config FB_VESA
 	bool "VESA VGA graphics support"
 	depends on (FB = y) && X86
+	select APERTURE_HELPERS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
 	select FB_CFB_IMAGEBLIT
@@ -630,6 +633,7 @@ config FB_VESA
 config FB_EFI
 	bool "EFI-based Framebuffer Support"
 	depends on (FB = y) && !IA64 && EFI
+	select APERTURE_HELPERS
 	select DRM_PANEL_ORIENTATION_QUIRKS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
@@ -2190,6 +2194,7 @@ config FB_SIMPLE
 	tristate "Simple framebuffer support"
 	depends on FB
 	depends on !DRM_SIMPLEDRM
+	select APERTURE_HELPERS
 	select FB_CFB_FILLRECT
 	select FB_CFB_COPYAREA
 	select FB_CFB_IMAGEBLIT
include/linux/aperture.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.36.1
author maintainer
#3 lore raw

PATCH v3 3/3 vfio/pci: Remove console drivers

In reply to Thomas Zimmermann

From: Alex Williamson <[email protected]>

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. Use the aperture helpers to remove these conflicts.

v3:
* call aperture_remove_conflicting_pci_devices()

---
 drivers/vfio/pci/vfio_pci_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/vfio/pci/vfio_pci_core.c +5 -0
index a0d69ddaf90d..756d049bd9cf 100644
@@ -10,6 +10,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/aperture.h>
 #include <linux/device.h>
 #include <linux/eventfd.h>
 #include <linux/file.h>
@@ -1793,6 +1794,10 @@ static int vfio_pci_vga_init(struct vfio_pci_core_device *vdev)
 	if (!vfio_pci_is_vga(pdev))
 		return 0;
 
+	ret = aperture_remove_conflicting_pci_devices(pdev, vdev->vdev.ops->name);
+	if (ret)
+		return ret;
+
 	ret = vga_client_register(pdev, vfio_pci_set_decode);
 	if (ret)
 		return ret;
Signature · 1 line
2.36.1
author maintainer
#4 lore raw
In reply to Thomas Zimmermann

Hi,

this patchset has meanwhile reached drm-next and should go into Linux v5.20.

https://cgit.freedesktop.org/drm/drm/commit/?id=d173780620792c725506b0f3c5ec52c7fbac1db0

Best regards
Thomas

Am 22.06.22 um 16:01 schrieb Thomas Zimmermann:

Quoted 52 lines

(I'm taking over this patchset from Alex, [1] as we agreed that it should go through the drm-misc tree.)

When assigning a primary graphics device to VM through vfio-pci device assignment, users often prevent binding of the native PCI graphics driver to avoid device initialization conflicts, however firmware console drivers may still be attached to the device which can often be cumbersome to manually unbind or exclude via cmdline options.

This series proposes to move the DRM aperture helpers out to drivers/video/ to make it more accessible to drivers like vfio-pci, which have neither dependencies on DRM code nor a struct drm_driver to present to existing interfaces. vfio-pci can then trivially call into the aperture helpers to remove conflicting drivers, rather than open coding it ourselves as was proposed with a new symbol export in v1 of this series. [2]

v3:
* add aperture_ prefix to all interfaces (Javier)
* improved documentation (Javier)
* update MAINTAINERS [3] and add aperture helpers

[1] https://lore.kernel.org/all/165541020563.1955826.16350888595945658159.stgit@omen/
[2] https://lore.kernel.org/all/165453797543.3592816.6381793341352595461.stgit@omen/
[3] https://lore.kernel.org/all/[email protected]/

Alex Williamson (1):
vfio/pci: Remove console drivers

Thomas Zimmermann (2):
MAINTAINERS: Broaden scope of simpledrm entry
drm: Implement DRM aperture helpers under video/

  Documentation/driver-api/aperture.rst |  13 +
  Documentation/driver-api/index.rst    |   1 +
  MAINTAINERS                           |   6 +-
  drivers/gpu/drm/drm_aperture.c        | 178 +------------
  drivers/gpu/drm/tiny/Kconfig          |   1 +
  drivers/vfio/pci/vfio_pci_core.c      |   5 +
  drivers/video/Kconfig                 |   6 +
  drivers/video/Makefile                |   2 +
  drivers/video/aperture.c              | 351 ++++++++++++++++++++++++++
  drivers/video/console/Kconfig         |   1 +
  drivers/video/fbdev/Kconfig           |   7 +-
  include/linux/aperture.h              |  56 ++++
  12 files changed, 456 insertions(+), 171 deletions(-)

create mode 100644 Documentation/driver-api/aperture.rst create mode 100644 drivers/video/aperture.c create mode 100644 include/linux/aperture.h

base-commit: 7025c1f111b7a057243de45bd56c14b906242a53

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev