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

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

Merge "iommu/debug: Add mutex to make attach/detach thread safe"

parents ff5fac3d ba826181
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1720,6 +1720,7 @@ static ssize_t iommu_debug_map_write(struct file *file, const char __user *ubuf,
	if (kstrtoint(comma3 + 1, 0, &prot))
		goto invalid_format;

	mutex_lock(&ddev->dev_lock);
	ret = iommu_map(ddev->domain, iova, phys, size, prot);
	if (ret) {
		pr_err("iommu_map failed with %d\n", ret);
@@ -1731,6 +1732,7 @@ static ssize_t iommu_debug_map_write(struct file *file, const char __user *ubuf,
	pr_err("Mapped %pa to %pa (len=0x%zx, prot=0x%x)\n",
	       &iova, &phys, size, prot);
out:
	mutex_unlock(&ddev->dev_lock);
	return retval;

invalid_format:
@@ -1818,14 +1820,17 @@ static ssize_t iommu_debug_dma_map_write(struct file *file,
	else
		goto invalid_format;

	mutex_lock(&ddev->dev_lock);
	iova = dma_map_single_attrs(dev, v_addr, size,
					DMA_TO_DEVICE, dma_attrs);

	if (dma_mapping_error(dev, iova)) {
		pr_err("Failed to perform dma_map_single\n");
		ret = -EINVAL;
		mutex_unlock(&ddev->dev_lock);
		goto out;
	}
	mutex_unlock(&ddev->dev_lock);

	retval = count;
	pr_err("Mapped 0x%p to %pa (len=0x%zx)\n",
@@ -1932,12 +1937,15 @@ static ssize_t iommu_debug_unmap_write(struct file *file,
	if (kstrtosize_t(comma1 + 1, 0, &size))
		goto invalid_format;

	mutex_lock(&ddev->dev_lock);
	unmapped = iommu_unmap(ddev->domain, iova, size);
	if (unmapped != size) {
		pr_err("iommu_unmap failed. Expected to unmap: 0x%zx, unmapped: 0x%zx",
		       size, unmapped);
		mutex_unlock(&ddev->dev_lock);
		return -EIO;
	}
	mutex_unlock(&ddev->dev_lock);

	retval = count;
	pr_err("Unmapped %pa (len=0x%zx)\n", &iova, size);
@@ -2023,7 +2031,9 @@ static ssize_t iommu_debug_dma_unmap_write(struct file *file,
	else
		goto invalid_format;

	mutex_lock(&ddev->dev_lock);
	dma_unmap_single_attrs(dev, iova, size, DMA_TO_DEVICE, dma_attrs);
	mutex_unlock(&ddev->dev_lock);

	retval = count;
	pr_err("Unmapped %pa (len=0x%zx)\n", &iova, size);