Commit graph

564592 commits

Author SHA1 Message Date
Mitchel Humpherys
880ae03739 iommu/arm-smmu: Add getter for DOMAIN_ATTR_SECURE_VMID
It can be useful to query a previously set secure VMID.  Add a domain
attribute getter for this.

Change-Id: Iaf14201d321161ce4ccc69b674a3b1247d6a7e94
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:43 -07:00
Neeti Desai
3dfe618eb3 msm: Update the permissions while making assign call
When memory that is assigned a particular VMID is re-assigned
back to HLOS, it needs to get RWX permissions so that HLOS can
use it for data as well as instructions.

Change-Id: Ib5413861de877d9081bdf5bd397f528293deb6e8
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2016-03-22 11:13:42 -07:00
Mitchel Humpherys
4a7ae76ea2 iommu/iommu-debug: Fix parsing of unmap size
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>
2016-03-22 11:13:41 -07:00
Mitchel Humpherys
d1f111a6f9 iommu/io-pgtable-arm: Don't leave dangling table entries
Currently, when all of the 4K PTEs beneath a 2M table entry are
unmapped, that 2M table entry is left intact, even though it doesn't
point to any valid 4K mappings anymore.  This results in a warning if a
subsequent block mapping lands on top of the dangling table entry, since
we require empty page table entries when we map.  It also causes the
page at which that the stomped-on table was pointing to be leaked.  Fix
this by keeping track of how many entries are currently mapped beneath a
table.  When the map count goes to zero (in unmap), free up the page the
table is pointing at and zero out the table entry.

Change-Id: I470e6ffb2206a09fe7c24253e3fd64a744337a7f
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:40 -07:00
Mitchel Humpherys
c84f867d94 iommu/io-pgtable: Add memory stats debugfs file
It can be useful for debugging to know how much memory is being used for
IOMMU page tables.  Add some dedicated allocation functions and a
debugfs file for this.

Change-Id: Id69b4b1b5df5dcc6c604eec3a12a894b8eab0eb6
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:39 -07:00
Mitchel Humpherys
3053a46e6f iommu: Create iommu debugfs directory from IOMMU code
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>
2016-03-22 11:13:39 -07:00
Jeremy Gebben
13ae3bcaca iommu/arm-smmu: add support for DOMAIN_ATTR_DYNAMIC
Implement support for dynamic domain switching.  This feature is
only enabled when the qcom,dynamic device tree attribute for an smmu
instance.

In order to use dynamic domains, a non-dynamic domain must first
be created and attached.  This non-dynamic domain must remain
attached while the device is in use.

All domains must be attached before calling any mapping functions, such as
iommu_map(). This allows the pagetable setup to be set up during attach
based on the hardware configuration for the smmu.

Before attaching a dynamic domain, the DOMAIN_ATTR_CONTEXT_BANK must be
set to indicate which context bank registers should be used for
any register programming.  Attaching dynamic domain doesn't cause
hardware register programming, but mapping operations may cause
TLBI operations. Additionally, the upstream driver or hardware may
do other register programming.

Because the arm-smmu driver assigns context banks dynamically, the
upstream driver should query DOMAIN_ATTR_CONTEXT_BANK on its non-dynamic
domain, to ensure the correct value is used for all dynamic domains
created.

To switch domains dynamically, the upstream driver or hardware
must program the TTBR0 and CONTEXTIDR registers with the values
from the DOMAIN_ATTR_TTBR0 and DOMAIN_ATTR_CONTEXTIDR attributes
for the desired domain. The upstream driver may also need to do
other hardware specific register programming to properly
synchronize the domain switch. It must ensure that all register
state, except for CONTEXTIDR and TTBR0 registers, is restored
at the end of the domain switch operation.

DOMAIN_ATTR_PROCID may be set to any value for each domain
before it is attached. This value is part of the CONTEXTIDR
register, but it is not used by the SMMU hardware. Setting a unique
value for this attribute in every domain can be useful for debugging.

Change-Id: Ib92d06db06832700bdf56265b169ccddfb192698
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:38 -07:00
Jeremy Gebben
36e4ea4ac1 iommu: introduce DOMAIN_ATTR_DYNAMIC
Some devices can support per-process iommu domains, which are used
asynchronously by the hardware which directly updates to the TTBR0
and CONTEXTIDR registers.

Add DOMAIN_ATTR_DYNAMIC to do indicate a domain may be used dynamically.
This attribute must be set before attaching, as it changes what
domain and hardware configuration is done by the iommu driver.
Before attaching any dynamic domains, the driver must first attach
a non-dynamic domain to do initial hardware configuration.

