From: magnus.damm@gmail.com (Magnus Damm)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH/RFC v2 3/4] iommu/ipmmu-vmsa: Check devices in xlate()
Date: Fri, 27 Jan 2017 15:14:36 +0900 [thread overview]
Message-ID: <148549767671.22203.10735883809069203556.sendpatchset@little-apple> (raw)
In-Reply-To: <148549764733.22203.16459470412085471955.sendpatchset@little-apple>
From: Magnus Damm <damm+renesas@opensource.se>
Rework the IPMMU code to validate devices in ->xlate() instead of
accepting all devices in xlate() and instead validating devices
in ->add_device(). This makes it possible for the IPMMU device
driver to reject slave devices based on software policy.
Once a slave device is rejected by the ->xlate() callback the shared
function of_iommu_configure() will fail as well which in turn disables
per-device IOMMU handing in the arch-specific mapping code by not
passing any IOMMU callbacks to arch_setup_dma_ops().
Signed-off-by: Magnus Damm <damm+renesas@opensource.se>
---
TODO: Make sure this does not break R-Car Gen2 support
drivers/iommu/ipmmu-vmsa.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
--- 0007/drivers/iommu/ipmmu-vmsa.c
+++ work/drivers/iommu/ipmmu-vmsa.c 2017-01-27 13:11:35.970607110 +0900
@@ -1007,16 +1007,14 @@ static int ipmmu_add_device_dma(struct d
struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
struct iommu_group *group;
- /* only accept devices with iommus property */
- if (of_count_phandle_with_args(dev->of_node, "iommus",
- "#iommu-cells") < 0)
+ /* The device needs to be verified in xlate() */
+ if (!archdata)
return -ENODEV;
group = iommu_group_get_for_dev(dev);
if (IS_ERR(group))
return PTR_ERR(group);
- archdata = dev->archdata.iommu;
spin_lock(&ipmmu_slave_devices_lock);
list_add(&archdata->list, &ipmmu_slave_devices);
spin_unlock(&ipmmu_slave_devices_lock);
@@ -1034,24 +1032,13 @@ static void ipmmu_remove_device_dma(stru
iommu_group_remove_device(dev);
}
-static struct iommu_group *ipmmu_device_group_dma(struct device *dev)
-{
- struct iommu_group *group;
- int ret;
-
- ret = ipmmu_init_platform_device(dev);
- if (!ret)
- group = ipmmu_find_group(dev);
- else
- group = ERR_PTR(ret);
-
- return group;
-}
-
static int ipmmu_of_xlate_dma(struct device *dev,
struct of_phandle_args *spec)
{
- return 0;
+ /* For now only tested on R-Car Gen3 with ARM64 arch init order
+ * TODO: Test R-Car Gen2 with ARM32 arch init order
+ */
+ return ipmmu_init_platform_device(dev);
}
static const struct iommu_ops ipmmu_ops = {
@@ -1065,7 +1052,7 @@ static const struct iommu_ops ipmmu_ops
.iova_to_phys = ipmmu_iova_to_phys,
.add_device = ipmmu_add_device_dma,
.remove_device = ipmmu_remove_device_dma,
- .device_group = ipmmu_device_group_dma,
+ .device_group = ipmmu_find_group,
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
.of_xlate = ipmmu_of_xlate_dma,
};
next prev parent reply other threads:[~2017-01-27 6:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-27 6:14 [PATCH/RFC v2 0/4] iommu/ipmmu-vmsa: IPMMU slave device whitelist V2 Magnus Damm
2017-01-27 6:14 ` [PATCH/RFC v2 1/4] iommu/of: Skip IOMMU devices disabled in DT Magnus Damm
2017-01-27 6:14 ` [PATCH/RFC v2 2/4] iommu/ipmmu-vmsa: Get rid of disabled device check Magnus Damm
2017-01-27 6:14 ` Magnus Damm [this message]
2017-01-27 6:14 ` [PATCH/RFC v2 3/4] iommu/ipmmu-vmsa: Opt-in slave devices based on ES version Magnus Damm
2017-03-06 9:00 ` [PATCH/RFC v2 0/4] iommu/ipmmu-vmsa: IPMMU slave device whitelist V2 Magnus Damm
2017-03-22 14:25 ` Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=148549767671.22203.10735883809069203556.sendpatchset@little-apple \
--to=magnus.damm@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox