mirror of
https://github.com/torvalds/linux.git
synced 2026-08-01 12:11:59 +02:00
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>
This commit is contained in:
parent
7ff9dff2e6
commit
b6ae4515d3
|
|
@ -1203,6 +1203,22 @@ static int iommu_debug_functional_fast_dma_api_show(struct seq_file *s,
|
|||
void *ignored)
|
||||
{
|
||||
int ret = 0;
|
||||
struct iommu_debug_device *ddev = s->private;
|
||||
|
||||
if (!ddev->test_dev) {
|
||||
pr_err("%s:Have you selected a uscase?\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!ddev->fastmap_usecase) {
|
||||
ps_printf(dev_name(ddev->test_dev), s,
|
||||
"Not a fastmap usecase\n");
|
||||
return 0;
|
||||
} else if (!IS_ENABLED(CONFIG_IOMMU_IO_PGTABLE_FAST)) {
|
||||
ps_printf(dev_name(ddev->test_dev), s,
|
||||
"CONFIG_IOMMU_IO_PGTABLE_FAST not enabled\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret |= __apply_to_new_mapping(s, __functional_dma_api_alloc_test, NULL);
|
||||
ret |= __apply_to_new_mapping(s, __functional_dma_api_basic_test, NULL);
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ iommu_debug_switch_usecase(struct iommu_debug_device *ddev, u32 usecase_nr)
|
|||
{
|
||||
struct platform_device *test_pdev;
|
||||
struct device_node *child;
|
||||
const char *str;
|
||||
int child_nr = 0;
|
||||
int ret;
|
||||
|
||||
|
|
@ -169,6 +170,10 @@ iommu_debug_switch_usecase(struct iommu_debug_device *ddev, u32 usecase_nr)
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (of_property_read_string(child, "qcom,iommu-dma", &str))
|
||||
str = "default";
|
||||
|
||||
ddev->fastmap_usecase = !strcmp(str, "fastmap");
|
||||
ddev->usecase_nr = usecase_nr;
|
||||
ddev->test_dev = &test_pdev->dev;
|
||||
ddev->domain = iommu_get_domain_for_dev(ddev->test_dev);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __DRIVERS_IOMMU_QCOM_IOMMU_DEBUG_H__
|
||||
|
|
@ -26,6 +26,7 @@ struct iommu_debug_device {
|
|||
struct device *test_dev;
|
||||
struct iommu_domain *domain;
|
||||
u32 usecase_nr;
|
||||
bool fastmap_usecase;
|
||||
/* Protects test_dev */
|
||||
struct mutex state_lock;
|
||||
/* For waiting for child probe to complete */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user