iommu/arm-smmu: Fix sign-extension of upstream bus addresses at stage 1
authorWill Deacon <will.deacon@arm.com>
Fri, 8 May 2015 16:44:22 +0000 (17:44 +0100)
committerJoerg Roedel <jroedel@suse.de>
Mon, 11 May 2015 16:36:20 +0000 (18:36 +0200)
commit5dc5616ee850eaba055bb469a6c4a471d489140e
tree5c369d17001018c564828b9f95a99d411f316621
parentd9e7eb152bb24f06028a0d10b054e39ebdf14f9c
iommu/arm-smmu: Fix sign-extension of upstream bus addresses at stage 1

Stage 1 translation is controlled by two sets of page tables (TTBR0 and
TTBR1) which grow up and down from zero respectively in the ARMv8
translation regime. For the SMMU, we only care about TTBR0 and, in the
case of a 48-bit virtual space, we expect to map virtual addresses 0x0
through to 0xffff_ffff_ffff.

Given that some masters may be incapable of emitting virtual addresses
targetting TTBR1 (e.g. because they sit on a 48-bit bus), the SMMU
architecture allows bit 47 to be sign-extended, halving the virtual
range of TTBR0 but allowing TTBR1 to be used. This is controlled by the
SEP field in TTBCR2.

The SMMU driver incorrectly enables this sign-extension feature, which
causes problems when userspace addresses are programmed into a master
device with the SMMU expecting to map the incoming transactions via
TTBR0; if the top bit of address is set, we will instead get a
translation fault since TTBR1 walks are disabled in the TTBCR.

This patch fixes the issue by disabling sign-extension of a fixed
virtual address bit and instead basing the behaviour on the upstream bus
size: the incoming address is zero extended unless the upstream bus is
only 49 bits wide, in which case bit 48 is used as the sign bit and is
replicated to the upper bits.

Cc: <stable@vger.kernel.org> # v4.0+
Reported-by: Varun Sethi <varun.sethi@freescale.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/arm-smmu.c