Merge tag 'pull-vfio-20240723-1' of https://github.com/legoater/qemu into staging
vfio queue: * IOMMUFD Dirty Tracking support * Fix for a possible SEGV in IOMMU type1 container * Dropped initialization of host IOMMU device with mdev devices # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEoPZlSPBIlev+awtgUaNDx8/77KEFAmafyVUACgkQUaNDx8/7 # 7KGebRAAzEYxvstDxSPNF+1xx937TKbRpiKYtspTfEgu4Ht50MwO2ZqnVWzTBSwa # qcjhDf2avMBpBvkp4O9fR7nXR0HRN2KvYrBSThZ3Qpqu4KjxCAGcHI5uYmgfizYh # BBLrw3eWME5Ry220TinQF5KFl50vGq7Z/mku5N5Tgj2qfTfCXYK1Kc19SyAga49n # LSokTIjZAGJa4vxrE7THawaEUjFRjfCJey64JUs/TPJaGr4R1snJcWgETww6juUE # 9OSw/xl0AoQhaN/ZTRC1qCsBLUI2MVPsC+x+vqVK62HlTjCx+uDRVQ8KzfDzjCeH # gaLkMjxJSuJZMpm4UU7DBzDGEGcEBCGeNyFt37BSqqPPpX55CcFhj++d8vqTiwpF # YzmTNd/znxcZTw6OJN9sQZohh+NeS86CVZ3x31HD3dXifhRf17jbh7NoIyi+0ZCb # N+mytOH5BXsD+ddwbk+yMaxXV43Fgz7ThG5tB1tjhhNtLZHDA5ezFvGZ5F/FJrqE # xAbjOhz5MC+RcOVNSzQJCULNqFpfE6Gqeys6btEDm/ltf4LpAe6W1HYuv8BJc19T # UsqGK2yKAuQX8GErYxJ1zqZCttVrgpsmXFYTC5iGbxC84mvsF0Iti96IdXz9gfzN # Vlb2OxoefcOwVqIhbkvTZW0ZwYGGDDPAYhLMfr5lSuRqj123OOo= # =cViP # -----END PGP SIGNATURE----- # gpg: Signature made Wed 24 Jul 2024 01:16:37 AM AEST # gpg: using RSA key A0F66548F04895EBFE6B0B6051A343C7CFFBECA1 # gpg: Good signature from "Cédric Le Goater <clg@kaod.org>" [undefined] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: A0F6 6548 F048 95EB FE6B 0B60 51A3 43C7 CFFB ECA1 * tag 'pull-vfio-20240723-1' of https://github.com/legoater/qemu: vfio/common: Allow disabling device dirty page tracking vfio/migration: Don't block migration device dirty tracking is unsupported vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support vfio/iommufd: Implement VFIOIOMMUClass::set_dirty_tracking support vfio/iommufd: Probe and request hwpt dirty tracking capability vfio/{iommufd, container}: Invoke HostIOMMUDevice::realize() during attach_device() vfio/iommufd: Add hw_caps field to HostIOMMUDeviceCaps vfio/{iommufd,container}: Remove caps::aw_bits vfio/iommufd: Introduce auto domain creation vfio/ccw: Don't initialize HOST_IOMMU_DEVICE with mdev vfio/ap: Don't initialize HOST_IOMMU_DEVICE with mdev vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt() backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW capabilities vfio/iommufd: Don't initialize nor set a HOST_IOMMU_DEVICE with mdev vfio/pci: Extract mdev check into an helper hw/vfio/container: Fix SIGSEV on vfio_container_instance_finalize() Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
+87
-2
@@ -18,6 +18,7 @@
|
||||
#include "qemu/error-report.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "trace.h"
|
||||
#include "hw/vfio/vfio-common.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/iommufd.h>
|
||||
|
||||
@@ -207,9 +208,91 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
|
||||
uint32_t pt_id, uint32_t flags,
|
||||
uint32_t data_type, uint32_t data_len,
|
||||
void *data_ptr, uint32_t *out_hwpt,
|
||||
Error **errp)
|
||||
{
|
||||
int ret, fd = be->fd;
|
||||
struct iommu_hwpt_alloc alloc_hwpt = {
|
||||
.size = sizeof(struct iommu_hwpt_alloc),
|
||||
.flags = flags,
|
||||
.dev_id = dev_id,
|
||||
.pt_id = pt_id,
|
||||
.data_type = data_type,
|
||||
.data_len = data_len,
|
||||
.data_uptr = (uintptr_t)data_ptr,
|
||||
};
|
||||
|
||||
ret = ioctl(fd, IOMMU_HWPT_ALLOC, &alloc_hwpt);
|
||||
trace_iommufd_backend_alloc_hwpt(fd, dev_id, pt_id, flags, data_type,
|
||||
data_len, (uintptr_t)data_ptr,
|
||||
alloc_hwpt.out_hwpt_id, ret);
|
||||
if (ret) {
|
||||
error_setg_errno(errp, errno, "Failed to allocate hwpt");
|
||||
return false;
|
||||
}
|
||||
|
||||
*out_hwpt = alloc_hwpt.out_hwpt_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be,
|
||||
uint32_t hwpt_id, bool start,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
struct iommu_hwpt_set_dirty_tracking set_dirty = {
|
||||
.size = sizeof(set_dirty),
|
||||
.hwpt_id = hwpt_id,
|
||||
.flags = start ? IOMMU_HWPT_DIRTY_TRACKING_ENABLE : 0,
|
||||
};
|
||||
|
||||
ret = ioctl(be->fd, IOMMU_HWPT_SET_DIRTY_TRACKING, &set_dirty);
|
||||
trace_iommufd_backend_set_dirty(be->fd, hwpt_id, start, ret ? errno : 0);
|
||||
if (ret) {
|
||||
error_setg_errno(errp, errno,
|
||||
"IOMMU_HWPT_SET_DIRTY_TRACKING(hwpt_id %u) failed",
|
||||
hwpt_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,
|
||||
uint32_t hwpt_id,
|
||||
uint64_t iova, ram_addr_t size,
|
||||
uint64_t page_size, uint64_t *data,
|
||||
Error **errp)
|
||||
{
|
||||
int ret;
|
||||
struct iommu_hwpt_get_dirty_bitmap get_dirty_bitmap = {
|
||||
.size = sizeof(get_dirty_bitmap),
|
||||
.hwpt_id = hwpt_id,
|
||||
.iova = iova,
|
||||
.length = size,
|
||||
.page_size = page_size,
|
||||
.data = (uintptr_t)data,
|
||||
};
|
||||
|
||||
ret = ioctl(be->fd, IOMMU_HWPT_GET_DIRTY_BITMAP, &get_dirty_bitmap);
|
||||
trace_iommufd_backend_get_dirty_bitmap(be->fd, hwpt_id, iova, size,
|
||||
page_size, ret ? errno : 0);
|
||||
if (ret) {
|
||||
error_setg_errno(errp, errno,
|
||||
"IOMMU_HWPT_GET_DIRTY_BITMAP (iova: 0x%"HWADDR_PRIx
|
||||
" size: 0x"RAM_ADDR_FMT") failed", iova, size);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
|
||||
uint32_t *type, void *data, uint32_t len,
|
||||
Error **errp)
|
||||
uint64_t *caps, Error **errp)
|
||||
{
|
||||
struct iommu_hw_info info = {
|
||||
.size = sizeof(info),
|
||||
@@ -225,6 +308,8 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
|
||||
|
||||
g_assert(type);
|
||||
*type = info.out_data_type;
|
||||
g_assert(caps);
|
||||
*caps = info.out_capabilities;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -237,7 +322,7 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
|
||||
case HOST_IOMMU_DEVICE_CAP_IOMMU_TYPE:
|
||||
return caps->type;
|
||||
case HOST_IOMMU_DEVICE_CAP_AW_BITS:
|
||||
return caps->aw_bits;
|
||||
return vfio_device_get_aw_bits(hiod->agent);
|
||||
default:
|
||||
error_setg(errp, "%s: unsupported capability %x", hiod->name, cap);
|
||||
return -EINVAL;
|
||||
|
||||
@@ -14,4 +14,7 @@ iommufd_backend_map_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size
|
||||
iommufd_backend_unmap_dma_non_exist(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " Unmap nonexistent mapping: iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)"
|
||||
iommufd_backend_unmap_dma(int iommufd, uint32_t ioas, uint64_t iova, uint64_t size, int ret) " iommufd=%d ioas=%d iova=0x%"PRIx64" size=0x%"PRIx64" (%d)"
|
||||
iommufd_backend_alloc_ioas(int iommufd, uint32_t ioas) " iommufd=%d ioas=%d"
|
||||
iommufd_backend_alloc_hwpt(int iommufd, uint32_t dev_id, uint32_t pt_id, uint32_t flags, uint32_t hwpt_type, uint32_t len, uint64_t data_ptr, uint32_t out_hwpt_id, int ret) " iommufd=%d dev_id=%u pt_id=%u flags=0x%x hwpt_type=%u len=%u data_ptr=0x%"PRIx64" out_hwpt=%u (%d)"
|
||||
iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%d)"
|
||||
iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)"
|
||||
iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)"
|
||||
|
||||
Reference in New Issue
Block a user