Skip to content

Commit 143c7bc

Browse files
committed
Merge tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd
Pull iommufd updates from Jason Gunthorpe: "Some polishing and small fixes for iommufd: - Remove IOMMU_CAP_INTR_REMAP, instead rely on the interrupt subsystem - Use GFP_KERNEL_ACCOUNT inside the iommu_domains - Support VFIO_NOIOMMU mode with iommufd - Various typos - A list corruption bug if HWPTs are used for attach" * tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd: iommufd: Do not add the same hwpt to the ioas->hwpt_list twice iommufd: Make sure to zero vfio_iommu_type1_info before copying to user vfio: Support VFIO_NOIOMMU with iommufd iommufd: Add three missing structures in ucmd_buffer selftests: iommu: Fix test_cmd_destroy_access() call in user_copy iommu: Remove IOMMU_CAP_INTR_REMAP irq/s390: Add arch_is_isolated_msi() for s390 iommu/x86: Replace IOMMU_CAP_INTR_REMAP with IRQ_DOMAIN_FLAG_ISOLATED_MSI genirq/msi: Rename IRQ_DOMAIN_MSI_REMAP to IRQ_DOMAIN_ISOLATED_MSI genirq/irqdomain: Remove unused irq_domain_check_msi_remap() code iommufd: Convert to msi_device_has_isolated_msi() vfio/type1: Convert to iommu_group_has_isolated_msi() iommu: Add iommu_group_has_isolated_msi() genirq/msi: Add msi_device_has_isolated_msi()
2 parents a13de74 + 939204e commit 143c7bc

File tree

27 files changed

+243
-134
lines changed

27 files changed

+243
-134
lines changed

arch/s390/include/asm/msi.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_S390_MSI_H
3+
#define _ASM_S390_MSI_H
4+
#include <asm-generic/msi.h>
5+
6+
/*
7+
* Work around S390 not using irq_domain at all so we can't set
8+
* IRQ_DOMAIN_FLAG_ISOLATED_MSI. See for an explanation how it works:
9+
*
10+
* https://lore.kernel.org/r/[email protected]/
11+
*
12+
* Note this is less isolated than the ARM/x86 versions as userspace can trigger
13+
* MSI belonging to kernel devices within the same gisa.
14+
*/
15+
#define arch_is_isolated_msi() true
16+
17+
#endif

drivers/infiniband/hw/usnic/usnic_uiom.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int usnic_uiom_map_sorted_intervals(struct list_head *intervals,
277277
usnic_dbg("va 0x%lx pa %pa size 0x%zx flags 0x%x",
278278
va_start, &pa_start, size, flags);
279279
err = iommu_map(pd->domain, va_start, pa_start,
280-
size, flags, GFP_KERNEL);
280+
size, flags, GFP_ATOMIC);
281281
if (err) {
282282
usnic_err("Failed to map va 0x%lx pa %pa size 0x%zx with err %d\n",
283283
va_start, &pa_start, size, err);
@@ -294,7 +294,7 @@ static int usnic_uiom_map_sorted_intervals(struct list_head *intervals,
294294
usnic_dbg("va 0x%lx pa %pa size 0x%zx flags 0x%x\n",
295295
va_start, &pa_start, size, flags);
296296
err = iommu_map(pd->domain, va_start, pa_start,
297-
size, flags, GFP_KERNEL);
297+
size, flags, GFP_ATOMIC);
298298
if (err) {
299299
usnic_err("Failed to map va 0x%lx pa %pa size 0x%zx with err %d\n",
300300
va_start, &pa_start, size, err);

drivers/iommu/amd/iommu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,8 +2278,6 @@ static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
22782278
switch (cap) {
22792279
case IOMMU_CAP_CACHE_COHERENCY:
22802280
return true;
2281-
case IOMMU_CAP_INTR_REMAP:
2282-
return (irq_remapping_enabled == 1);
22832281
case IOMMU_CAP_NOEXEC:
22842282
return false;
22852283
case IOMMU_CAP_PRE_BOOT_PROTECTION:
@@ -3682,7 +3680,8 @@ int amd_iommu_create_irq_domain(struct amd_iommu *iommu)
36823680
}
36833681

36843682
irq_domain_update_bus_token(iommu->ir_domain, DOMAIN_BUS_AMDVI);
3685-
iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
3683+
iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT |
3684+
IRQ_DOMAIN_FLAG_ISOLATED_MSI;
36863685

36873686
if (amd_iommu_np_cache)
36883687
iommu->ir_domain->msi_parent_ops = &virt_amdvi_msi_parent_ops;

drivers/iommu/intel/iommu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4478,8 +4478,6 @@ static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
44784478
switch (cap) {
44794479
case IOMMU_CAP_CACHE_COHERENCY:
44804480
return true;
4481-
case IOMMU_CAP_INTR_REMAP:
4482-
return irq_remapping_enabled == 1;
44834481
case IOMMU_CAP_PRE_BOOT_PROTECTION:
44844482
return dmar_platform_optin();
44854483
case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:

drivers/iommu/intel/irq_remapping.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,8 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)
573573
}
574574

575575
irq_domain_update_bus_token(iommu->ir_domain, DOMAIN_BUS_DMAR);
576-
iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
576+
iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT |
577+
IRQ_DOMAIN_FLAG_ISOLATED_MSI;
577578

578579
if (cap_caching_mode(iommu->cap))
579580
iommu->ir_domain->msi_parent_ops = &virt_dmar_msi_parent_ops;

drivers/iommu/iommu.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/cc_platform.h>
3131
#include <trace/events/iommu.h>
3232
#include <linux/sched/mm.h>
33+
#include <linux/msi.h>
3334

3435
#include "dma-iommu.h"
3536

@@ -1904,6 +1905,29 @@ bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
19041905
}
19051906
EXPORT_SYMBOL_GPL(device_iommu_capable);
19061907