A simplified example:

void use_domain(struct iommu_domain *domain, struct job *job)
{
	u64 ttbr0;
	u32 contextidr;

	iommu_domain_get_attr(domain, DOMAIN_ATTR_TTBR0, &ttbr0);
	iommu_domain_get_attr(domain, DOMAIN_ATTR_CONTEXTIDR, &contextidr);

	/*
	 * Schedule work on the hardware, which is time sliced between
	 * clients. Each client has a separate iommu domain and when
	 * a job is run, the hardware first programs TTBR0 and
	 * CONTEXTIDR to use the appropriate domain.
	 */
	submit_job(ttbr0, contextidr, job);
}

void init(void)
{
	struct iommu_domain *master_domain, *dyn_domain1, *dyn_domain2;
	int dynamic = 1;
	master_domain = iommu_domain_alloc(bus);
	dyn_domain1 = iommu_domain_alloc(bus);
	dyn_domain2 = iommu_domain_alloc(bus);
	iommu_attach_device(base_domain, dev);
	iommu_domain_set_attr(dyn_domain1, DOMAIN_ATTR_DYNAMIC, &dynamic);
	iommu_domain_set_attr(dyn_domain2, DOMAIN_ATTR_DYNAMIC, &dynamic);
	iommu_attach_device(dyn_domain1, dev);
	iommu_attach_device(dyn_domain2, dev);
	while (keep_going) {
		iommu_map(dyn_domain1, ...);
		iommu_map(dyn_domain2, ...);
		use_domain(dyn_domain1, job1);
		use_domain(dyn_domain2, job2);
		iommu_unmap(dyn_domain1, ...);
		iommu_unmap(dyn_domain2, ...);
	}
	iommu_detach_device(dyn_domain2, dev);
	iommu_detach_device(dyn_domain1, dev);
	iommu_detach_device(master_domain, dev);
}

Change-Id: Ic4fa0a831751eb4b10fff5d9aec28a411856fbd1
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:37 -07:00
Jeremy Gebben
930d3bcb94 iommu/arm-smmu: add support for TTBR0, CONTEXTIDR and PROCID attributes
Add fields to arm_smmu_cfg to store asid, vmid, and procid so that they
can queried easily.

Program the CONTEXTIDR register during attach so that the PROCID
attribute functions as expected.

Change-Id: I2e2b3926fbf021754e89edda9a6857d2e3a7138b
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:36 -07:00
Jeremy Gebben
ee954ddc28 iommu: introduce TTBR0, CONTEXTIDR, and PROCID domain attributes
In the ARM SMMU architecture, pagetable programming is controlled
by the TTBR0 and CONTEXTIDR registers. The layout of these
registers varies depending on the pagetable format in use.
In particular, the ASID (address space ID) field is found in
CONTEXTIDR when using V7S format and in the top bits of TTBR0
for V7L and V8L.

Some drivers need to program hardware to switch domains on the
fly. These attributes allow the correct settings to be determined
by querying the domain rather than directly reading registers and
making assumptions about the pagetable format. The domain must be
attached before TTBR0 and CONTEXTIDR may be queried.

The PROCID attribute allows driver set a debug field in the
CONTEXTIDR register. This attribute may only be set before
attaching, but may be queried at any time.  The SMMU hardware
doesn't use the contents of this field, but debug can be simpler
if each domain stores a unique value in it.

Change-Id: I175aa78fee02c3e4e0071496d9cc2b8841ff9e3c
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:35 -07:00
Mitchel Humpherys
f0abe72924 iommu/iommu-debug: Don't add debugfs entries until we init
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>
2016-03-22 11:13:34 -07:00
Mitchel Humpherys
844ca444df iommu/iommu-debug: Add debugfs file to trigger context faults
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>
2016-03-22 11:13:33 -07:00
Mitchel Humpherys
2681714067 iommu/arm-smmu: Implement .trigger_fault
In order to facilitate debugging and development, implement the
.trigger_fault method from iommu_ops.  This can be done on ARM SMMUv2 by
writing to the FSRRESTORE register.  Do it.

Change-Id: Ia8339b54fbb9263d8cf23ff61c4615122316729a
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:33 -07:00
Mitchel Humpherys
1f9b32916b iommu: Add iommu_trigger_fault
It can be useful to trigger an IOMMU fault during development and
debugging.  Add support to the IOMMU framework to do so.

