ti-linux-kernel/ti-linux-kernel-next.git
5 years agoMerge branch 'v4.1/topic/IOMMU-DMA' of http://git.linaro.org/kernel/linux-linaro... ti-lsk-linux-4.1.y-next ti-lsk-linux-4.1.y-next-20160420-iommu
Dan Murphy [Wed, 20 Apr 2016 14:12:46 +0000 (09:12 -0500)]
Merge branch 'v4.1/topic/IOMMU-DMA' of git.linaro.org/kernel/linux-linaro-stable into ti-lsk-linux-4.1.y-next

* 'v4.1/topic/IOMMU-DMA' of http://git.linaro.org/kernel/linux-linaro-stable: (63 commits)
  arm64: dma-mapping: fix handling of devices registered before arch_initcall
  crypto: asymmetric_keys/rsa - Use non-conflicting variable name
  iommu/dma: Use correct offset in map_sg
  iommu/dma: Avoid unlikely high-order allocations
  iommu/dma: Add some missing #includes
  iommu: Move default domain allocation to iommu_group_get_for_dev()
  arm64: Hook up IOMMU dma_ops
  arm64 : Introduce support for ACPI _CCA object
  arm64: Add IOMMU dma_ops
  iommu: Implement common IOMMU ops for DMA mapping
  iommu: iova: Move iova cache management to the iova library
  iommu/arm-smmu: Remove redundant calculation of gr0 base address
  iommu/arm-smmu: Fix error checking for ASID and VMID allocation
  iommu/arm-smmu: ThunderX mis-extends 64bit registers
  iommu/arm-smmu: Remove unneeded '0x' annotation
  iommu/arm-smmu: Use drvdata instead of maintaining smmu_devices list
  iommu/arm-smmu: Use correct address mask for CMD_TLBI_S2_IPA
  iommu/arm-smmu: Ensure IAS is set correctly for AArch32-capable SMMUs
  iommu/io-pgtable-arm: Don't use dma_to_phys()
  of: iommu: Silence misleading warning
  ...

5 years agoMerge branch 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro...
LCPD Auto Merger [Wed, 20 Apr 2016 13:43:43 +0000 (08:43 -0500)]
Merge branch 'linux-linaro-lsk-v4.1' of git.linaro.org/kernel/linux-linaro-stable into ti-lsk-linux-4.1.y

TI-Feature: linaro-stable-4-1
TI-Tree: http://git.linaro.org/kernel/linux-linaro-stable.git
TI-Branch: linux-linaro-lsk-v4.1

* 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro-stable:
  mm/early_ioremap: add explicit #include of asm/early_ioremap.h
  arm64: Don't relocate non-existent initrd

Signed-off-by: LCPD Auto Merger <lcpd_integration@list.ti.com>
5 years agoMerge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1
Alex Shi [Wed, 20 Apr 2016 13:20:11 +0000 (21:20 +0800)]
Merge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1

5 years agomm/early_ioremap: add explicit #include of asm/early_ioremap.h
Ard Biesheuvel [Fri, 11 Sep 2015 20:07:50 +0000 (13:07 -0700)]
mm/early_ioremap: add explicit #include of asm/early_ioremap.h

Commit 6b0f68e32ea8 ("mm: add utility for early copy from unmapped ram")
introduces a function copy_from_early_mem() into mm/early_ioremap.c
which itself calls early_memremap()/early_memunmap().  However, since
early_memunmap() has not been declared yet at this point in the .c file,
nor by any explicitly included header files, we are depending on a
transitive include of asm/early_ioremap.h to declare it, which is
fragile.

So instead, include this header explicitly.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 4f1af60bcc2fc6caa7fa3036238b5994708e9a84)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: Don't relocate non-existent initrd
Mark Rutland [Tue, 6 Oct 2015 17:24:37 +0000 (18:24 +0100)]
arm64: Don't relocate non-existent initrd

When booting a kernel without an initrd, the kernel reports that it
moves -1 bytes worth, having gone through the motions with initrd_start
equal to initrd_end:

    Moving initrd from [4080000000-407fffffff] to [9fff49000-9fff48fff]

Prevent this by bailing out early when the initrd size is zero (i.e. we
have no initrd), avoiding the confusing message and other associated
work.

Fixes: 1570f0d7ab425c1e ("arm64: support initrd outside kernel linear map")
Cc: Mark Salter <msalter@redhat.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 4ca3bc86bea23f38596ce7508f75e072839bde44)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: dma-mapping: fix handling of devices registered before arch_initcall
Marek Szyprowski [Tue, 16 Feb 2016 14:14:44 +0000 (15:14 +0100)]
arm64: dma-mapping: fix handling of devices registered before arch_initcall

This patch ensures that devices, which got registered before arch_initcall
will be handled correctly by IOMMU-based DMA-mapping code.

Cc: <stable@vger.kernel.org>
Fixes: 13b8629f6511 ("arm64: Add IOMMU dma_ops")
Acked-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 722ec35f7faefcc34d12616eca7976a848870f9d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agocrypto: asymmetric_keys/rsa - Use non-conflicting variable name
Guenter Roeck [Wed, 24 Jun 2015 22:27:01 +0000 (15:27 -0700)]
crypto: asymmetric_keys/rsa - Use non-conflicting variable name

arm64:allmodconfig fails to build as follows.

In file included from include/acpi/platform/aclinux.h:74:0,
                 from include/acpi/platform/acenv.h:173,
                 from include/acpi/acpi.h:56,
                 from include/linux/acpi.h:37,
                 from ./arch/arm64/include/asm/dma-mapping.h:21,
                 from include/linux/dma-mapping.h:86,
                 from include/linux/skbuff.h:34,
                 from include/crypto/algapi.h:18,
                 from crypto/asymmetric_keys/rsa.c:16:
include/linux/ctype.h:15:12: error: expected ‘;’, ‘,’ or ‘)’
before numeric constant
 #define _X 0x40 /* hex digit */
            ^
crypto/asymmetric_keys/rsa.c:123:47: note: in expansion of macro ‘_X’
 static int RSA_I2OSP(MPI x, size_t xLen, u8 **_X)
                                               ^
crypto/asymmetric_keys/rsa.c: In function ‘RSA_verify_signature’:
crypto/asymmetric_keys/rsa.c:256:2: error:
implicit declaration of function ‘RSA_I2OSP’

The problem is caused by an unrelated include file change, resulting in
the inclusion of ctype.h on arm64. This in turn causes the local variable
_X to conflict with macro _X used in ctype.h.

Fixes: b6197b93fa4b ("arm64 : Introduce support for ACPI _CCA object")
Cc: Suthikulpanit, Suravee <Suravee.Suthikulpanit@amd.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 2cdcc357c221796fac3772f23cd5830f411c0e45)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoMerge branch 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro...
LCPD Auto Merger [Wed, 20 Apr 2016 08:23:58 +0000 (03:23 -0500)]
Merge branch 'linux-linaro-lsk-v4.1' of git.linaro.org/kernel/linux-linaro-stable into ti-lsk-linux-4.1.y

TI-Feature: linaro-stable-4-1
TI-Tree: http://git.linaro.org/kernel/linux-linaro-stable.git
TI-Branch: linux-linaro-lsk-v4.1

* 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro-stable: (22 commits)
  include/linux/compiler-gcc.h: improve __visible documentation
  include/linux/compiler-gcc.h: hide assume_aligned attribute from sparse
  compiler.h: add support for function attribute assume_aligned
  compiler, atomics, kasan: Provide READ_ONCE_NOCHECK()
  compiler-gcc: integrate the various compiler-gcc[345].h files
  kasan: fix kmemleak false-positive in kasan_module_alloc()
  kasan: always taint kernel on report
  kasan: use IS_ALIGNED in memory_is_poisoned_8()
  kasan: fix last shadow judgement in memory_is_poisoned_16()
  kasan: Fix a type conversion error
  kasan: update reference to kasan prototype repo
  kasan: update log messages
  kasan: accurately determine the type of the bad access
  kasan: update reported bug types for kernel memory accesses
  kasan: update reported bug types for not user nor kernel memory accesses
  mm/kasan: prevent deadlock in kasan reporting
  mm/kasan: don't use kasan shadow pointer in generic functions
  mm/kasan: MODULE_VADDR is not available on all archs
  mm/kasan: rename kasan_enabled() to kasan_report_enabled()
  x86/kasan, mm: Introduce generic kasan_populate_zero_shadow()
  ...

