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

Commit 3af6f933 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "iommu/iommu-debug: Add secure_attach debugfs file"

parents f1ee29c8 9f583a52
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2278,6 +2278,10 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain,
				(1 << DOMAIN_ATTR_COHERENT_HTW_DISABLE));
		ret = 0;
		break;
	case DOMAIN_ATTR_SECURE_VMID:
		*((int *)data) = smmu_domain->secure_vmid;
		ret = 0;
		break;
	case DOMAIN_ATTR_PT_BASE_ADDR:
		*((phys_addr_t *)data) =
			smmu_domain->pgtbl_cfg.arm_lpae_s1_cfg.ttbr[0];
+61 −20
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <soc/qcom/secure_buffer.h>

#ifdef CONFIG_IOMMU_DEBUG_TRACKING

@@ -40,6 +41,7 @@ static int iommu_debug_attachment_info_show(struct seq_file *s, void *ignored)
	struct iommu_debug_attachment *attach = s->private;
	phys_addr_t pt_phys;
	int coherent_htw_disable;
	int secure_vmid;

	seq_printf(s, "Domain: 0x%p\n", attach->domain);
	if (iommu_domain_get_attr(attach->domain, DOMAIN_ATTR_PT_BASE_ADDR,
@@ -60,6 +62,15 @@ static int iommu_debug_attachment_info_show(struct seq_file *s, void *ignored)
	else
		seq_printf(s, "%d\n", coherent_htw_disable);

	seq_puts(s, "SECURE_VMID: ");
	if (iommu_domain_get_attr(attach->domain,
				  DOMAIN_ATTR_SECURE_VMID,
				  &secure_vmid))
		seq_puts(s, "(Unknown)\n");
	else
		seq_printf(s, "%s (0x%x)\n",
			   msm_secure_vmid_to_string(secure_vmid), secure_vmid);

	return 0;
}

@@ -422,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;

@@ -439,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;
@@ -452,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;
@@ -483,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;
@@ -498,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;
@@ -509,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)
{
@@ -535,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)
@@ -779,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",
+32 −0
Original line number Diff line number Diff line
@@ -347,6 +347,38 @@ err1:
	return ret;
}

const char *msm_secure_vmid_to_string(int secure_vmid)
{
	switch (secure_vmid) {
	case VMID_HLOS:
		return "VMID_HLOS";
	case VMID_CP_TOUCH:
		return "VMID_CP_TOUCH";
	case VMID_CP_BITSTREAM:
		return "VMID_CP_BITSTREAM";
	case VMID_CP_PIXEL:
		return "VMID_CP_PIXEL";
	case VMID_CP_NON_PIXEL:
		return "VMID_CP_NON_PIXEL";
	case VMID_CP_CAMERA:
		return "VMID_CP_CAMERA";
	case VMID_HLOS_FREE:
		return "VMID_HLOS_FREE";
	case VMID_MSS_MSA:
		return "VMID_MSS_MSA";
	case VMID_MSS_NONMSA:
		return "VMID_MSS_NONMSA";
	case VMID_CP_SEC_DISPLAY:
		return "VMID_CP_SEC_DISPLAY";
	case VMID_CP_APP:
		return "VMID_CP_APP";
	case VMID_INVAL:
		return "VMID_INVAL";
	default:
		return "Unknown VMID";
	}
}

#define MAKE_CP_VERSION(major, minor, patch) \
	(((major & 0x3FF) << 22) | ((minor & 0x3FF) << 12) | (patch & 0xFFF))

+9 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@
#define VMID_CP_SEC_DISPLAY 0x11
#define VMID_CP_APP 0x12
#define VMID_INVAL -1
/*
 * if you add a secure VMID here make sure you update
 * msm_secure_vmid_to_string
 */

#define PERM_READ                       0x4
#define PERM_WRITE                      0x2
@@ -44,6 +48,7 @@ int hyp_assign_phys(phys_addr_t addr, u64 size,
			u32 *source_vmlist, int source_nelems,
			int *dest_vmids, int *dest_perms, int dest_nelems);
bool msm_secure_v2_is_supported(void);
const char *msm_secure_vmid_to_string(int secure_vmid);
#else
static inline int msm_secure_table(struct sg_table *table)
{
@@ -70,5 +75,9 @@ static inline bool msm_secure_v2_is_supported(void)
{
	return false;
}
const char *msm_secure_vmid_to_string(int secure_vmid)
{
	return "N/A";
}
#endif
#endif