Doing a cat on pte,test_virt_addr from adb shell prints a null
character as well which is at the end of the string this is not
required so, don't pass this null character to copy_to_user.
Change-Id: I8d9120f64d1df84a704379eb00bd239fc7059e9e
Signed-off-by: Vijayanand Jitta <vjitta@codeaurora.org>
The kernel buffer 'ubuf' can overflow while copying data to user
space in debugfs read functions. Fix it by limiting the length of
data to be copied to userspace.
Change-Id: Ibb3d8c4fb637ddc0e63677ec2dff14a4cf8c0c73
Signed-off-by: Srinivasarao P <spathi@codeaurora.org>
This mutex lock will help to synchronise the usage of iommu domain
structure which is getting used by multiple threads to perform
iommu attach and iommu detach in case of any error.
Without this change we are seeing page poisoning - write after free
when running stress tests using iommu-debug test cases.
Change-Id: I388a90084ab8cc7e7097bac9a41ed5fed6dad312
Acked-by: Ankur Saxena <c_ankusa@qti.qualcomm.com>
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Signed-off-by: VENKATA RAO KAKANI <vkakani@codeaurora.org>
This mutex lock will help to synchronise the usage of iommu domain
structure which is getting used by multiple threads to perform
iommu attach and iommu detach in case of any error.
Without this change we are seeing page poisoning - write after free
when running stress tests using iommu-debug test cases.
Change-Id: I1033808a510786577c41201c2a6a330e5465d4d1
Acked-by: Ankur Saxena <c_ankusa@qti.qualcomm.com>
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Update pte and dma atos debugfs nodes to be inline
with other iommu debugfs nodes and only expose memory
addresses when kptr_restrict is disabled.
Change-Id: I46d5de498b811b4874be570aea7b41461b9a1a98
Signed-off-by: Liam Mark <lmark@codeaurora.org>
Only expose debugfs nodes for test devices.
Restrict secure attach to a valid vmid.
Add clock reference counting to make code more robust.
Restrict address printing with kptr_restrict.
Change-Id: Ibf90068d778b0156e3bb42287af5dda3864da5fc
Signed-off-by: Liam Mark <lmark@codeaurora.org>
If CONFIG_IOMMU_DEBUG_TRACKING=y, a deadlock will occur if userspace
writes to the debugfs file "attach":
-001|context_switch(inline)
-001|__schedule()
-002|__preempt_count_sub(inline)
-002|schedule()
-003|schedule_timeout()
-004|do_wait_for_common(inline)
-004|__wait_for_common(inline)
-004|wait_for_common()
-005|wait_for_completion()
-006|__synchronize_srcu()
-007|synchronize_srcu()
-008|debugfs_remove_recursive()
-009|iommu_debug_detach_device()
-010|__iommu_detach_device()
-011|__iommu_group_for_each_dev(inline)
-011|__iommu_detach_group()
-012|iommu_detach_device()
-013|iommu_debug_device_profiling()
-014|iommu_debug_device_show()
-015|seq_read()
-016|full_proxy_read()
-017|__vfs_read()
-018|vfs_read()
Since the files in the attachment directory are rarely used, remove
them. Update the data saved by this config option to work properly
with iommu groups.
Change-Id: I3f0f1d0836f37412915ce3e78d8aefe92dc8d096
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
[lmark@codeaurora.org: deadlock is not an issue on this branch
but this change is backported because there are security benefits
from removing the iommu debugfs attachments nodes, such as removing
register access.]
Signed-off-by: Liam Mark <lmark@codeaurora.org>
Added new debugfs files/nodes to perform basic validation of the
per-buffer IO coherent dma-mapping that was recently implemented.
Also, added a node to print out the PTE for a given IOVA.
Nodes added:
dma_attach
dma_map
dma_unmap
dma_atos
virt_addr
pte
Change-Id: I041ab5f4e37e50dd3f58e2def3fdd3125a60629c
Signed-off-by: Sudarshan Rajagopalan <sudaraja@codeaurora.org>
Disable the SMMU stalls on faulty transactions by terminating it using
the CB.SCTLR register. Faulty transaction on a CB causes the back
pressure on the QSMMU transaction pipe which inturn affect the other
masters using the same SMMU. Pass the DOMAIN_ATTR_CB_STALL_DISABLE flag
to iommu_domain_set_attr api in order to use this feature.
Change-Id: Ib8fa35854ff24e0295d330c5fb79375f58c3e841
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
With fast mapping, the iova range is zero in the absence of
mapping object from the client. In such case, set the iova
space using the DOMAIN_ATTR_GEOMETRY dommain attribute.
CRs-Fixed: 2020868
Change-Id: I28790728c02ecb2d0a921bf5a218fb8b16662619
Signed-off-by: Sudarshan Rajagopalan <sudaraja@codeaurora.org>
It's hard to tell whether ATOS failed due to a misconfiguration in
hardware or software. Add a software table walk to help narrow down the
reasons for the failure. If the software walk succeeds then there's
something wrong in hardware. If the software walk fails then there's
something wrong in software.
CRs-Fixed: 1014916
Change-Id: I49dd61856ad08e1890791b3e5c180350a5eaa648
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
io-pgtable-fast was implemented to achieve
better performance for IOMMU map/un-map. Add
DMA API support that goes through io-pgtable-fast
for 32 bit targets.
Change-Id:I3d0560a4331f6b7b87c70d0885df11d12cb1d6ec
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Pass the proper VMID value during secure attach. This VMID is used by
the HYP/TZ to maintain the pagetables.
Change-Id: I3b7c27c079b044c9325bcbcb6fa4312e424f3a94
Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
Iommu addresses are unsigned numbers. Therefore use the unsigned variants
of the kstrto*_from_user functions.
Change-Id: I9a34d522a8dc7e2efca95b5a1ccb6a7a2e260b42
Reported-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
For performance reasons there are clients who would like to move
from stage 1 bypass to stage 1 enabled without having to stop their
device.
Currently clients need to stop their device because they have to
create the required stage 1 mappings before re-enabling the device.
Add the new DOMAIN_ATTR_EARLY_MAP domain attribute to allow clients
to create stage 1 mappings after attaching but before enabling
stage 1 translations.
If the clients set the DOMAIN_ATTR_EARLY_MAP domain attribute to 1
before attaching then then once they attach the SMMU driver won't
enable stage 1 translations. This gives the client the opportunity to
create the required early mappings (for example using iommu_map).
When the client has finished creating the necessary early mappings
the client can then set the DOMAIN_ATTR_EARLY_MAP domain attribute
to 0, this will in turn enable stage 1 translations.
Change-Id: I9e95c5d2130f1d371e201eac69dec140cc773b1f
Signed-off-by: Liam Mark <lmark@codeaurora.org>
The DOMAIN_ATTR_COHERENT_HTW_DISABLE IOMMU domain attribute is being
removed. SMMU coherency will be configured through the SMMU device tree
nodes moving forward. Remove the obsolete option.
Change-Id: If1251c945d71f8a7ab7c8e62c8a3d9d9139495ab
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Currently iommu-debug was enable only for 64 bit
targets as there were compilation issues coming
up while enabling it for 32 bit. Fix these issues
to ensure that we can use it on 32 bit targets
too.
Change-Id: If230af86f2fdd12fb5396f3b4736e57a123422bd
Signed-off-by: Susheel Khiani <skhiani@codeaurora.org>
Initialize return values to their default before being
used.
Change-Id: Ie4dd908657573e5110bce65931d5507125da4c40
Signed-off-by: Shiraz Hashim <shashim@codeaurora.org>
It's fairly common while debugging to need to enable the config clocks
for an SMMU so that you can poke around at the registers. Add a debugfs
file to do this.
CRs-Fixed: 997751
Change-Id: I31b90d64c2facb0a681f9da586e2c90803776819
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The vanilla ARM DMA IOMMU mapper is used by many clients in our system,
but we have no functional test coverage of it. Add some functional
testing for it by leveraging the tests that were recently added for the
Fast DMA mapper. Since the Fast mapper and the ARM mapper are both DMA
API implementations we can share most of the code.
CRs-Fixed: 997751
Change-Id: I58734a82f4dc3e4658ab7995b6682205097da991
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Functional tests are good. Add some for the fast DMA mapper.
CRs-Fixed: 997751
Change-Id: Iefb80124c335d65ea5bd8a15406c685125030003
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The fast DMA API implementation that was recently needs to be profiled.
Add a new debugfs file (similar to the original "profiling" file) to do
this.
CRs-Fixed: 997751
Change-Id: I1236d9b6aaeab9d34b39e7f5d7b285691d1779da
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
We'd like to understand the performance of the fast page table mapper,
which only supports 4K page sizes. Add a debugfs file to profile the
new mapper.
CRs-Fixed: 997751
Change-Id: I5adc3c3ecd432552386b600b9e66e3db42e73138
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Current list of domains in iommu-debug was only
maintained during attach/detach calls. But for
masters like graphics this won't account for all
the domains, as it allocates multiple different
domains but attaches only one domain at a time.
Add support for maintaining list of unattached
domains too by adding them to debug_attachments
list during domain alloc but keeping dev as NULL.
We would add entry in debugfs attachment directory
only on actual attach call.
Change-Id: Ifde043e5c39f356b4187a30cbdf020ee943618f1
Signed-off-by: Susheel Khiani <skhiani@codeaurora.org>
The IOMMU test framework relies on the `iommus' property, and we
currently rely on these methods for making that happen:
(1) Clients enabling their DT nodes.
(2) We put an `iommus' property in our IOMMU DT nodes themselves.
The problem with (1) is that clients aren't always ready during early
chip validation. The problem with (2) is that it results in us
recursively mapping into the SMMU when we try to do cache maintenance on
our page table memory.
Fix these problems by introducing a dummy driver with associated device
tree bindings that will do absolutely nothing other than wait for the
SMMU driver and IOMMU test framework to slurp it up.
CRs-Fixed: 1003233
Change-Id: I6a5802aff5bab99d29c6ed9d953a203cbd8015bb
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Fix some variable initializations which would otherwise cause
forbidden warnings.
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
Print time with ns precision.
Ex:
size iommu_map iommu_unmap
4K 43.021 us 99.479 us
Change-Id: Ib7f3db2be533c77adf0a20de557615a0e2433dd9
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
Add a nr_iters file which specifies the number of runs to average
performance over. Alternatively, setting this to 1 allows the user
to collect raw data.
Change-Id: Ifab7215027b597fb2650ab2f0c5065bebe0b8c5d
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
Currently we only take one sample per buffer size per API when doing
profiling. This results in high run-to-run variance in the results.
Use more iterations to help smooth this out.
Change-Id: I3779007a2f69ef79b573285b2422554f42dda99f
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Secure domains do different amounts of work than non-secure domains, so
we need to be able to profile them separately. Add another debugfs
file, "secure_profiling", that does the same thing as the "profiling"
file.
Change-Id: I6968036bfdcc63449f27336771b3956a2b7754f6
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The subdirectories under "attach" currently get a UUID appended to their
name to ensure that there won't be any collisions when multiple domains
are attached to the same device. This is only needed for dynamic
domains since those are the only types of domains that can be attached
to the same device concurrently. Only do the uniquification for dynamic
domains since the resulting directory name is a bit messy with the UUID.
Change-Id: Ia86b192e5b9d6a63132228fa86549a2977ec74a4
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
There's some non-deterministic latency incurred by enabling clocks and
regulators. Clocks and regulators are left on for atomic domains, which
makes them a good choice for profiling the page table management code.
Use an atomic domain for map/unmap profiling to make things more
deterministic.
Change-Id: Ib9fa48699c9d6009dd3f3b322002e2fb0f2ff99c
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
It can be useful to read and modify SMMU settings interactively. Add a
debugfs interface for the recently added iommu_reg_read and
iommu_reg_write functions for this purpose.
Change-Id: If3c9bf1833dc950c7ca1e2ce1a373bcaa31ebcf0
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
iommu_trigger_fault now accepts a flags argument which can be handled by
the individual IOMMU drivers. Take the value written to the debugfs
file by the user and pass it as the flags value.
Change-Id: I803e6585aea35fbb0f6e03e4279587b36a7bad92
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
IOMMU drivers might want more control over the types of faults being
triggered with iommu_trigger_fault. Add a flags parameter that can be
used to provide more control over the types of faults that can be
triggered.
Change-Id: I2f21b383437430e957ab52070d3575e8cb3dee90
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
MSM iommu devices' DT bindings defer from upstream
way. And hence, the debug driver doesn't support
to profile MSM iommu devices. Add that support.
Change-Id: I507d500785408b1d96f017648475933ee408b664
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
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: Mitchel Humpherys <mitchelh@codeaurora.org>
It can be useful to know a domain's secure VMID value. Add this
information to the attach info debugfs file.
Change-Id: Ic8a73000b8337639f95376b13ef58a0e2a089dde
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The unmap debugfs file write handler is currently incorrectly parsing
the size to be unmapped (storing the IOVA as the size). Fix this by
parsing from the correct offset (just after the first comma).
Change-Id: I438851882052acc511c713706bc4f0cbf373353e
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Currently we're creating an "iommu" debugfs directory from the
iommu-debug code. Other IOMMU modules might want to make use of this
same directory, so create it from the IOMMU framework code itself.
Change-Id: I679fdfc34ba5fcbd927dc5981438c6fabcfa3639
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The attachment tracking code adds a node to debugfs every time a client
attaches a domain to an IOMMU device. The problem is that clients can
start making those attachments during early boot, before iommu-debug
initializes (including setting up the root debugfs directory for the
attachment tracking), which means they get stuck in the root debugfs
directory. Trying to initialize iommu-debug earlier than all possible
IOMMU clients is tricky, so fix this by only installing debugfs entries
onces we've initialized, installing debugfs entries for any early
attachments at initialization time.
Change-Id: I8364015346105187e0c8f787fc2b4155d72b3584
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
It can be useful during development to trigger faults. Add a debugfs
file to do so.
Change-Id: Ic7b304ef0d908ebd506979f0c87189e34d7dfc67
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
It can be useful to check whether or not coherent hardware table walking
has been explicitly disabled on attached domains. Add this to the
attach info debugfs file.
Change-Id: I432303ecb734d32eaa02038694daad0d8c4d8aba
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Currently IOMMU attachment info is available in debugfs files located at
<debugfs_root>/iommu/attachments/<attached_device>. However, there are
more actions that can be taken on attached devices besides just printing
their info. Make room for more debugfs files for attached devices by
creating a directory for each one, and move the existing info file to:
<debugfs_root>/iommu/attachments/<attached_device>/info.
Change-Id: Ia56efc3aeb5e82afc34314fe48aaa0cd6e5579be
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
Currently the debug device structure is allocated with kmalloc, without
initializing all of the fields in the structure. Later, those fields
might be uses before they've every been assigned. For example, if a user
executes the following code on a fresh boot:
# cd /sys/kernel/debug/iommu/tests/some_device
# echo 0 > attach
The kernel crashes with something like this (assuming page poisoning is
enabled):
Unable to handle kernel paging request at virtual address aaaaaaaaaaaaaaaa
pgd = ffffffc0a92a1000
[aaaaaaaaaaaaaaaa] *pgd=0000000000000000, *pud=0000000000000000
Fix this by initializing all the fields in the structure to 0 by using
kzalloc instead of kmalloc.
Change-Id: I3514bf7bf174e176ff7a310c7134d0f53e22d771
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
The functions for iommu/devices/<device>/profiling don't actually have
the word `profiling' in the name, which will be confusing as we add more
files to that directory. Rename them for clarity.
Change-Id: Ic57d9400d8784d2cbd667185c5b2b0e1275461dd
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>