Signed-off-by: LCPD Auto Merger <lcpd_integration@list.ti.com>
5 years agoiommu/dma: Use correct offset in map_sg
Robin Murphy [Mon, 4 Jan 2016 16:19:42 +0000 (16:19 +0000)]
iommu/dma: Use correct offset in map_sg

When mapping a non-page-aligned scatterlist entry, we copy the original
offset to the output DMA address before aligning it to hand off to
iommu_map_sg(), then later adding the IOVA page address portion to get
the final mapped address. However, when the IOVA page size is smaller
than the CPU page size, it is the offset within the IOVA page we want,
not that within the CPU page, which can easily be larger than an IOVA
page and thus result in an incorrect final address.

Fix the bug by taking only the IOVA-aligned part of the offset as the
basis of the DMA address, not the whole thing.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 164afb1d85b872907cfac048b46c094db596d529)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/dma: Avoid unlikely high-order allocations
Robin Murphy [Fri, 18 Dec 2015 17:01:48 +0000 (17:01 +0000)]
iommu/dma: Avoid unlikely high-order allocations

Doug reports that the equivalent page allocator on 32-bit ARM exhibits
particularly pathalogical behaviour under memory pressure when
fragmentation is high, where allocating a 4MB buffer takes tens of
seconds and the number of calls to alloc_pages() is over 9000![1]

We can drastically improve that situation without losing the other
benefits of high-order allocations when they would succeed, by assuming
memory pressure is relatively constant over the course of an allocation,
and not retrying allocations at orders we know to have failed before.
This way, the best-case behaviour remains unchanged, and in the worst
case we should see at most a dozen or so (MAX_ORDER - 1) failed attempts
before falling back to single pages for the remainder of the buffer.

[1]:http://lists.infradead.org/pipermail/linux-arm-kernel/2015-December/394660.html

Reported-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 0a9afeda8057bcedc997278db193914d32c4003b)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/dma: Add some missing #includes
Robin Murphy [Fri, 18 Dec 2015 17:01:46 +0000 (17:01 +0000)]
iommu/dma: Add some missing #includes

dma-iommu.c was naughtily relying on an implicit transitive #include of
linux/vmalloc.h, which is apparently not present on some architectures.
Add that, plus a couple more headers for other functions which are used
similarly.

Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 5b11e9cd42d08e76b86eacf103b1fa7794e21bff)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Move default domain allocation to iommu_group_get_for_dev()
Joerg Roedel [Wed, 21 Oct 2015 21:51:43 +0000 (23:51 +0200)]
iommu: Move default domain allocation to iommu_group_get_for_dev()

Now that the iommu core support for iommu groups is not
pci-centric anymore, we can move default domain allocation
to the bus independent iommu_group_get_for_dev() function.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 1228236de5f978970fb814cc27138cdb00cbb48d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: Hook up IOMMU dma_ops
Robin Murphy [Thu, 1 Oct 2015 19:14:00 +0000 (20:14 +0100)]
arm64: Hook up IOMMU dma_ops

With iommu_dma_ops in place, hook them up to the configuration code, so
IOMMU-fronted devices will get them automatically.

Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 876945dbf6497c7539ef958fee7ade970fbbe17a)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64 : Introduce support for ACPI _CCA object
Suthikulpanit, Suravee [Wed, 10 Jun 2015 16:08:53 +0000 (11:08 -0500)]
arm64 : Introduce support for ACPI _CCA object

section 6.2.17 _CCA states that ARM platforms require ACPI _CCA
object to be specified for DMA-cabpable devices. Therefore, this patch
specifies ACPI_CCA_REQUIRED in arm64 Kconfig.

In addition, to handle the case when _CCA is missing, arm64 would assign
dummy_dma_ops to disable DMA capability of the device.

Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit b6197b93fa4bcba9313cc415934e3fe27e2db9b0)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: Add IOMMU dma_ops
Robin Murphy [Thu, 1 Oct 2015 19:13:59 +0000 (20:13 +0100)]
arm64: Add IOMMU dma_ops

Taking some inspiration from the arch/arm code, implement the
arch-specific side of the DMA mapping ops using the new IOMMU-DMA layer.

Since there is still work to do elsewhere to make DMA configuration happen
in a more appropriate order and properly support platform devices in the
IOMMU core, the device setup code unfortunately starts out carrying some
workarounds to ensure it works correctly in the current state of things.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 13b8629f651164d71f4d38b821925f93ba4236c8)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Implement common IOMMU ops for DMA mapping
Robin Murphy [Thu, 1 Oct 2015 19:13:58 +0000 (20:13 +0100)]
iommu: Implement common IOMMU ops for DMA mapping

Taking inspiration from the existing arch/arm code, break out some
generic functions to interface the DMA-API to the IOMMU-API. This will
do the bulk of the heavy lifting for IOMMU-backed dma-mapping.

Since associating an IOVA allocator with an IOMMU domain is a fairly
common need, rather than introduce yet another private structure just to
do this for ourselves, extend the top-level struct iommu_domain with the
notion. A simple opaque cookie allows reuse by other IOMMU API users
with their various different incompatible allocator types.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 0db2e5d18f76a66ca945447d9f610bed0a94ca5a)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: iova: Move iova cache management to the iova library
Sakari Ailus [Mon, 13 Jul 2015 11:31:28 +0000 (14:31 +0300)]
iommu: iova: Move iova cache management to the iova library

This is necessary to separate intel-iommu from the iova library.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
(cherry picked from commit ae1ff3d623905947158fd3394854c23026337810)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Remove redundant calculation of gr0 base address
Will Deacon [Tue, 13 Oct 2015 16:53:24 +0000 (17:53 +0100)]
iommu/arm-smmu: Remove redundant calculation of gr0 base address

Since commit 1463fe44fd0f ("iommu/arm-smmu: Don't use VMIDs for stage-1
translations"), we don't need the GR0 base address when initialising a
context bank, so remove the useless local variable and its init code.

Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit c88ae5de71629e4b5e4075897d9980a7b079d122)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix error checking for ASID and VMID allocation
Will Deacon [Tue, 13 Oct 2015 16:51:14 +0000 (17:51 +0100)]
iommu/arm-smmu: Fix error checking for ASID and VMID allocation

The bitmap allocator returns an int, which is one of the standard
negative values on failure. Rather than assigning this straight to a
u16 (like we do for the ASID and VMID callers), which means that we
won't detect failure correctly, use an int for the purposes of error
checking.

Cc: <stable@vger.kernel.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit c0733a2cf30c1e7923b6ad4f8df67941502923de)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: ThunderX mis-extends 64bit registers
Tirumalesh Chalamarla [Tue, 18 Aug 2015 23:40:30 +0000 (00:40 +0100)]
iommu/arm-smmu: ThunderX mis-extends 64bit registers

The SMMU architecture defines two different behaviors when 64-bit
registers are written with 32-bit writes.  The first behavior causes
zero extension into the upper 32-bits.  The second behavior splits a
64-bit register into "normal" 32-bit register pairs.

On some buggy implementations, registers incorrectly zero extended
when they should instead behave as normal 32-bit register pairs.

Signed-off-by: Tirumalesh Chalamarla <tchalamarla@caviumnetworks.com>
[will: removed redundant macro parameters]
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 668b4ada1cdf406dac9f72503fa2f69f31bed0c5)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Remove unneeded '0x' annotation
Fabio Estevam [Tue, 18 Aug 2015 16:12:24 +0000 (17:12 +0100)]
iommu/arm-smmu: Remove unneeded '0x' annotation

'%pad' automatically prints with '0x', so remove the explicit '0x'
annotation.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 077124c98da3aa5aaf498fd0980ed14eaf777c09)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Use drvdata instead of maintaining smmu_devices list
Will Deacon [Tue, 11 Aug 2015 15:25:10 +0000 (16:25 +0100)]
iommu/arm-smmu: Use drvdata instead of maintaining smmu_devices list