Change-Id: I908c9f5b52c6abe937f031de546d290027ba64b5
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:32 -07:00
Mitchel Humpherys
4b8b66bb58 iommu/io-pgtable-arm: Use non-cacheable page table memory
Requests from the walker to page table memory are currently inner- and
outer-cacheable.  This configuration hasn't been fully validated for
functionality or characterized for performance.  Configure these
requests as non-cacheable.

Change-Id: I7efb0a697faff68a67ee0afdb933b6dd6926f30a
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:31 -07:00
Mitchel Humpherys
8e5207d1fc iommu/arm-smmu: Disable coherent table walk by default
Coherent hardware table walking hasn't been properly validated or
characterized, so all clients are expected to disable it.  This is a
recipe for disaster since it could be easy for a new client to come
along without knowing that they need to disable it.  Just disable it by
default.  Clients can always explicitly enable it in the future if it's
found to be beneficial.

Change-Id: I4badfe33e815a6ba7b25507f5dd5a42f68d4bfa6
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:30 -07:00
Mitchel Humpherys
9a9c9a25ed iommu/iommu-debug: Add COHERENT_HTW_DISABLE to attach info
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>
2016-03-22 11:13:29 -07:00
Mitchel Humpherys
19ce6acc8e iommu/iommu-debug: Move attachment info file to subdirectory
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>
2016-03-22 11:13:28 -07:00
Mitchel Humpherys
fd7f57ccd3 iommu/iommu-debug: Initialize debug device to 0
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>
2016-03-22 11:13:27 -07:00
Mitchel Humpherys
1cbd556395 iommu/iommu-debug: Add translation and mapping test files
Running ATOS commands on custom mappings is a useful tool for debugging.
Add a new debugfs file for interactively attaching, detaching, mapping,
unmapping, and issuing ATOS commands.

Example usage:

    # cd /sys/kernel/debug/iommu/tests/soc:qcom,msm-audio-ion
    # echo 1 > attach
    # echo 0x1000,0x5000,0x1000,1 > map
    # echo 0x1008 > atos
    # cat atos
    0x5008
    # echo 0x2000 > atos
    # cat atos
    FAIL
    # echo 0 > attach

Change-Id: I596cd3f05fcb59653e2acddc17d175855a1eb9a1
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:27 -07:00
Mitchel Humpherys
682dd703a1 iommu/iommu-debug: Rename profiling device functions
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>
2016-03-22 11:13:26 -07:00
Mitchel Humpherys
8f418bc8a3 iommu/arm-smmu: Do an ATOS in the fault handler
In order to facilitate debugging of context faults, the result of a
software table walk is currently printed as part of the fault handling.
However, there are certain bugs and error conditions that can't be
caught by doing a software table walk (like missing TLB invalidation or
misbehaving hardware).  Add a hardware table walk (via ATOS) to improve
debugging capabilities.

Change-Id: Ie89019df62f115627359e29b1f6cc5de3a36d1b5
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:25 -07:00
Mitchel Humpherys
9f24ce3582 iommu/arm-smmu: Resurrect hardware iova-to-phys
The hardware address translation operations (ATOS) can be useful for
debugging.  arm-smmu used to have support for ATOS, but it was ripped
out while moving to the io-pgtable framework.  Resurrect the old ATOS
code with the following modifications:

  - Remove errata workarounds for deprecated hardware.
  - Move the atos lock to a spinlock (since the only reason a mutex was
    being used previously was due to the fact that some of the old
    errata workarounds required sleeping operations).

Change-Id: I1a021026b9ee41ba2c1761bd5d5b7a13399c6417
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:24 -07:00
Mitchel Humpherys
49e92b140d iommu: Add iommu_iova_to_phys_hard
Some IOMMU hardware implementations provide hardware translation
operations that can be useful during debugging and development.  Add a
function for this purpose along with an associated op in the iommu_ops
structure so that drivers can implement it.

Change-Id: I54ad5df526cdce05f8e04206a4f01253b3976b48
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:23 -07:00
Mitchel Humpherys
ec98437949 iommu/iommu-debug: Make attachment directories unique
Currently, the device name for the SMMU context bank device is used as
the filename for the IOMMU debug info file.  This doesn't work in cases
where multiple domains can be attached to a single SMMU context bank
device (like dynamic domains).  Make these filenames unique by appending
a 16-byte uuid to the name.

