From d9f92cd3e21f9b63dbafb9fe396a0f7560e00c66 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 28 Feb 2019 16:57:03 -0700 Subject: [PATCH] memory: add way of checking iommu usage Since the fuzz tester will be submitting random commands with random memory addresses and such to the NVMe drives, we want to be especially sure that we are using the IOMMU while running this test to prevent memory corruption in the event that an errant command triggers a bad DMA. This function exposes to the application whether or not we are using the IOMMU. Change-Id: Ie4d26c706967a520967bfc81f72f7b581b792437 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446568 Reviewed-by: Jim Harris Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- include/spdk/env.h | 7 +++++++ lib/env_dpdk/memory.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/spdk/env.h b/include/spdk/env.h index 2d2c7faa5..53eb54533 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -573,6 +573,13 @@ size_t spdk_ring_enqueue(struct spdk_ring *ring, void **objs, size_t count); */ size_t spdk_ring_dequeue(struct spdk_ring *ring, void **objs, size_t count); +/** + * Reports whether the SPDK application is using the IOMMU for DMA + * + * \return True if we are using the IOMMU, false otherwise. + */ +bool spdk_iommu_is_enabled(void); + #define SPDK_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL) /** diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 9afd5ad59..ed26a7295 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -779,6 +779,16 @@ spdk_mem_map_init(void) return 0; } +bool +spdk_iommu_is_enabled(void) +{ +#if SPDK_VFIO_ENABLED + return g_vfio.enabled && !g_vfio.noiommu_enabled; +#else + return false; +#endif +} + struct spdk_vtophys_pci_device { struct rte_pci_device *pci_device; TAILQ_ENTRY(spdk_vtophys_pci_device) tailq;