Rather than keep a private list of struct arm_smmu_device and searching
this whenever we need to look up the correct SMMU instance, instead use
the drvdata field in the struct device to take care of the mapping for
us.

Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 941a802d939221028baf6d19afd6dc8652219a81)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Use correct address mask for CMD_TLBI_S2_IPA
Will Deacon [Fri, 18 Sep 2015 15:12:56 +0000 (16:12 +0100)]
iommu/arm-smmu: Use correct address mask for CMD_TLBI_S2_IPA

Stage-2 TLBI by IPA takes a 48-bit address field, as opposed to the
64-bit field used by the VA-based invalidation commands.

This patch re-jigs the SMMUv3 command construction code so that the
address field is correctly masked.

Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 1c27df1c0a82b938d8073a60243ff62eff8056b5)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Ensure IAS is set correctly for AArch32-capable SMMUs
Will Deacon [Thu, 20 Aug 2015 11:12:32 +0000 (12:12 +0100)]
iommu/arm-smmu: Ensure IAS is set correctly for AArch32-capable SMMUs

AArch32-capable SMMU implementations have a minimum IAS of 40 bits, so
ensure that is reflected in the stage-2 page table configuration.

Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit f0c453dbcce7767cd868deb809ba68083c93954e)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable-arm: Don't use dma_to_phys()
Robin Murphy [Thu, 17 Sep 2015 16:42:16 +0000 (17:42 +0100)]
iommu/io-pgtable-arm: Don't use dma_to_phys()

In checking whether DMA addresses differ from physical addresses, using
dma_to_phys() is actually the wrong thing to do, since it may hide any
DMA offset, which is precisely one of the things we are checking for.
Simply casting between the two address types, whilst ugly, is in fact
the appropriate course of action. Further care (and ugliness) is also
necessary in the comparison to avoid truncation if phys_addr_t and
dma_addr_t differ in size.

We can also reject any device with a fixed DMA offset up-front at page
table creation, leaving the allocation-time check for the more subtle
cases like bounce buffering due to an incorrect DMA mask.

Furthermore, we can then fix the hackish KConfig dependency so that
architectures without a dma_to_phys() implementation may still
COMPILE_TEST (or even use!) the code. The true dependency is on the
DMA API, so use the appropriate symbol for that.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
[will: folded in selftest fix from Yong Wu]
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit ffcb6d1686ceb4a6b50776fb2597ab0e4dd79040)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
Conflicts:
include cf27ec9 iommu/io-pgtable-arm: Unmap and free table...
in file drivers/iommu/io-pgtable-arm.c

5 years agoof: iommu: Silence misleading warning
Robin Murphy [Wed, 22 Jul 2015 17:47:00 +0000 (18:47 +0100)]
of: iommu: Silence misleading warning

Printing "IOMMU is currently not supported for PCI" for
every PCI device probed on a DT-based system proves to be
both irritatingly noisy and confusing to users who have
misinterpreted it to mean they can no longer use VFIO device
assignment.

Since configuring DMA masks for PCI devices via
of_dma_configure() has not in fact changed anything with
regard to IOMMUs there really is nothing to warn about here;
shut it up.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 7b0ce727bf7ac5240a433109f53bf78788f9159b)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable-arm: Unmap and free table when overwriting with block
Will Deacon [Tue, 11 Aug 2015 15:48:32 +0000 (16:48 +0100)]
iommu/io-pgtable-arm: Unmap and free table when overwriting with block

When installing a block mapping, we unconditionally overwrite a non-leaf
PTE if we find one. However, this can cause a problem if the following
sequence of events occur:

  (1) iommu_map called for a 4k (i.e. PAGE_SIZE) mapping at some address
      - We initialise the page table all the way down to a leaf entry
      - No TLB maintenance is required, because we're going from invalid
        to valid.

  (2) iommu_unmap is called on the mapping installed in (1)
      - We walk the page table to the final (leaf) entry and zero it
      - We only changed a valid leaf entry, so we invalidate leaf-only

  (3) iommu_map is called on the same address as (1), but this time for
      a 2MB (i.e. BLOCK_SIZE) mapping)
      - We walk the page table down to the penultimate level, where we
        find a table entry
      - We overwrite the table entry with a block mapping and return
        without any TLB maintenance and without freeing the memory used
        by the now-orphaned table.

This last step can lead to a walk-cache caching the overwritten table
entry, causing unexpected faults when the new mapping is accessed by a
device. One way to fix this would be to collapse the page table when
freeing the last page at a given level, but this would require expensive
iteration on every map call. Instead, this patch detects the case when
we are overwriting a table entry and explicitly unmaps the table first,
which takes care of both freeing and TLB invalidation.

Cc: <stable@vger.kernel.org>
Reported-by: Brian Starkey <brian.starkey@arm.com>
Tested-by: Brian Starkey <brian.starkey@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit cf27ec930be906e142c752f9161197d69ca534d7)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable-arm: Move init-fn declarations to io-pgtable.h
Joerg Roedel [Thu, 13 Aug 2015 10:01:10 +0000 (12:01 +0200)]
iommu/io-pgtable-arm: Move init-fn declarations to io-pgtable.h

Avoid extern declarations in c files.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 2e169bb3ccc20fea5e6f59d1abcea249c6598163)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable: Remove flush_pgtable callback
Robin Murphy [Wed, 29 Jul 2015 18:46:12 +0000 (19:46 +0100)]
iommu/io-pgtable: Remove flush_pgtable callback

With the users fully converted to DMA API operations, it's dead, Jim.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit f5b831907da3e64bfb0288089a5c07124266b1a5)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Remove arm_smmu_flush_pgtable()
Robin Murphy [Wed, 29 Jul 2015 18:46:11 +0000 (19:46 +0100)]
iommu/arm-smmu: Remove arm_smmu_flush_pgtable()

With the io-pgtable code now enforcing its own appropriate sync points,
the vestigial flush_pgtable callback becomes entirely redundant, so
remove it altogether.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 857c88ca62f1e2594e1e760ef9a45ec1961f2a53)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Remove arm_smmu_flush_pgtable()
Robin Murphy [Wed, 29 Jul 2015 18:46:10 +0000 (19:46 +0100)]
iommu/arm-smmu: Remove arm_smmu_flush_pgtable()

With the io-pgtable code now enforcing its own appropriate sync points,
the vestigial flush_pgtable callback becomes entirely redundant, so
remove it altogether.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 4103d662cbd0c045d7a44a18c82172220478b20c)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable-arm: Centralise sync points
Robin Murphy [Wed, 29 Jul 2015 18:46:09 +0000 (19:46 +0100)]
iommu/io-pgtable-arm: Centralise sync points

With all current users now opted in to DMA API operations, make the
iommu_dev pointer mandatory, rendering the flush_pgtable callback
redundant for cache maintenance. However, since the DMA calls could be
nops in the case of a coherent IOMMU, we still need to ensure the page
table updates are fully synchronised against a subsequent page table
walk. In the unmap path, the TLB sync will usually need to do this
anyway, so just cement that requirement; in the map path which may
consist solely of cacheable memory writes (in the coherent case),
insert an appropriate barrier at the end of the operation, and obviate
the need to call flush_pgtable on every individual update for
synchronisation.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
[will: slight clarification to tlb_sync comment]
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 87a91b15d691d6f4aa0a5baffb5767bbc6e4a8c4)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/ipmmu-vmsa: Clean up DMA API usage
Robin Murphy [Wed, 29 Jul 2015 18:46:08 +0000 (19:46 +0100)]
iommu/ipmmu-vmsa: Clean up DMA API usage

With the correct DMA API calls now integrated into the io-pgtable code,
let that handle the flushing of non-coherent page table updates.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit ff2ed96dde3b30d8f1b2ab0d9b164140f2278e6e)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Clean up DMA API usage
Robin Murphy [Wed, 29 Jul 2015 18:46:07 +0000 (19:46 +0100)]
iommu/arm-smmu: Clean up DMA API usage

With the correct DMA API calls now integrated into the io-pgtable code,
let that handle the flushing of non-coherent page table updates.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit bdc6d973473f32891a8518c51b210ce7daaa10ac)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Clean up DMA API usage
Robin Murphy [Wed, 29 Jul 2015 18:46:06 +0000 (19:46 +0100)]
iommu/arm-smmu: Clean up DMA API usage

