android_kernel_samsung_sm8650/drivers/iommu/qcom-iommu-debug.h

77 lines
2.7 KiB
C
Raw Permalink Normal View History

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
qcom-iommu-debug: Fail incorrect fastmap usecases In the current iommu-debug fastmap test device, we map and unmap the entire iova range from 0..4G for each of the usecases. However for the following secure usecase: $ cd /sys/kernel/debug/iommu-test $ cat usecase $ echo 4 > usecase $ cat functional_fast_dma_api this mapping of iova range fails with following warning after about 496640 iterations of 8K-size mapping. batched_hyp_assign: Failed to assign memory protection, ret = -22 ------------[ cut here ]------------ failed to assign memory to VMID: 10 rc:-99 WARNING: CPU: 0 PID: 240 at drivers/iommu/qcom-io-pgtable-alloc.c:39 qcom_io_pgtable_alloc_page+0x110/0x120 Once this happens the memory is no longer usable by HLOS (according to following comments batched_hyp_assign(): 344 if (ret) { 345 pr_info("%s: Failed to assign memory protection, ret= %d\n", 346 __func__, ret); 347 /* 348 * Make it clear to clients that the memory may no 349 * longer be in a usable state. 350 */ 351 ret = -EADDRNOTAVAIL; 352 break; 353 } To run any other usecase, we must first destroy the device and recreate it. But when destroying the device, we get the following warning continuously (presumably for the 496640 mappings that succeeded): ------------[ cut here ]------------ failed to unassign memory from VMID: 10 rc: -99 WARNING: CPU: 0 PID: 240 at drivers/iommu/qcom-io-pgtable-alloc.c:54 io_pgtable_pool_release+0x1b8/0x24c Call trace: io_pgtable_pool_release+0x1b8/0x24c qcom_io_pgtable_allocator_unregister+0x5c/0xa8 arm_lpae_free_pgtable+0x30/0x4c qcom_free_io_pgtable_ops+0x80/0xa4 arm_smmu_destroy_domain_context+0xd0/0x1ec arm_smmu_domain_free+0x34/0x50 iommu_group_release+0x5c/0xa8 kobject_cleanup+0x78/0x1dc kobject_cleanup+0xd8/0x1dc kobject_put+0x68/0xa8 iommu_group_remove_device+0x114/0x184 iommu_release_device+0x48/0x8c iommu_bus_notifier+0x4c/0xa4 blocking_notifier_call_chain+0x5c/0xa8 device_del+0x2d8/0x3d4 platform_device_unregister+0x34/0xb4 of_platform_device_destroy+0xac/0xe4 iommu_debug_switch_usecase+0x38/0x194 iommu_debug_usecase_reset+0x18/0x28 iommu_debug_functional_fast_dma_api_show+0x13e8/0x1538 IOW, the device is unusable and requires a reboot. Its not clear what the behavior should be for a fastmap test on a non-fastmap device. For now, detect an invalid usecase and fail cleanly. Change-Id: I77b827825215f262e836e8902143ea297448612e Signed-off-by: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>
2022-09-16 15:15:19 +09:00
* Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
*/
#ifndef __DRIVERS_IOMMU_QCOM_IOMMU_DEBUG_H__
#define __DRIVERS_IOMMU_QCOM_IOMMU_DEBUG_H__
#include <linux/device.h>
#include <linux/debugfs.h>
#include <linux/iommu.h>
#include <linux/completion.h>
#include <linux/mutex.h>
#define MSI_IOVA_BASE 0x8000000
#define MSI_IOVA_LENGTH 0x100000
#define ARM_SMMU_SMR_ID GENMASK(15, 0)
struct iommu_debug_device {
struct device *self;
u32 nr_children;
char *buffer;
struct dentry *root_dir;
/* for usecase under test */
struct device *test_dev;
struct iommu_domain *domain;
u32 usecase_nr;
qcom-iommu-debug: Fail incorrect fastmap usecases In the current iommu-debug fastmap test device, we map and unmap the entire iova range from 0..4G for each of the usecases. However for the following secure usecase: $ cd /sys/kernel/debug/iommu-test $ cat usecase $ echo 4 > usecase $ cat functional_fast_dma_api this mapping of iova range fails with following warning after about 496640 iterations of 8K-size mapping. batched_hyp_assign: Failed to assign memory protection, ret = -22 ------------[ cut here ]------------ failed to assign memory to VMID: 10 rc:-99 WARNING: CPU: 0 PID: 240 at drivers/iommu/qcom-io-pgtable-alloc.c:39 qcom_io_pgtable_alloc_page+0x110/0x120 Once this happens the memory is no longer usable by HLOS (according to following comments batched_hyp_assign(): 344 if (ret) { 345 pr_info("%s: Failed to assign memory protection, ret= %d\n", 346 __func__, ret); 347 /* 348 * Make it clear to clients that the memory may no 349 * longer be in a usable state. 350 */ 351 ret = -EADDRNOTAVAIL; 352 break; 353 } To run any other usecase, we must first destroy the device and recreate it. But when destroying the device, we get the following warning continuously (presumably for the 496640 mappings that succeeded): ------------[ cut here ]------------ failed to unassign memory from VMID: 10 rc: -99 WARNING: CPU: 0 PID: 240 at drivers/iommu/qcom-io-pgtable-alloc.c:54 io_pgtable_pool_release+0x1b8/0x24c Call trace: io_pgtable_pool_release+0x1b8/0x24c qcom_io_pgtable_allocator_unregister+0x5c/0xa8 arm_lpae_free_pgtable+0x30/0x4c qcom_free_io_pgtable_ops+0x80/0xa4 arm_smmu_destroy_domain_context+0xd0/0x1ec arm_smmu_domain_free+0x34/0x50 iommu_group_release+0x5c/0xa8 kobject_cleanup+0x78/0x1dc kobject_cleanup+0xd8/0x1dc kobject_put+0x68/0xa8 iommu_group_remove_device+0x114/0x184 iommu_release_device+0x48/0x8c iommu_bus_notifier+0x4c/0xa4 blocking_notifier_call_chain+0x5c/0xa8 device_del+0x2d8/0x3d4 platform_device_unregister+0x34/0xb4 of_platform_device_destroy+0xac/0xe4 iommu_debug_switch_usecase+0x38/0x194 iommu_debug_usecase_reset+0x18/0x28 iommu_debug_functional_fast_dma_api_show+0x13e8/0x1538 IOW, the device is unusable and requires a reboot. Its not clear what the behavior should be for a fastmap test on a non-fastmap device. For now, detect an invalid usecase and fail cleanly. Change-Id: I77b827825215f262e836e8902143ea297448612e Signed-off-by: Sukadev Bhattiprolu <quic_sukadev@quicinc.com>
2022-09-16 15:15:19 +09:00
bool fastmap_usecase;
/* Protects test_dev */
struct mutex state_lock;
/* For waiting for child probe to complete */
struct completion probe_wait;
/* Used for atos */
u64 iova;
/* number of iterations */
u32 nr_iters;
};
struct device *iommu_debug_usecase_reset(struct iommu_debug_device *ddev);
struct device *iommu_debug_switch_usecase(struct iommu_debug_device *ddev, u32 usecase_nr);
int iommu_debug_check_mapping_flags(struct device *dev, dma_addr_t iova, size_t size,
phys_addr_t expected_pa, u32 flags);
#define iommu_debug_check_mapping(d, i, s, p) \
iommu_debug_check_mapping_flags(d, i, s, p, 0)
/* Only checks a single page */
#define iommu_debug_check_mapping_fast(d, i, s, p) \
iommu_debug_check_mapping_flags(d, i, PAGE_SIZE, p, 0)
int iommu_debug_check_mapping_sg_flags(struct device *dev, struct scatterlist *sgl,
unsigned int pgoffset, unsigned int dma_nents,
unsigned int nents, u32 flags);
#define iommu_debug_check_mapping_sg(d, s, o, e1, e2) \
iommu_debug_check_mapping_sg_flags(d, s, o, e1, e2, 0)
/* Only checks the last page of first sgl */
static inline int iommu_debug_check_mapping_sg_fast(struct device *dev, struct scatterlist *sgl,
unsigned int pgoffset, unsigned int dma_nents,
unsigned int nents)
{
pgoffset = PAGE_ALIGN(sgl->offset + sgl->length) >> PAGE_SHIFT;
return iommu_debug_check_mapping_sg_flags(dev, sgl, pgoffset - 1, dma_nents, 1, 0);
}
extern const struct file_operations iommu_debug_functional_arm_dma_api_fops;
extern const struct file_operations iommu_debug_functional_fast_dma_api_fops;
extern const struct file_operations iommu_debug_atos_fops;
extern const struct file_operations iommu_debug_map_fops;
extern const struct file_operations iommu_debug_unmap_fops;
extern const struct file_operations iommu_debug_dma_map_fops;
extern const struct file_operations iommu_debug_dma_unmap_fops;
extern const struct file_operations iommu_debug_test_virt_addr_fops;
extern const struct file_operations iommu_debug_profiling_fops;
#endif