-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iommu: always enable the vfio backend
Even if we have a kernel with iommufd vfio features enabled, the kernel may not be configured for modern iommufd (i.e., no device cdevs). In that case we want to fall back to legacy vfio. Signed-off-by: Klaus Jensen <[email protected]>
- Loading branch information
Showing
7 changed files
with
108 additions
and
29 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,65 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later or MIT | ||
|
||
/* | ||
* This file is part of libvfn. | ||
* | ||
* Copyright (C) 2023 The libvfn Authors. All Rights Reserved. | ||
* | ||
* This library (libvfn) is dual licensed under the GNU Lesser General | ||
* Public License version 2.1 or later or the MIT license. See the | ||
* COPYING and LICENSE files for more information. | ||
*/ | ||
|
||
#define log_fmt(fmt) "iommu/context: " fmt | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <pthread.h> | ||
|
||
#include <sys/stat.h> | ||
|
||
#include "vfn/support.h" | ||
|
||
#include "util/iova_map.h" | ||
#include "context.h" | ||
|
||
#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD | ||
static bool __iommufd_broken; | ||
|
||
static void __attribute__((constructor)) __check_iommufd_broken(void) | ||
{ | ||
struct stat sb; | ||
|
||
if (stat("/dev/vfio/devices", &sb) || (sb.st_mode & S_IFDIR)) { | ||
log_info("iommufd broken; probably missing CONFIG_VFIO_DEVICE_CDEV=y\n"); | ||
|
||
__iommufd_broken = true; | ||
} | ||
} | ||
#endif | ||
|
||
struct iommu_ctx *iommu_get_default_context(void) | ||
{ | ||
#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD | ||
if (__iommufd_broken) | ||
goto fallback; | ||
|
||
return iommufd_get_default_iommu_context(); | ||
|
||
fallback: | ||
#endif | ||
return vfio_get_default_iommu_context(); | ||
} | ||
|
||
struct iommu_ctx *iommu_get_context(const char *name) | ||
{ | ||
#ifdef HAVE_VFIO_DEVICE_BIND_IOMMUFD | ||
if (__iommufd_broken) | ||
goto fallback; | ||
|
||
return iommufd_get_iommu_context(name); | ||
|
||
fallback: | ||
#endif | ||
return vfio_get_iommu_context(name); | ||
} |
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
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
iommu_sources = files( | ||
'context.c', | ||
'dma.c', | ||
'vfio.c', | ||
) | ||
|
||
if config_host.get('HAVE_VFIO_DEVICE_BIND_IOMMUFD', false) | ||
iommu_sources += files('iommufd.c',) | ||
else | ||
iommu_sources += files('vfio.c') | ||
endif | ||
|
||
vfn_sources += iommu_sources |
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