With the correct DMA API calls now integrated into the io-pgtable code,
let that handle the flushing of non-coherent page table updates.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 2df7a25ce4a79092946330ac4b7a2fbb5944d1d6)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/io-pgtable-arm: Allow appropriate DMA API use
Robin Murphy [Wed, 29 Jul 2015 18:46:04 +0000 (19:46 +0100)]
iommu/io-pgtable-arm: Allow appropriate DMA API use

Currently, users of the LPAE page table code are (ab)using dma_map_page()
as a means to flush page table updates for non-coherent IOMMUs. Since
from the CPU's point of view, creating IOMMU page tables *is* passing
DMA buffers to a device (the IOMMU's page table walker), there's little
reason not to use the DMA API correctly.

Allow IOMMU drivers to opt into DMA API operations for page table
allocation and updates by providing their appropriate device pointer.
The expectation is that an LPAE IOMMU should have a full view of system
memory, so use streaming mappings to avoid unnecessary pressure on
ZONE_DMA, and treat any DMA translation as a warning sign.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit f8d5496131554f61b0fd931fa046f0233fe2aac2)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
Conflicts:
on file drivers/iommu/io-pgtable-arm.c
commit cf27ec9 iommu/io-pgtable-arm: Unmap and free table when overwriting with block
was backported to v4.1 LTS. coexist with it.

5 years agoiommu/arm-smmu: Treat unknown OAS as 48-bit
Will Deacon [Mon, 3 Aug 2015 09:35:40 +0000 (10:35 +0100)]
iommu/arm-smmu: Treat unknown OAS as 48-bit

A late change to the SMMUv3 architecture ensures that the OAS field
will be monotonically increasing, so we can assume that an unknown OAS
is at least 48-bit and use that, rather than fail the device probe.

Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 85430968ae72650a63f77f05a29d5c56e41581db)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Sort out coherency
Robin Murphy [Wed, 29 Jul 2015 18:46:05 +0000 (19:46 +0100)]
iommu/arm-smmu: Sort out coherency

Currently, we detect whether the SMMU has coherent page table walk
capability from the IDR0.CTTW field, and base our cache maintenance
decisions on that. In preparation for fixing the bogus DMA API usage,
however, we need to ensure that the DMA API agrees about this, which
necessitates deferring to the dma-coherent property in the device tree
for the final say.

As an added bonus, since systems exist where an external CTTW signal
has been tied off incorrectly at integration, allowing DT to override
it offers a neat workaround for coherency issues with such SMMUs.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit bae2c2d421cdea9dd8d62425eef99e389584cdb3)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Limit 2-level strtab allocation for small SID sizes
Will Deacon [Thu, 16 Jul 2015 16:50:12 +0000 (17:50 +0100)]
iommu/arm-smmu: Limit 2-level strtab allocation for small SID sizes

If the StreamIDs in a system can all be resolved by a single level-2
stream table (i.e. SIDSIZE < SPLIT), then we currently get our maths
wrong and allocate the largest strtab we support, thanks to unsigned
overflow in our calculation.

This patch fixes the issue by checking the SIDSIZE explicitly when
calculating the size of our first-level stream table.

Reported-by: Matt Evans <matt.evans@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 28c8b4045b18b013e05656b493ce9a57cbf1f09a)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix MSI memory attributes to match specification
Marc Zyngier [Wed, 15 Jul 2015 10:55:19 +0000 (11:55 +0100)]
iommu/arm-smmu: Fix MSI memory attributes to match specification

The MSI memory attributes in the SMMUv3 driver are from an older
revision of the spec, which doesn't match the current implementations.

Out with the old, in with the new.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit ec11d63c677bbba15e65a35f5ba06c1d6eba4dbe)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix enabling of PRIQ interrupt
Marc Zyngier [Wed, 15 Jul 2015 10:55:18 +0000 (11:55 +0100)]
iommu/arm-smmu: Fix enabling of PRIQ interrupt

When an ARM SMMUv3 instance supports PRI, the driver registers
an interrupt handler, but fails to enable the generation of
such interrupt at the SMMU level.

This patches simply moves the enable flags to a variable that
gets updated by the PRI handling code before being written to the
SMMU register.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit ccd6385dfbb7b2f2e6670b5cfc55bb7ec0aa3839)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Skip the execution of CMD_PREFETCH_CONFIG
Zhen Lei [Tue, 7 Jul 2015 03:30:18 +0000 (04:30 +0100)]
iommu/arm-smmu: Skip the execution of CMD_PREFETCH_CONFIG

Hisilicon SMMUv3 devices treat CMD_PREFETCH_CONFIG as a illegal command,
execute it will trigger GERROR interrupt. Although the gerror code manage
to turn the prefetch into a SYNC, and the system can continue to run
normally, but it's ugly to print error information.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
[will: extended binding documentation]
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 5e92946c39ca6abc65e34775a93cc1d1a819c0e3)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Enlarge STRTAB_L1_SZ_SHIFT to support larger sidsize
Zhen Lei [Tue, 7 Jul 2015 03:30:17 +0000 (04:30 +0100)]
iommu/arm-smmu: Enlarge STRTAB_L1_SZ_SHIFT to support larger sidsize

Because we will choose the minimum value between STRTAB_L1_SZ_SHIFT and
IDR1.SIDSIZE, so enlarge STRTAB_L1_SZ_SHIFT will not impact the platforms
whose IDR1.SIDSIZE is smaller than old STRTAB_L1_SZ_SHIFT value.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit e2f4c2330f08ba73d9a3c919a3d6ca33dce7d2c2)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix the values of ARM64_TCR_{I,O}RGN0_SHIFT
Zhen Lei [Fri, 26 Jun 2015 08:32:59 +0000 (09:32 +0100)]
iommu/arm-smmu: Fix the values of ARM64_TCR_{I,O}RGN0_SHIFT

The arm64 CPU architecture defines TCR[8:11] as holding the inner and
outer memory attributes for TTBR0.

This patch fixes the ARM SMMUv3 driver to pack these bits into the
context descriptor, rather than picking up the TTBR1 attributes as it
currently does.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 5d58c6207c300340151931ad9c2cdea2d1685dc4)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix LOG2SIZE setting for 2-level stream tables
Will Deacon [Tue, 30 Jun 2015 09:02:28 +0000 (10:02 +0100)]
iommu/arm-smmu: Fix LOG2SIZE setting for 2-level stream tables

STRTAB_BASE_CFG.LOG2SIZE should be set to log2(entries), where entries
is the *total* number of entries in the stream table, not just the first
level.

This patch fixes the register setting, which was previously being set to
the size of the l1 thanks to a multi-use "size" variable.

Reported-by: Zhen Lei <thunder.leizhen@huawei.com>
Tested-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit d2e88e7c081efb2c5a9e1adb2a065d373167af4b)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix the index calculation of strtab
Zhen Lei [Fri, 26 Jun 2015 08:32:58 +0000 (09:32 +0100)]
iommu/arm-smmu: Fix the index calculation of strtab

The element size of cfg->strtab is just one DWORD, so we should use a
multiply operation instead of a shift when calculating the level 1
index.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
(cherry picked from commit 69146e7bfc38139a134c79a4ee6607c881891786)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Delete an unnecessary check before the function call "free_io_pgtable...
Markus Elfring [Mon, 29 Jun 2015 16:47:43 +0000 (17:47 +0100)]
iommu/arm-smmu: Delete an unnecessary check before the function call "free_io_pgtable_ops"

The free_io_pgtable_ops() function tests whether its argument is NULL
and then returns immediately. Thus the test around the call is not needed.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit a6e08fb2d2f9eb38f52e6f2425a38f1cb9794742)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Ignore -ENODEV errors from add_device call-back
Joerg Roedel [Mon, 29 Jun 2015 08:16:08 +0000 (10:16 +0200)]
iommu: Ignore -ENODEV errors from add_device call-back

The -ENODEV error just means that the device is not
translated by an IOMMU. We shouldn't bail out of iommu
driver initialization when that happens, as this is a common
scenario on ARM.

Not returning -ENODEV in the drivers would be a bad idea, as
the IOMMU core would have no indication whether a device is
translated or not. This indication is not used at the
moment, but will probably be in the future.

