Skip to content

Commit

Permalink
iommu: Check iommufd is broken during runtime
Browse files Browse the repository at this point in the history
Rather than checking whether IOMMUFD is broken or not in the
constructor, this patch checks it everytime app. tries to get the IOMMU
context.  This is for cases that the target device is binded to
`vfio-pci` driver in the middle of the app's runtime, not the very first
time.

Signed-off-by: Minwoo Im <[email protected]>
  • Loading branch information
minwooim authored and birkelund committed Jul 18, 2024
1 parent c8af2e2 commit a51a97b
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/iommu/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@
#define IOVA_MAX_39BITS (1ULL << 39)

#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD
static bool __iommufd_broken;

static void __attribute__((constructor)) __check_iommufd_broken(void)
static inline bool __iommufd_is_broken(void)
{
struct stat sb;

if (stat("/dev/vfio/devices", &sb) || !S_ISDIR(sb.st_mode)) {
log_info("iommufd broken; probably missing CONFIG_VFIO_DEVICE_CDEV=y\n");

__iommufd_broken = true;
return true;
}
return false;
}
#endif

struct iommu_ctx *iommu_get_default_context(void)
{
#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD
if (__iommufd_broken)
if (__iommufd_is_broken())
goto fallback;

return iommufd_get_default_iommu_context();
Expand All @@ -57,7 +56,7 @@ struct iommu_ctx *iommu_get_default_context(void)
struct iommu_ctx *iommu_get_context(const char *name)
{
#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD
if (__iommufd_broken)
if (__iommufd_is_broken())
goto fallback;

return iommufd_get_iommu_context(name);
Expand Down

0 comments on commit a51a97b

Please sign in to comment.