Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5bfd16f authored by Liam Mark's avatar Liam Mark
Browse files

iommu: iommu-debug: cleanup iommu debug



Only expose debugfs nodes for test devices.
Restrict secure attach to a valid vmid.
Add clock reference counting to make code more robust.
Restrict address printing with kptr_restrict.

Change-Id: Ibf90068d778b0156e3bb42287af5dda3864da5fc
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 778f546f
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -170,6 +170,8 @@ struct iommu_debug_device {
	u64 phys;
	size_t len;
	struct list_head list;
	struct mutex clk_lock;
	unsigned int clk_count;
};

static int iommu_debug_build_phoney_sg_table(struct device *dev,
@@ -1278,7 +1280,7 @@ static int iommu_debug_attach_do_attach(struct iommu_debug_device *ddev,
	}

	ddev->domain->is_debug_domain = true;

	val = VMID_CP_CAMERA;
	if (is_secure && iommu_domain_set_attr(ddev->domain,
					       DOMAIN_ATTR_SECURE_VMID,
					       &val)) {
@@ -1638,6 +1640,10 @@ static ssize_t iommu_debug_atos_read(struct file *file, char __user *ubuf,
	ssize_t retval;
	size_t buflen;

	if (kptr_restrict != 0) {
		pr_err("kptr_restrict needs to be disabled.\n");
		return -EPERM;
	}
	if (!ddev->domain) {
		pr_err("No domain. Did you already attach?\n");
		return -EINVAL;
@@ -2132,20 +2138,34 @@ static ssize_t iommu_debug_config_clocks_write(struct file *file,
		return -EFAULT;
	}

	mutex_lock(&ddev->clk_lock);
	switch (buf) {
	case '0':
		if (ddev->clk_count == 0) {
			dev_err(dev, "Config clocks already disabled\n");
			break;
		}

		if (--ddev->clk_count > 0)
			break;

		dev_err(dev, "Disabling config clocks\n");
		iommu_disable_config_clocks(ddev->domain);
		break;
	case '1':
		if (ddev->clk_count++ > 0)
			break;

		dev_err(dev, "Enabling config clocks\n");
		if (iommu_enable_config_clocks(ddev->domain))
			dev_err(dev, "Failed!\n");
		break;
	default:
		dev_err(dev, "Invalid value. Should be 0 or 1.\n");
		mutex_unlock(&ddev->clk_lock);
		return -EINVAL;
	}
	mutex_unlock(&ddev->clk_lock);

	return count;
}
@@ -2195,6 +2215,9 @@ static int snarf_iommu_devices(struct device *dev, void *ignored)
	if (!of_find_property(dev->of_node, "iommus", NULL))
		return 0;

	if (!of_device_is_compatible(dev->of_node, "iommu-debug-test"))
		return 0;

	/* Hold a reference count */
	if (!iommu_group_get(dev))
		return 0;
@@ -2203,6 +2226,7 @@ static int snarf_iommu_devices(struct device *dev, void *ignored)
	if (!ddev)
		return -ENODEV;

	mutex_init(&ddev->clk_lock);
	ddev->dev = dev;
	dir = debugfs_create_dir(dev_name(dev), debugfs_tests_dir);
	if (!dir) {