Fixes: 19762d7 ("iommu: Propagate error in add_iommu_group")
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Eric Auger <eric.auger@linaro.org>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 38667f18900afe172a4fe44279b132b4140f920f)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Fix checkpatch warnings for Missing a blank line after declarations
Robert Callicotte [Fri, 17 Apr 2015 04:32:47 +0000 (23:32 -0500)]
iommu: Fix checkpatch warnings for Missing a blank line after declarations

Fixed checkpatch warnings for missing blank line after
declaration of struct.

Signed-off-by: Robert Callicotte <rcallicotte@gmail.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 733cac2ade2fbb73740a1d22c05c7b006a6cf3d2)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Checking for NULL instead of IS_ERR
Dan Carpenter [Wed, 10 Jun 2015 10:59:27 +0000 (13:59 +0300)]
iommu: Checking for NULL instead of IS_ERR

The iommu_group_alloc() and iommu_group_get_for_dev()
functions return error pointers, they never return NULL.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 409e553deeeb08d644ed1110e0f1c97b71cb6409)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Introduce iommu_request_dm_for_dev()
Joerg Roedel [Thu, 28 May 2015 16:41:36 +0000 (18:41 +0200)]
iommu: Introduce iommu_request_dm_for_dev()

This function can be called by an IOMMU driver to request
that a device's default domain is direct mapped.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit d290f1e70d85a9a4d124594c6a3d769329960bdc)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Add function to query the default domain of a group
Joerg Roedel [Thu, 28 May 2015 16:41:35 +0000 (18:41 +0200)]
iommu: Add function to query the default domain of a group

This will be used to handle unity mappings in the iommu
drivers.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 6827ca83695d5e41ad31b0719788ee65f00ca4b3)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Create direct mappings in default domains
Joerg Roedel [Thu, 28 May 2015 16:41:34 +0000 (18:41 +0200)]
iommu: Create direct mappings in default domains

Use the information exported by the IOMMU drivers to create
direct mapped regions in the default domains.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit beed2821b4f42c268222c4c1f1795e53340acf64)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Introduce direct mapped region handling
Joerg Roedel [Thu, 28 May 2015 16:41:33 +0000 (18:41 +0200)]
iommu: Introduce direct mapped region handling

Add two new functions to the IOMMU-API to allow the IOMMU
drivers to export the requirements for direct mapped regions
per device.
This is useful for exporting the information in Intel VT-d's
RMRR entries or AMD-Vi's unity mappings.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit a1015c2b99b94cf521603b41debf167114031456)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Add iommu_get_domain_for_dev function
Joerg Roedel [Thu, 28 May 2015 16:41:32 +0000 (18:41 +0200)]
iommu: Add iommu_get_domain_for_dev function

This function can be used to request the current domain a
device is attached to.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 2c1296d92ac0367364bcb73a43c12a0bdfbfee75)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Make sure a device is always attached to a domain
Joerg Roedel [Thu, 28 May 2015 16:41:31 +0000 (18:41 +0200)]
iommu: Make sure a device is always attached to a domain

Make use of the default domain and re-attach a device to it
when it is detached from another domain. Also enforce that a
device has to be in the default domain before it can be
attached to a different domain.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit e39cb8a3aa988a74433a3f26443b454cca033651)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Limit iommu_attach/detach_device to devices with their own group
Joerg Roedel [Thu, 28 May 2015 16:41:30 +0000 (18:41 +0200)]
iommu: Limit iommu_attach/detach_device to devices with their own group

This patch changes the behavior of the iommu_attach_device
and iommu_detach_device functions. With this change these
functions only work on devices that have their own group.
For all other devices the iommu_group_attach/detach
functions must be used.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 426a273834eae65abcfc7132a21a85b3151e0bce)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Allocate a default domain for iommu groups
Joerg Roedel [Thu, 28 May 2015 16:41:29 +0000 (18:41 +0200)]
iommu: Allocate a default domain for iommu groups

The default domain will be used (if supported by the iommu
driver) when the devices in the iommu group are not attached
to any other domain.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 53723dc59ff3ab504c739000b287ded49aeb2019)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Call remove_device call-back after driver release
Joerg Roedel [Thu, 28 May 2015 16:41:28 +0000 (18:41 +0200)]
iommu: Call remove_device call-back after driver release

Do not remove the device from the IOMMU while the driver is
still attached.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 843cb6dc7749a25849797cc9aeeb86f87a8acb84)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Clean up after a failed bus initialization
Joerg Roedel [Thu, 28 May 2015 16:41:27 +0000 (18:41 +0200)]
iommu: Clean up after a failed bus initialization

Make sure we call the ->remove_device call-back on all
devices already initialized with ->add_device when the bus
initialization fails.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 8da30142a21e2d7595510892a4c99cf294f7e6f1)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Propagate error in add_iommu_group
Joerg Roedel [Thu, 28 May 2015 16:41:26 +0000 (18:41 +0200)]
iommu: Propagate error in add_iommu_group

Make sure any errors reported from the IOMMU drivers get
progapated back to the IOMMU core.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 19762d7095e6392b6ec56c363a6f29b2119488c2)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Add a few printk messages to group handling code
Joerg Roedel [Thu, 28 May 2015 16:41:25 +0000 (18:41 +0200)]
iommu: Add a few printk messages to group handling code

Write a message to the kernel log when a device is added or
removed from a group and add debug messages to group
allocation and release routines.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 269aa808a990b3fdd0e7ec9e04322284c40748c4)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Remove function name from pr_fmt()
Joerg Roedel [Thu, 28 May 2015 16:41:24 +0000 (18:41 +0200)]
iommu: Remove function name from pr_fmt()

Including the function name is only useful for debugging
messages. They don't belong into other messages from the
iommu core.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 92e7066fde31d5ac48a9bccc12d3063d251dd079)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu: Init iommu-groups support earlier, in core_initcall
Marek Szyprowski [Tue, 19 May 2015 13:20:23 +0000 (15:20 +0200)]
iommu: Init iommu-groups support earlier, in core_initcall

iommu_group_alloc might be called very early in case of iommu controllers
activated from of_iommu, so ensure that this part of subsystem is ready
when devices are being populated from device-tree (core_initcall seems to
be okay for this case).

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit d7ef9995f1d9e394f994b9a1755cccb21ba3e421)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agodrivers/vfio: Allow type-1 IOMMU instantiation on top of an ARM SMMUv3
Will Deacon [Wed, 27 May 2015 16:26:00 +0000 (17:26 +0100)]
drivers/vfio: Allow type-1 IOMMU instantiation on top of an ARM SMMUv3

The ARM SMMUv3 driver is compatible with the notion of a type-1 IOMMU in
VFIO.

This patch allows VFIO_IOMMU_TYPE1 to be selected if ARM_SMMU_V3=y.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Acked-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 8a0a01bff855a6763d937acc70a876cb0bed063d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Add initial driver support for ARM SMMUv3 devices
Will Deacon [Wed, 27 May 2015 16:25:59 +0000 (17:25 +0100)]
iommu/arm-smmu: Add initial driver support for ARM SMMUv3 devices

Version three of the ARM SMMU architecture introduces significant
changes and improvements over previous versions of the specification,
necessitating a new driver in the Linux kernel.

The main change to the programming interface is that the majority of the
configuration data has been moved from MMIO registers to in-memory data
structures, with communication between the CPU and the SMMU being
mediated via in-memory circular queues.

This patch adds an initial driver for SMMUv3 to Linux. We currently
support pinned stage-1 (DMA) and stage-2 (KVM VFIO) mappings using the
generic IO-pgtable code.

Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 48ec83bcbcf5090fcdf74a6168f161d247492979)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoDocumentation: dt-bindings: Add device-tree binding for ARM SMMUv3 IOMMU
Will Deacon [Wed, 27 May 2015 16:25:58 +0000 (17:25 +0100)]
Documentation: dt-bindings: Add device-tree binding for ARM SMMUv3 IOMMU

This patch adds device-tree bindings for ARM SMMUv3 IOMMU devices.

Cc: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit a73e528ab1499505c29e14091b19cb041e20e038)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Make force_stage module param read-only in sysfs
Will Deacon [Wed, 27 May 2015 16:09:35 +0000 (17:09 +0100)]
iommu/arm-smmu: Make force_stage module param read-only in sysfs

