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

Commit 9f583a52 authored by Mitchel Humpherys's avatar Mitchel Humpherys
Browse files

iommu/iommu-debug: Add secure_attach debugfs file



It can be useful to perform tests on secure domains.  Add support for
this with a "secure_attach" file that will also set the
DOMAIN_ATTR_SECURE_VMID to the value written to the file.

Example usage:

    # cd /sys/kernel/debug/iommu/tests/<device>
    # echo 0xA > secure_attach
    # echo 0x1000,0x1000,0x1000,1 > map
    # echo 0x1000,0x1000 > unmap
    # echo 0 > secure_attach

Change-Id: I0181e360f3e98e0e47a3af8c6adb71c9c4a3c9b5
Signed-off-by: default avatarMitchel Humpherys <mitchelh@codeaurora.org>
parent a11719cc
Loading
Loading
Loading
Loading
+50 −20
Original line number Diff line number Diff line
@@ -433,7 +433,8 @@ static const struct file_operations iommu_debug_profiling_fops = {
	.release = single_release,
};

static int iommu_debug_attach_do_attach(struct iommu_debug_device *ddev)
static int iommu_debug_attach_do_attach(struct iommu_debug_device *ddev,
					int val, bool is_secure)
{
	int htw_disable = 1;

@@ -450,6 +451,13 @@ static int iommu_debug_attach_do_attach(struct iommu_debug_device *ddev)
		goto out_domain_free;
	}

	if (is_secure && iommu_domain_set_attr(ddev->domain,
					       DOMAIN_ATTR_SECURE_VMID,
					       &val)) {
		pr_err("Couldn't set secure vmid to %d\n", val);
		goto out_domain_free;
	}

	if (iommu_attach_device(ddev->domain, ddev->dev)) {
		pr_err("Couldn't attach new domain to device. Is it already attached?\n");
		goto out_domain_free;
@@ -463,27 +471,22 @@ out_domain_free:
	return -EIO;
}

static ssize_t iommu_debug_attach_write(struct file *file,
static ssize_t __iommu_debug_attach_write(struct file *file,
					  const char __user *ubuf,
				      size_t count, loff_t *offset)
					  size_t count, loff_t *offset,
					  bool is_secure)
{
	struct iommu_debug_device *ddev = file->private_data;
	ssize_t retval;
	char val;

	if (count > 2) {
		pr_err("Invalid value.  Expected 0 or 1.\n");
		retval = -EINVAL;
		goto out;
	}
	int val;

	if (copy_from_user(&val, ubuf, 1)) {
		pr_err("Couldn't copy from user\n");
	if (kstrtoint_from_user(ubuf, count, 0, &val)) {
		pr_err("Invalid format. Expected a hex or decimal integer");
		retval = -EFAULT;
		goto out;
	}

	if (val == '1') {
	if (val) {
		if (ddev->domain) {
			pr_err("Already attached.\n");
			retval = -EINVAL;
@@ -494,12 +497,12 @@ static ssize_t iommu_debug_attach_write(struct file *file,
			retval = -EINVAL;
			goto out;
		}
		if (iommu_debug_attach_do_attach(ddev)) {
		if (iommu_debug_attach_do_attach(ddev, val, is_secure)) {
			retval = -EIO;
			goto out;
		}
		pr_err("Attached\n");
	} else if (val == '0') {
	} else {
		if (!ddev->domain) {
			pr_err("No domain. Did you already attach?\n");
			retval = -EINVAL;
@@ -509,10 +512,6 @@ static ssize_t iommu_debug_attach_write(struct file *file,
		iommu_domain_free(ddev->domain);
		ddev->domain = NULL;
		pr_err("Detached\n");
	} else {
		pr_err("Invalid value.  Expected 0 or 1\n");
		retval = -EFAULT;
		goto out;
	}

	retval = count;
@@ -520,6 +519,15 @@ out:
	return retval;
}

static ssize_t iommu_debug_attach_write(struct file *file,
					  const char __user *ubuf,
					  size_t count, loff_t *offset)
{
	return __iommu_debug_attach_write(file, ubuf, count, offset,
					  false);

}

static ssize_t iommu_debug_attach_read(struct file *file, char __user *ubuf,
				       size_t count, loff_t *offset)
{
@@ -546,6 +554,21 @@ static const struct file_operations iommu_debug_attach_fops = {
	.read	= iommu_debug_attach_read,
};

static ssize_t iommu_debug_attach_write_secure(struct file *file,
					       const char __user *ubuf,
					       size_t count, loff_t *offset)
{
	return __iommu_debug_attach_write(file, ubuf, count, offset,
					  true);

}

static const struct file_operations iommu_debug_secure_attach_fops = {
	.open	= simple_open,
	.write	= iommu_debug_attach_write_secure,
	.read	= iommu_debug_attach_read,
};

static ssize_t iommu_debug_atos_write(struct file *file,
				      const char __user *ubuf,
				      size_t count, loff_t *offset)
@@ -790,6 +813,13 @@ static int snarf_iommu_devices(struct device *dev, void *ignored)
		goto err_rmdir;
	}

	if (!debugfs_create_file("secure_attach", S_IRUSR, dir, ddev,
				 &iommu_debug_secure_attach_fops)) {
		pr_err("Couldn't create iommu/devices/%s/secure_attach debugfs file\n",
		       dev_name(dev));
		goto err_rmdir;
	}

	if (!debugfs_create_file("atos", S_IWUSR, dir, ddev,
				 &iommu_debug_atos_fops)) {
		pr_err("Couldn't create iommu/devices/%s/atos debugfs file\n",