Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iommu/iommufd: Add iommufd_[un]bind_device()
Under the /dev/iommu model, iommufd provides the interface for I/O page tables management such as dma map/unmap. However, it cannot work independently since the device is still owned by the device-passthrough frameworks (VFIO, vDPA, etc.) and vice versa. Device-passthrough frameworks should build a connection between its device and the iommufd to delegate the I/O page table management affairs to iommufd. This patch introduces iommufd_[un]bind_device() helpers for the device- passthrough framework to build such connection. The helper functions then invoke iommu core (iommu_device_init/exit_user_dma()) to establish/exit security context for the bound device. Each successfully bound device is internally tracked by an iommufd_device object. This object is returned to the caller for subsequent attaching operations on the device as well. The caller should pass a user-provided cookie to mark the device in the iommufd. Later this cookie will be used to represent the device in iommufd uAPI, e.g. when querying device capabilities or handling per-device I/O page faults. One alternative is to have iommufd allocate a device label and return to the user. Either way works, but cookie is slightly preferred per earlier discussion as it may allow the user to inject faults slightly faster without ID->vRID lookup. iommu_[un]bind_device() functions are only used for physical devices. Other variants will be introduced in the future, e.g.: - iommu_[un]bind_device_pasid() for mdev/subdev which requires pasid granular DMA isolation; - iommu_[un]bind_sw_mdev() for sw mdev which relies on software measures instead of iommu to isolate DMA; Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
- Loading branch information
Showing
2 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* IOMMUFD API definition | ||
* | ||
* Copyright (C) 2021 Intel Corporation | ||
* | ||
* Author: Liu Yi L <yi.l.liu@intel.com> | ||
*/ | ||
#ifndef __LINUX_IOMMUFD_H | ||
#define __LINUX_IOMMUFD_H | ||
|
||
#include <linux/types.h> | ||
#include <linux/errno.h> | ||
#include <linux/err.h> | ||
#include <linux/device.h> | ||
|
||
#define IOMMUFD_DEVID_MAX ((unsigned int)(0x7FFFFFFF)) | ||
#define IOMMUFD_DEVID_MIN 0 | ||
|
||
struct iommufd_device; | ||
|
||
#if IS_ENABLED(CONFIG_IOMMUFD) | ||
struct iommufd_device * | ||
iommufd_bind_device(int fd, struct device *dev, u64 dev_cookie); | ||
void iommufd_unbind_device(struct iommufd_device *idev); | ||
|
||
#else /* !CONFIG_IOMMUFD */ | ||
static inline struct iommufd_device * | ||
iommufd_bind_device(int fd, struct device *dev, u64 dev_cookie) | ||
{ | ||
return ERR_PTR(-ENODEV); | ||
} | ||
|
||
static inline void iommufd_unbind_device(struct iommufd_device *idev) | ||
{ | ||
} | ||
#endif /* CONFIG_IOMMUFD */ | ||
#endif /* __LINUX_IOMMUFD_H */ |