Changing force_stage dynamically isn't supported by the driver and it
also doesn't make a whole lot of sense to change it once the SMMU is up
and running.

This patch makes the sysfs entry for the parameter read-only.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit e3ce0c940e02e4d9d09c1c1377f80d9e90a893a0)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoiommu/arm-smmu: Fix ATS1* register writes
Robin Murphy [Wed, 27 May 2015 16:09:34 +0000 (17:09 +0100)]
iommu/arm-smmu: Fix ATS1* register writes

The ATS1* address translation registers only support being written
atomically - in SMMUv2 where they are 64 bits wide, 32-bit writes to
the lower half are automatically zero-extended, whilst 32-bit writes
to the upper half are ignored. Thus, the current logic of performing
64-bit writes as two 32-bit accesses is wrong.

Since we already limit IOVAs to 32 bits on 32-bit ARM, the lack of a
suitable writeq() implementation there is not an issue, and we only
need a little preprocessor ugliness to safely hide the 64-bit case.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit 661d962f19c23df492a03f47b583ef6a540d6031)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoMerge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1
Alex Shi [Thu, 14 Apr 2016 01:20:25 +0000 (09:20 +0800)]
Merge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1

5 years agoinclude/linux/compiler-gcc.h: improve __visible documentation
Andrew Morton [Sat, 7 Nov 2015 00:30:09 +0000 (16:30 -0800)]
include/linux/compiler-gcc.h: improve __visible documentation

Cc: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 9add850c211a39d5ab1a091d48795e21599a73d0)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoinclude/linux/compiler-gcc.h: hide assume_aligned attribute from sparse
Rasmus Villemoes [Fri, 6 Nov 2015 02:45:05 +0000 (18:45 -0800)]
include/linux/compiler-gcc.h: hide assume_aligned attribute from sparse

The patch "slab.h: sprinkle __assume_aligned attributes" causes *tons* of
whinges if you do 'make C=2' with sparse 0.5.0:

  CHECK   drivers/media/usb/pwc/pwc-if.c
include/linux/slab.h:307:43: error: attribute '__assume_aligned__': unknown attribute
include/linux/slab.h:308:58: error: attribute '__assume_aligned__': unknown attribute
include/linux/slab.h:337:73: error: attribute '__assume_aligned__': unknown attribute
include/linux/slab.h:375:74: error: attribute '__assume_aligned__': unknown attribute
include/linux/slab.h:378:80: error: attribute '__assume_aligned__': unknown attribute

sparse apparently pretends to be gcc >= 4.9, yet isn't prepared to handle
all the function attributes supported by those gccs and complains loudly.
So hide the definition of __assume_aligned from it (so that the generic
one in compiler.h gets used).

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reported-by: Valdis Kletnieks <Valdis.Kletnieks@vt.edu>
Tested-By: Valdis Kletnieks <valdis.kletnieks@vt.edu>
Cc: Christopher Li <sparse@chrisli.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 8748dd5c98f7fe506ccb31a094833401ed120915)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agocompiler.h: add support for function attribute assume_aligned
Rasmus Villemoes [Fri, 6 Nov 2015 02:45:02 +0000 (18:45 -0800)]
compiler.h: add support for function attribute assume_aligned

gcc 4.9 added the function attribute assume_aligned, indicating to the
caller that the returned pointer may be assumed to have a certain minimal
alignment.  This is useful if, for example, the return value is passed to
memset().  Add a shorthand macro for that.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit a744fd17b5233360681ce03e43804406745b680b)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agocompiler, atomics, kasan: Provide READ_ONCE_NOCHECK()
Andrey Ryabinin [Mon, 19 Oct 2015 08:37:17 +0000 (11:37 +0300)]
compiler, atomics, kasan: Provide READ_ONCE_NOCHECK()

Some code may perform racy by design memory reads. This could be
harmless, yet such code may produce KASAN warnings.

To hide such accesses from KASAN this patch introduces
READ_ONCE_NOCHECK() macro. KASAN will not check the memory
accessed by READ_ONCE_NOCHECK(). The KernelThreadSanitizer
(KTSAN) is going to ignore it as well.

This patch creates __read_once_size_nocheck() a clone of
__read_once_size(). The only difference between them is
'no_sanitized_address' attribute appended to '*_nocheck'
function. This attribute tells the compiler that instrumentation
of memory accesses should not be applied to that function. We
declare it as static '__maybe_unsed' because GCC is not capable
to inline such function:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368

With KASAN=n READ_ONCE_NOCHECK() is just a clone of READ_ONCE().

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
Cc: kasan-dev <kasan-dev@googlegroups.com>
Link: http://lkml.kernel.org/r/1445243838-17763-2-git-send-email-aryabinin@virtuozzo.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit d976441f44bc5d48635d081d277aa76556ffbf8b)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agocompiler-gcc: integrate the various compiler-gcc[345].h files
Joe Perches [Thu, 25 Jun 2015 22:01:02 +0000 (15:01 -0700)]
compiler-gcc: integrate the various compiler-gcc[345].h files

As gcc major version numbers are going to advance rather rapidly in the
future, there's no real value in separate files for each compiler
version.

Deduplicate some of the macros #defined in each file too.

Neaten comments using normal kernel commenting style.

Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Michal Marek <mmarek@suse.cz>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Sasha Levin <levinsasha928@gmail.com>
Cc: Anton Blanchard <anton@samba.org>
Cc: Alan Modra <amodra@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit cb984d101b30eb7478d32df56a0023e4603cba7f)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoMerge branch 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro...
Dan Murphy [Tue, 12 Apr 2016 20:45:41 +0000 (15:45 -0500)]
Merge branch 'linux-linaro-lsk-v4.1' of git.linaro.org/kernel/linux-linaro-stable into ti-lsk-linux-4.1.y

TI-Feature: linaro-stable-4-1
TI-Tree: http://git.linaro.org/kernel/linux-linaro-stable.git
TI-Branch: linux-linaro-lsk-v4.1

* 'linux-linaro-lsk-v4.1' of http://git.linaro.org/kernel/linux-linaro-stable: (201 commits)
  arm64: KASAN depends on !(ARM64_16K_PAGES && ARM64_VA_BITS_48)
  arm64: kasan: fix issues reported by sparse
  ARM64: kasan: print memory assignment
  arm64: add KASAN support
  arm64: introduce VA_START macro - the first kernel virtual address.
  arm64: support initrd outside kernel linear map
  mm: add utility for early copy from unmapped ram
  arm64: Change memcpy in kernel to use the copy template file
  arm64: move PGD_SIZE definition to pgalloc.h
  arm64: use ENDPIPROC() to annotate position independent assembler routines
  PM / OPP: Rename structures for clarity
  PM / OPP: Fix incorrect comments
  PM / OPP: Initialize regulator pointer to an error value
  PM / OPP: Initialize u_volt_min/max to a valid value
  PM / OPP: Fix NULL pointer dereference crash when disabling OPPs
  cpufreq: dt: No need to allocate resources anymore
  cpufreq: dt: No need to fetch voltage-tolerance
  cpufreq: dt: Use dev_pm_opp_set_rate() to switch frequency
  cpufreq: dt: Reuse dev_pm_opp_get_max_transition_latency()
  cpufreq: dt: Unsupported OPPs are already disabled
  ...

Signed-off-by: Dan Murphy <DMurphy@ti.com>
5 years agocpufreq: voltdm: Fix function renames in cpufreq/opp backports
Dave Gerlach [Thu, 7 Apr 2016 01:56:08 +0000 (01:56 +0000)]
cpufreq: voltdm: Fix function renames in cpufreq/opp backports