Change-Id: Ie26ece773bfa2e8c75a329a8cb8461bcd598218e
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:22 -07:00
Jordan Crouse
fd7077c385 iommu: io-pgtable-arm: Fix unmap optimization for pagetable boundaries
The last level optimization for __arm_lpae_unmap assumes that
consecutive blocks of 2MB addresses are located in the same
1GB mapping but this isn't always true - if the address spans
a 1GB boundary the next iova is in a different pagetable.

Only perform the optimization for the current pagetable entry and
then kick it back for the loop in arm_lpae_unmap to try again
with the updated iova.  All this means that __arm_lpae_unmap may
not unmap all of the size that it was given. This is okay assuming
at least something was unmapped so don't jump out of the loop
in arm_lpae_unmap until the child function returns 0 or the entire
block is freed, whichever comes first.

CRs-Fixed: 867143
Change-Id: Ic0dedbad407d60365a95afdaf03ec3b91f53960d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2016-03-22 11:13:21 -07:00
Rohit Vaswani
d295004695 arm64: mm: dma: Use dma attribute to allow executeable mappings
The default mapping type is non-executeable. Check for the
DMA_ATTR_EXEC_MAPPING attribute which allows clients to
request an executeable mapping.

Change-Id: I24a170990cc04a848b6779871ae2025721177d46
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
2016-03-22 11:13:21 -07:00
Rohit Vaswani
061e61fdf4 common: DMA-mapping: Add EXEC_MAPPING attribute
DMA_ATTR_EXEC_MAPPING specifies that an executable mapping
should be created for the requested buffer. By default, the
DMA mappings are non-executable.

Change-Id: I135077e14996e92fa9d199bdee043c443db48924
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
2016-03-22 11:13:20 -07:00
Rohit Vaswani
66771e869d iommu: msm: Provide the IOMMU_NOEXEC flag explicitly during mapping
The logic for the iommu executable flag is inverted now and
all the iommu mappings are executable by default.
Provide the IOMMU_NOEXEC flag where the mapping needs to be non-executable.

Change-Id: Ifa0aa3d17ae79c16abdf66d2177a09b868a9f45f
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
[pdaly@codeaurora.org Remove gpu/mdss]
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
2016-03-22 11:13:19 -07:00
Rohit Vaswani
2a9e5873f3 iommu: msm: Allow passing dma_attrs for lazy mapping
The msm lazy mapping APIs did not allow to pass in
dma attributes that could be passed to the dma-mapping
driver. This patch allows users to specify dma attributes for the
msm lazy mappings.

Change-Id: I3e4cd2bb99d205dce78083a256f4d444d865f3cc
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
2016-03-22 11:13:18 -07:00
Rohit Vaswani
0244adb5c7 common: DMA-mapping: add NO_DELAYED_UNMAP attribute
DMA_ATTR_NO_DELAYED_UNMAP specifies to the msm lazy mapping
driver that this buffer should be immediately unmapped once
it is freed.

Change-Id: I43e6a6058705502cf91bf5f0c530c3099cba06ae
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
2016-03-22 11:13:17 -07:00
Mitchel Humpherys
d957981cb4 arm64: dma-mapping: remove order parameter from arm_iommu_create_mapping()
arm32 recently removed the `order' parameter from
arm_iommu_create_mapping: (68efd7d2fb: arm: dma-mapping: remove order
parameter from arm_iommu_create_mapping()) in order to make the API
easier to understand.  The arm32 DMA IOMMU mapper has dynamic resizing
of the iova bitmap, so there was no reason to keep the `order' parameter
around (which was introduced to reduce the size of the bitmap).