1908+
/**
1909+
* iommu_group_has_isolated_msi() - Compute msi_device_has_isolated_msi()
1910+
* for a group
1911+
* @group: Group to query
1912+
*
1913+
* IOMMU groups should not have differing values of
1914+
* msi_device_has_isolated_msi() for devices in a group. However nothing
1915+
* directly prevents this, so ensure mistakes don't result in isolation failures
1916+
* by checking that all the devices are the same.
1917+
*/
1918+
bool iommu_group_has_isolated_msi(struct iommu_group *group)
1919+
{
1920+
struct group_device *group_dev;
1921+
bool ret = true;
1922+
1923+
mutex_lock(&group->mutex);
1924+
list_for_each_entry(group_dev, &group->devices, list)
1925+
ret &= msi_device_has_isolated_msi(group_dev->dev);
1926+
mutex_unlock(&group->mutex);
1927+
return ret;
1928+
}
1929+
EXPORT_SYMBOL_GPL(iommu_group_has_isolated_msi);
1930+
19071931
/**
19081932
* iommu_set_fault_handler() - set a fault handler for an iommu domain
19091933
* @domain: iommu domain

drivers/iommu/iommufd/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ config IOMMUFD_VFIO_CONTAINER
2323
removed.
2424

2525
IOMMUFD VFIO container emulation is known to lack certain features
26-
of the native VFIO container, such as no-IOMMU support, peer-to-peer
26+
of the native VFIO container, such as peer-to-peer
2727
DMA mapping, PPC IOMMU support, as well as other potentially
2828
undiscovered gaps. This option is currently intended for the
2929
purpose of testing IOMMUFD with unmodified userspace supporting VFIO

drivers/iommu/iommufd/device.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <linux/iommufd.h>
55
#include <linux/slab.h>
66
#include <linux/iommu.h>
7-
#include <linux/irqdomain.h>
87

98
#include "io_pagetable.h"
109
#include "iommufd_private.h"
@@ -169,8 +168,7 @@ static int iommufd_device_setup_msi(struct iommufd_device *idev,
169168
* operation from the device (eg a simple DMA) cannot trigger an
170169
* interrupt outside this iommufd context.
171170
*/
172-
if (!device_iommu_capable(idev->dev, IOMMU_CAP_INTR_REMAP) &&
173-
!irq_domain_check_msi_remap()) {
171+
if (!iommu_group_has_isolated_msi(idev->group)) {
174172
if (!allow_unsafe_interrupts)
175173
return -EPERM;
176174

@@ -346,10 +344,6 @@ int iommufd_device_attach(struct iommufd_device *idev, u32 *pt_id)
346344
rc = iommufd_device_do_attach(idev, hwpt);
347345
if (rc)
348346
goto out_put_pt_obj;
349-
350-
mutex_lock(&hwpt->ioas->mutex);
351-
list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list);
352-
mutex_unlock(&hwpt->ioas->mutex);
353347
break;
354348
}
355349
case IOMMUFD_OBJ_IOAS: {

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct iommufd_ctx {
1818
struct xarray objects;
1919

2020
u8 account_mode;
21+
/* Compatibility with VFIO no iommu */
22+
u8 no_iommu_mode;
2123
struct iommufd_ioas *vfio_ioas;
2224
};
2325

drivers/iommu/iommufd/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ union ucmd_buffer {
252252
struct iommu_destroy destroy;
253253
struct iommu_ioas_alloc alloc;
254254
struct iommu_ioas_allow_iovas allow_iovas;
255+
struct iommu_ioas_copy ioas_copy;
255256
struct iommu_ioas_iova_ranges iova_ranges;
256257
struct iommu_ioas_map map;
257258
struct iommu_ioas_unmap unmap;
259+
struct iommu_option option;
260+
struct iommu_vfio_ioas vfio_ioas;
258261
#ifdef CONFIG_IOMMUFD_TEST
259262
struct iommu_test_cmd test;
260263
#endif

0 commit comments

Comments
 (0)