Page MenuHomeFreeBSD

virtio: get a correct tag for IOMMU operation
Needs ReviewPublic

Authored by br on Tue, Feb 10, 2:05 PM.
Tags
None
Referenced Files
F145015348: D55220.diff
Sun, Feb 15, 2:01 AM
Unknown Object (File)
Wed, Feb 11, 7:53 AM
Unknown Object (File)
Wed, Feb 11, 7:27 AM
Unknown Object (File)
Wed, Feb 11, 6:54 AM
Unknown Object (File)
Wed, Feb 11, 5:16 AM
Unknown Object (File)
Wed, Feb 11, 12:35 AM
Unknown Object (File)
Wed, Feb 11, 12:15 AM
Subscribers
None

Details

Summary

Ensure that PCI bus BUS_GET_DMA_TAG() method sees the actual PCI device which makes the request for dma tag, instead of some descendant of the PCI device (e.g. virtio devices on a transport bus).

Also, accept the VIRTIO_F_IOMMU_PLATFORM feature which is present on IOMMU-enabled emulators.

This is needed for the virtio block device operation on a IOMMU-enabled system like ARM System MMU or RISC-V IOMMU.

This patch depends on these reviews (busdma support for virtqueue and virtio block)
https://reviews.freebsd.org/D54959
https://reviews.freebsd.org/D54960

Test Plan

Tested on a RISC-V IOMMU-enabled platform

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

br requested review of this revision.Tue, Feb 10, 2:05 PM
br created this revision.

How does this differ from the default implementation specified in sys/kern/bus_if.m, namely bus_generic_get_dma_tag?

How does this differ from the default implementation specified in sys/kern/bus_if.m, namely bus_generic_get_dma_tag?

In the default implementation, the child device (for example, a virtio block drive) is passed up the device hierarchy to the PCI bus. This implementation, however, requests a tag at the Virtio-PCI level, treating the virtio pci controller (which is a device discovered on the PCI bus) as the effective child.

Oh I see, the point is about what's passed up as the second argument, not what device the method is invoked on. I guess then my question becomes why is the DMA tag special? We don't do this for resources, and we don't do this for the bus space tag. Is that just because normally it's virtio_pci doing the resource allocation?

Oh I see, the point is about what's passed up as the second argument, not what device the method is invoked on. I guess then my question becomes why is the DMA tag special? We don't do this for resources, and we don't do this for the bus space tag. Is that just because normally it's virtio_pci doing the resource allocation?

Yes, second argument is Virtio PCI bus (which is a child of the PCI bus), so that PCI framework could find a context ID for address translation based on iommu-map property in DTS. Each PCI device has its own unique context ID.
We do that for DMA tag because that is how IOMMU works in freebsd: a default busdma backend provided by architecture is replaced with a generic IOMMU busdma backend. The IOMMU busdma backend manages the guest address space per domain and allows to establish and tear down arbitrary mappings by invoking methods on an underlying IOMMU driver (ARM System MMU, RISC-V IOMMU, x86 DMAR).