The newest LSK branch merge introduced Commit 1200951bcd46 ("PM / OPP:
Rename opp init/free table routines") which renamed of_init/free_opp_table
to of_add/remove_opp_table and Commit fdba5906018c ("PM / OPP: Prefix
exported opp routines with dev_pm_opp_") which added prefixes so rename our
use of of_init/free_opp_table to reflect the proper new names otherwise
a build error will be seen.

Fixes: d3e2dd94ed47 ("cpufreq: cpufreq-voltdm: Split cpufreq-dt to use clk
rate-change notifiers")
Signed-off-by: Dave Gerlach <d-gerlach@ti.com>
5 years agokasan: fix kmemleak false-positive in kasan_module_alloc()
Andrey Ryabinin [Fri, 20 Nov 2015 23:57:18 +0000 (15:57 -0800)]
kasan: fix kmemleak false-positive in kasan_module_alloc()

Kmemleak reports the following leak:

unreferenced object 0xfffffbfff41ea000 (size 20480):
comm "modprobe", pid 65199, jiffies 4298875551 (age 542.568s)
hex dump (first 32 bytes):
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
backtrace:
  [<ffffffff82354f5e>] kmemleak_alloc+0x4e/0xc0
  [<ffffffff8152e718>] __vmalloc_node_range+0x4b8/0x740
  [<ffffffff81574072>] kasan_module_alloc+0x72/0xc0
  [<ffffffff810efe68>] module_alloc+0x78/0xb0
  [<ffffffff812f6a24>] module_alloc_update_bounds+0x14/0x70
  [<ffffffff812f8184>] layout_and_allocate+0x16f4/0x3c90
  [<ffffffff812faa1f>] load_module+0x2ff/0x6690
  [<ffffffff813010b6>] SyS_finit_module+0x136/0x170
  [<ffffffff8239bbc9>] system_call_fastpath+0x16/0x1b
  [<ffffffffffffffff>] 0xffffffffffffffff

kasan_module_alloc() allocates shadow memory for module and frees it on
module unloading.  It doesn't store the pointer to allocated shadow memory
because it could be calculated from the shadowed address, i.e.
kasan_mem_to_shadow(addr).

Since kmemleak cannot find pointer to allocated shadow, it thinks that
memory leaked.

Use kmemleak_ignore() to tell kmemleak that this is not a leak and shadow
memory doesn't contain any pointers.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 459372545c9c0d6f491e280dccc8a54a61b60e56)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: always taint kernel on report
Andrey Ryabinin [Fri, 6 Nov 2015 02:51:26 +0000 (18:51 -0800)]
kasan: always taint kernel on report

Currently we already taint the kernel in some cases.  E.g.  if we hit some
bug in slub memory we call object_err() which will taint the kernel with
TAINT_BAD_PAGE flag.  But for other kind of bugs kernel left untainted.

Always taint with TAINT_BAD_PAGE if kasan found some bug.  This is useful
for automated testing.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Alexander Potapenko <glider@google.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit eb06f43f1c94d502b7867b0998e92cdabbc060bc)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: use IS_ALIGNED in memory_is_poisoned_8()
Xishi Qiu [Fri, 6 Nov 2015 02:51:21 +0000 (18:51 -0800)]
kasan: use IS_ALIGNED in memory_is_poisoned_8()

Use IS_ALIGNED() to determine whether the shadow span two bytes.  It
generates less code and more readable.  Also add some comments in shadow
check functions.

Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andrey Konovalov <adech.fo@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 10f702627e139e21465f4c9d44f63527bbca163c)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: fix last shadow judgement in memory_is_poisoned_16()
Xishi Qiu [Thu, 17 Sep 2015 23:01:43 +0000 (16:01 -0700)]
kasan: fix last shadow judgement in memory_is_poisoned_16()

The shadow which correspond 16 bytes memory may span 2 or 3 bytes.  If
the memory is aligned on 8, then the shadow takes only 2 bytes.  So we
check "shadow_first_bytes" is enough, and need not to call
"memory_is_poisoned_1(addr + 15);".  But the code "if
(likely(!last_byte))" is wrong judgement.

e.g.  addr=0, so last_byte = 15 & KASAN_SHADOW_MASK = 7, then the code
will continue to call "memory_is_poisoned_1(addr + 15);"

Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andrey Konovalov <adech.fo@gmail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Michal Marek <mmarek@suse.cz>
Cc: <zhongjiang@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 8d77a6d18ae9ccfd5eee1cc551ee4ac27fd41464)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: Fix a type conversion error
Wang Long [Fri, 6 Nov 2015 02:51:18 +0000 (18:51 -0800)]
kasan: Fix a type conversion error

The current KASAN code can not find the following out-of-bounds bugs:

        char *ptr;
        ptr = kmalloc(8, GFP_KERNEL);
        memset(ptr+7, 0, 2);

the cause of the problem is the type conversion error in
*memory_is_poisoned_n* function.  So this patch fix that.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit e0d57714394f5e2ce4e2f9bbebf48e3c7a7fd3be)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: update reference to kasan prototype repo
Andrey Konovalov [Fri, 6 Nov 2015 02:51:12 +0000 (18:51 -0800)]
kasan: update reference to kasan prototype repo

Update the reference to the kasan prototype repository on github, since it
was renamed.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 5d0926efe728e00afbd81a1e3c498222cf908d23)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: update log messages
Andrey Konovalov [Fri, 6 Nov 2015 02:51:03 +0000 (18:51 -0800)]
kasan: update log messages

We decided to use KASAN as the short name of the tool and
KernelAddressSanitizer as the full one.  Update log messages according to
that.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 25add7ec708170e4eaef1f9793a07803b2fb5c71)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: accurately determine the type of the bad access
Andrey Konovalov [Fri, 6 Nov 2015 02:51:01 +0000 (18:51 -0800)]
kasan: accurately determine the type of the bad access

Makes KASAN accurately determine the type of the bad access. If the shadow
byte value is in the [0, KASAN_SHADOW_SCALE_SIZE) range we can look at
the next shadow byte to determine the type of the access.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit cdf6a273dc4346277ab9d148ef29f6e058624a8c)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: update reported bug types for kernel memory accesses
Andrey Konovalov [Fri, 6 Nov 2015 02:50:58 +0000 (18:50 -0800)]
kasan: update reported bug types for kernel memory accesses

Update the names of the bad access types to better reflect the type of
the access that happended and make these error types "literals" that can
be used for classification and deduplication in scripts.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 0952d87fd6a6211ac51b2abdc5c066b49c651fd8)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: update reported bug types for not user nor kernel memory accesses
Andrey Konovalov [Fri, 6 Nov 2015 02:50:55 +0000 (18:50 -0800)]
kasan: update reported bug types for not user nor kernel memory accesses

Each access with address lower than
kasan_shadow_to_mem(KASAN_SHADOW_START) is reported as user-memory-access.
This is not always true, the accessed address might not be in user space.
Fix this by reporting such accesses as null-ptr-derefs or
wild-memory-accesses.

There's another reason for this change.  For userspace ASan we have a
bunch of systems that analyze error types for the purpose of
classification and deduplication.  Sooner of later we will write them to
KASAN as well.  Then clearly and explicitly stated error types will bring
value.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit e91210766341cb356ead7fd39f07493a3d00b80f)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agomm/kasan: prevent deadlock in kasan reporting
Aneesh Kumar K.V [Fri, 6 Nov 2015 02:50:51 +0000 (18:50 -0800)]
mm/kasan: prevent deadlock in kasan reporting

When we end up calling kasan_report in real mode, our shadow mapping for
the spinlock variable will show poisoned.  This will result in us calling
kasan_report_error with lock_report spin lock held.  To prevent this
disable kasan reporting when we are priting error w.r.t kasan.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit fc5aeeaf593278f07ffa4d97296e27423ecae867)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agomm/kasan: don't use kasan shadow pointer in generic functions
Aneesh Kumar K.V [Fri, 6 Nov 2015 02:50:48 +0000 (18:50 -0800)]
mm/kasan: don't use kasan shadow pointer in generic functions

We can't use generic functions like print_hex_dump to access kasan shadow
region.  This require us to setup another kasan shadow region for the
address passed (kasan shadow address).  Some architectures won't be able
to do that.  Hence make a copy of the shadow region row and pass that to
generic functions.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit f2377d4eaab2aabe1938b3974b5b94f5ba4c7ead)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agomm/kasan: MODULE_VADDR is not available on all archs
Aneesh Kumar K.V [Fri, 6 Nov 2015 02:50:46 +0000 (18:50 -0800)]
mm/kasan: MODULE_VADDR is not available on all archs

Use is_module_address instead

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 527f215b78976e94995dce7163b07539b576d519)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agomm/kasan: rename kasan_enabled() to kasan_report_enabled()
Aneesh Kumar K.V [Fri, 6 Nov 2015 02:50:43 +0000 (18:50 -0800)]
mm/kasan: rename kasan_enabled() to kasan_report_enabled()