Although we don't have dynamic iova bitmap reallocation on arm64, we'd
still like to get rid of the `order' parameter since it's confusing and
doesn't really help much (especially since all known clients on our
system are passing order=0).  Remove it.

Change-Id: I35e32fdfbe05ec434f64a3a316d13c8f43304bc6
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
[pdaly@codeaurora.org Remove gpu/ipa etc modifications]
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
2016-03-22 11:13:16 -07:00
Matt Wagantall
d5a18b907b arm64: dma-mapping: fix attribs for non-coherent strongly-ordered mappings
An incorrect conflict resolution when picking up 07c17f4e0b71d ("arm64:
add support for NO_KERNEL_MAPPING and STRONGLY_ORDERED") caused
MT_NORMAL_NC attributes being set for strongly-ordered mappings, rather
than MT_DEVICE_nGnRnE attributes.

As a result of this, speculative data fetches of the incorrectly-
mapped memory have been observed. In cases where this memory is
XPU protected or reads result in side-effects, this may result in
device crashes.

Fix this by setting the attributes returned by pgprot_noncached()
regardless of the value of the coherent flag passed to
__get_dma_pgprot()

Change-Id: Iec56027e280ae0920016df3066045b71299a915b
Signed-off-by: Matt Wagantall <mattw@codeaurora.org>
2016-03-22 11:13:16 -07:00
Mitchel Humpherys
4f3cba2015 iommu: Add debugging infrastructure
Currently, debugging IOMMU issues is done via manual instrumentation of
the code or via low-level techniques like using a JTAG debugger.
Introduce a set of library functions and debugfs files to facilitate
interactive debugging and testing.

This patch introduces the basic infrastructure as well an initial
debugfs for:

  - viewing IOMMU attachments (domain->dev mappings created by
    iommu_attach_device) and resulting attributes (like the base address
    of the page tables)

  - basic performance profiling

Example usage:

    # cd /sys/kernel/debug/iommu/attachments
    # cat b40000.qcom,kgsl-iommu:iommu_kgsl_cb2
    Domain: 0xffffffc0cb983f00
    PT_BASE_ADDR: virt=0xffffffc057eca000 phys=0x00000000d7eca000

    # cd /sys/kernel/debug/iommu/tests
    # cat soc:qcom,cam_smmu:msm_cam_smmu_cb1/profiling
        size       iommu_map  iommu_unmap
          4K           47 us       909 us
         64K           97 us       594 us
          2M         1536 us       605 us
         12M         8737 us      1193 us
         20M        26517 us      1121 us

        size    iommu_map_sg  iommu_unmap
         64K           31 us       656 us
          2M          885 us       600 us
         12M         2674 us       687 us
         20M         4352 us      1096 us

Change-Id: I1c301eec6e64688831cad80ffd0380743f7f0df6
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:15 -07:00
Mitchel Humpherys
7543efb4bc iommu/arm-smmu: Protect against concurrent attach from different domains
Currently we're relying on the smmu_domain->lock for synchronizing
attach and detach.  This is a problem because each domain has its own
smmu_domain->lock, so if multiple different domains try to attach to the
same device at the same time, they'll be racing.

Fix the race by holding a lock that's part of the smmu
structure (attach_lock should do just fine).

The test case that uncovered this was:

    # cd /sys/kernel/debug/iommu/tests/soc:qcom,msm-audio-ion/
    # while :; do cat profiling; done &
    # while :; do cat profiling; done &

Change-Id: I8a60cdc214c91967aff63882e3a7280865ffda9e
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:14 -07:00
Mitchel Humpherys
49b6182ba5 iommu/arm-smmu: Add missing unlock in attach error path
We currently have an error path in arm_smmu_attach_dev where we're
returning with a mutex locked.  Fix this.

Change-Id: I197edea7cefe361027cf46e22313ebe844684ec8
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:13 -07:00
Mitchel Humpherys
5c9140f257 iommu/arm-smmu: Poll TLBSTATUS with a tight loop
Currently we're using a 10us delay while polling the TLB status register
after doing a TLB operation.  These operations almost always finish on
the first iteration or two, so the delay is unnecessary.  Just do a
tight poll.

Change-Id: I7d5787ea92e227ded5a0578c1c647e8317c8ceca
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:12 -07:00
Mitchel Humpherys
1368353726 iommu/arm-smmu: Use context bank TLBSTATUS registers
There are TLBSTATUS registers in SMMU global register space as well as
context bank register space.  Currently we're polling the global
TLBSTATUS registers after TLB invalidation, even when using the TLB
invalidation registers from context bank address space.  This violates
the usage model described in the ARM SMMU spec.  Fix this by polling
context bank TLBSTATUS registers for context bank TLB operations, and
global TLBSTATUS registers for global TLB operations.

Change-Id: I8aa916f7bc71793cad4c9224aa85d5310eacec75
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:11 -07:00
Neeti Desai
1550045c31 iommu/arm-smmu: Fix size parameter in .unprepare_pgtable()
The size parameter in .unprepare_pgtable() and arm_smmu_assign_table()
needs to be the same since the functions are complimentary.

Use PAGE_SIZE in both functions instead of relying on the calling
function for .unprepare_pgtable().

Change-Id: Ic6fade307360254329968e1b4548732d045b8205
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2016-03-22 11:13:10 -07:00
Abhimanyu Kapur
8d4ded3f02 iommu: msm: surround the msm_dma_iommu apis with iommu ifdef
Make all msm_dma_iommu apis depend on CONFIG_IOMMU_API as it is
only used when we have the linux iommu layer available.

Change-Id: I879dc1a9174d498b9b4bc68b2418165f3b2675a3
Signed-off-by: Abhimanyu Kapur <abhimany@codeaurora.org>
2016-03-22 11:13:09 -07:00
Liam Mark
057dffa6b9 iommu/arm-smmu: lock clock enabling and reference counting
Ensure that clock enabling and reference counting is done atomically
to avoid any potential race conditions.

An example of a potential race condition is that while thread one is
enabling the clocks thread two could enter and then exit the clock
enabling function early because of reference counting. This could
lead to thread two attempting to access registers before the clocks
are enabled.

Have removed the regulator reference because enabling the regulators
involves the use of a mutex so spin locks cannot be used to protect
the reference count. Also the use of a regulator reference count is
of limited benefit since there is only one regulator to enable.

Change-Id: I7215bbf9157907fde24c94841e347370769423c8
Signed-off-by: Liam Mark <lmark@codeaurora.org>
2016-03-22 11:13:08 -07:00
Jeremy Gebben
e723f7b4a1 iommu/arm-smmu: add support for DOMAIN_ATTR_CONTEXT_BANK
Because the ARM SMMU driver assigns context banks dynamically,
some drivers need a way to know which one they are using.

Change-Id: Ic0dedbad4327ef86c5a893a48b57f0f9417800e9
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:08 -07:00
Jeremy Gebben
a0d2bed317 iommu: introduce DOMAIN_ATTR_CONTEXT_BANK
After attaching a domain, this attribute may be
queried to determine which hardware context bank
was assigned.

Change-Id: I31e674672041103007fcaff3f83a0cc2c33a4a6d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:07 -07:00
Jeremy Gebben
7b156fd0c2 iommu/arm-smmu: hold init_mutex in iommu_domain_get_attr
Some attributes are changed during domain attach and detach,
so hold init_mutex to ensure consistency.

Change-Id: I450a9a2da4bfe3616ef6dd0a6426271d25c292ce
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:06 -07:00
Jeremy Gebben
ae4721897e iommu/arm-smmu: Tear down domain context if attach fails
Currently we're leaving domains half-initialized after a
partially-successful attach.  Fix this by destroying the
domain in the error path.

Change-Id: I36c529ed4974c01fba96088b6f57a8e82b350252
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
2016-03-22 11:13:05 -07:00
Mitchel Humpherys
636df566d2 iommu/arm-smmu: Remove domain lock variable
The `lock' field of struct arm_smmu_domain was replaced by `init_mutex'
in 9725ec12d27e215 (iommu/arm-smmu: re-use the init_mutex for protecting
smmu_domain.smmu), but the `lock' field itself was not deleted.  It's
not meant to be used anymore, so delete it.  Some usages of the crufty
lock have also crept up, so fix those as well.

Change-Id: I33c2f83e7b15f0ec2cb08c784a84991a7c57950f
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:04 -07:00
Shiraz Hashim
72da3d84eb of: update reserved-memory document to include removed-dma-pool
removed-dma-pool compatibility creates a carve out region,
include the documentation for the same.

Change-Id: I6c2cd9a9dac4afab106b0d4d49db4cd51c63fbf7
Signed-off-by: Shiraz Hashim <shashim@codeaurora.org>
2016-03-22 11:13:03 -07:00
Neeti Desai
0b2a54aabe iommu/arm-smmu: Add support for page table donation
For secure domains, the page tables need to be assigned
to the correct VMIDs. Add support for doing the assignment.

Change-Id: I60009ef96ae1c8965d57096b6a1b0658ae6acc9a
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2016-03-22 11:13:02 -07:00
Neeti Desai
f6ee2b6ea3 msm: secure_buffer: Update the hyp_assign_phys() api
The hyp_assign_phys() api can be called by different
usecases where it is not guaranteed that the source vm is
always VMID_HLOS.

Pass the responsibility of setting the source_vm to
caller of the function.

Change-Id: I3851a6681f49d4bb6fa5b7a889a16a158497e9e6
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2016-03-22 11:13:01 -07:00
Mitchel Humpherys
661ff7a508 Revert "iommu: io-pgtable-arm: set page tables as outer shareable"
This reverts commit 0c78cf6e138f ("iommu: io-pgtable-arm: set page
tables as outer shareable").  We actually don't want outer-shareable
since we'd like to disable coherent table walking.

Change-Id: Id38e931864c4c1a0d77bb06d0da231b546bedf6d
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2016-03-22 11:13:01 -07:00