The function only disable/enable reporting.  In the later patch we will be
adding a kasan early enable/disable.  Rename kasan_enabled to properly
reflect its function.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 0ba8663cbfae066fc504b858db7cbb7d03c2b872)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agox86/kasan, mm: Introduce generic kasan_populate_zero_shadow()
Andrey Ryabinin [Thu, 13 Aug 2015 05:37:24 +0000 (08:37 +0300)]
x86/kasan, mm: Introduce generic kasan_populate_zero_shadow()

Introduce generic kasan_populate_zero_shadow(shadow_start,
shadow_end). This function maps kasan_zero_page to the
[shadow_start, shadow_end] addresses.

This replaces x86_64 specific populate_zero_shadow() and will
be used for ARM64 in follow on patches.

The main changes from original version are:

 * Use p?d_populate*() instead of set_p?d()
 * Use memblock allocator directly instead of vmemmap_alloc_block()
 * __pa() instead of __pa_nodebug(). __pa() causes troubles
   iff we use it before kasan_early_init(). kasan_populate_zero_shadow()
   will be used later, so we ok with __pa() here.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Alexey Klimov <klimov.linux@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Keitel <dkeitel@codeaurora.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Yury <yury.norov@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/1439444244-26057-3-git-send-email-ryabinin.a.a@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit 69786cdb379bbc6eab14cf2393c1abd879316e85)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agox86/kasan: Define KASAN_SHADOW_OFFSET per architecture
Andrey Ryabinin [Thu, 13 Aug 2015 05:37:23 +0000 (08:37 +0300)]
x86/kasan: Define KASAN_SHADOW_OFFSET per architecture

Current definition of  KASAN_SHADOW_OFFSET in
include/linux/kasan.h will not work for upcomming arm64, so move
it to the arch header.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Alexey Klimov <klimov.linux@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Keitel <dkeitel@codeaurora.org>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Yury <yury.norov@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-mm@kvack.org
Link: http://lkml.kernel.org/r/1439444244-26057-2-git-send-email-ryabinin.a.a@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit 920e277e17f12870188f4564887a95ae9ac03e31)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agokasan: remove duplicate definition of the macro KASAN_FREE_PAGE
Wang Long [Thu, 25 Jun 2015 22:03:35 +0000 (15:03 -0700)]
kasan: remove duplicate definition of the macro KASAN_FREE_PAGE

Remove duplicate definition of the macro KASAN_FREE_PAGE in
mm/kasan/kasan.h

Signed-off-by: Wang Long <long.wanglong@huawei.com>
Acked-by: Andrey Ryabinin <a.ryabinin@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit bffacb9132a306b7e22bb6366e5b277f20f67465)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoMerge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1
Alex Shi [Fri, 8 Apr 2016 09:16:20 +0000 (17:16 +0800)]
Merge branch 'v4.1/topic/KASAN' into linux-linaro-lsk-v4.1

5 years agoarm64: KASAN depends on !(ARM64_16K_PAGES && ARM64_VA_BITS_48)
Andrey Ryabinin [Tue, 17 Nov 2015 15:47:08 +0000 (18:47 +0300)]
arm64: KASAN depends on !(ARM64_16K_PAGES && ARM64_VA_BITS_48)

On KASAN + 16K_PAGES + 48BIT_VA
 arch/arm64/mm/kasan_init.c: In function ‘kasan_early_init’:
 include/linux/compiler.h:484:38: error: call to ‘__compiletime_assert_95’ declared with attribute error: BUILD_BUG_ON failed: !IS_ALIGNED(KASAN_SHADOW_END, PGDIR_SIZE)
    _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)

Currently KASAN will not work on 16K_PAGES and 48BIT_VA, so
forbid such configuration to avoid above build failure.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reported-by: Suzuki K. Poulose <Suzuki.Poulose@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit f1b9032f61c0412082a240cb7245f8b79e09ae8d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: kasan: fix issues reported by sparse
Will Deacon [Tue, 13 Oct 2015 13:01:06 +0000 (14:01 +0100)]
arm64: kasan: fix issues reported by sparse

Sparse reports some new issues introduced by the kasan patches:

  arch/arm64/mm/kasan_init.c:91:13: warning: no previous prototype for
  'kasan_early_init' [-Wmissing-prototypes] void __init kasan_early_init(void)
             ^
  arch/arm64/mm/kasan_init.c:91:13: warning: symbol 'kasan_early_init'
  was not declared. Should it be static? [sparse]

This patch resolves the problem by adding a prototype for
kasan_early_init and marking the function as asmlinkage, since it's only
called from head.S.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Acked-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit 83040123fde42ec532d3b632efb5f7f84024e61d)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoARM64: kasan: print memory assignment
Linus Walleij [Mon, 12 Oct 2015 15:52:59 +0000 (18:52 +0300)]
ARM64: kasan: print memory assignment

This prints out the virtual memory assigned to KASan in the
boot crawl along with other memory assignments, if and only
if KASan is activated.

Example dmesg from the Juno Development board:

Memory: 1691156K/2080768K available (5465K kernel code, 444K rwdata,
2160K rodata, 340K init, 217K bss, 373228K reserved, 16384K cma-reserved)
Virtual kernel memory layout:
    kasan   : 0xffffff8000000000 - 0xffffff9000000000   (    64 GB)
    vmalloc : 0xffffff9000000000 - 0xffffffbdbfff0000   (   182 GB)
    vmemmap : 0xffffffbdc0000000 - 0xffffffbfc0000000   (     8 GB maximum)
              0xffffffbdc2000000 - 0xffffffbdc3fc0000   (    31 MB actual)
    fixed   : 0xffffffbffabfd000 - 0xffffffbffac00000   (    12 KB)
    PCI I/O : 0xffffffbffae00000 - 0xffffffbffbe00000   (    16 MB)
    modules : 0xffffffbffc000000 - 0xffffffc000000000   (    64 MB)
    memory  : 0xffffffc000000000 - 0xffffffc07f000000   (  2032 MB)
      .init : 0xffffffc0007f5000 - 0xffffffc00084a000   (   340 KB)
      .text : 0xffffffc000080000 - 0xffffffc0007f45b4   (  7634 KB)
      .data : 0xffffffc000850000 - 0xffffffc0008bf200   (   445 KB)

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit ee7f881b59de4e0e0be250fd0c5d4ade3e30ec34)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
5 years agoarm64: add KASAN support
Alex Shi [Fri, 8 Apr 2016 09:11:20 +0000 (17:11 +0800)]
arm64: add KASAN support

This patch adds arch specific code for kernel address sanitizer
(see Documentation/kasan.txt).

1/8 of kernel addresses reserved for shadow memory. There was no
big enough hole for this, so virtual addresses for shadow were
stolen from vmalloc area.

At early boot stage the whole shadow region populated with just
one physical page (kasan_zero_page). Later, this page reused
as readonly zero shadow for some memory that KASan currently
don't track (vmalloc).
After mapping the physical memory, pages for shadow memory are
allocated and mapped.

Functions like memset/memmove/memcpy do a lot of memory accesses.
If bad pointer passed to one of these function it is important
to catch this. Compiler's instrumentation cannot do this since
these functions are written in assembly.
KASan replaces memory functions with manually instrumented variants.
Original functions declared as weak symbols so strong definitions
in mm/kasan/kasan.c could replace them. Original functions have aliases
with '__' prefix in name, so we could call non-instrumented variant
if needed.
Some files built without kasan instrumentation (e.g. mm/slub.c).
Original mem* function replaced (via #define) with prefixed variants
to disable memory access checks for such files.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit 39d114ddc68223022c12ae3a1573912bc4b585e5)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
Conflicts:
remove efitstub from arch/arm64/kernel/image.h, since we
don't have it.

5 years agoarm64: introduce VA_START macro - the first kernel virtual address.
Andrey Ryabinin [Thu, 17 Sep 2015 09:38:07 +0000 (12:38 +0300)]
arm64: introduce VA_START macro - the first kernel virtual address.

In order to not use lengthy (UL(0xffffffffffffffff) << VA_BITS) everywhere,
replace it with VA_START.

Signed-off-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit 127db024a7baee9874014dac33628253f438b4da)
Signed-off-by: Alex Shi <alex.shi@linaro.org>