Skip to contentSkip to conversation

iommu: replace IOMMU_EXEC with IOMMU_EXEC and update ARM SMMU driver

PATCH In review Antonios Motakis 4 participants 8 messages Oct 13, 2014 – Oct 22, 2014 3 messages not in the archive IOMMU

lore
Share & tools
lore
#0 lore raw

cover iommu: replace IOMMU_EXEC with IOMMU_EXEC and update ARM SMMU driver

This patch series applies to Joerg Roedel's iommu/next branch, commit 09b5269a. It replaces the IOMMU_EXEC flag used by the ARM SMMU driver to IOMMU_NOEXEC. This is more enforceable, since the lack of the flag on hardware that doesn't support it implies that the target memory will be executable.

Antonios Motakis (3):
iommu/arm-smmu: change IOMMU_EXEC to IOMMU_NOEXEC
iommu: add capability IOMMU_CAP_NOEXEC iommu/arm-smmu: add IOMMU_CAP_NOEXEC to the ARM SMMU driver

 drivers/iommu/arm-smmu.c | 11 +++++++----
 include/linux/iommu.h    |  3 ++-
 2 files changed, 9 insertions(+), 5 deletions(-)
Signature · 1 line
2.1.1
#1 lore raw

PATCH 1/3 iommu/arm-smmu: change IOMMU_EXEC to IOMMU_NOEXEC

Exposing the XN flag of the SMMU driver as IOMMU_NOEXEC instead of IOMMU_EXEC makes it enforceable, since for IOMMUs that don't support the XN flag pages will always be executable.

---
 drivers/iommu/arm-smmu.c | 9 +++++----
 include/linux/iommu.h    | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/iommu/arm-smmu.c +5 -4
index 60558f7..566c176 100644
@@ -1281,7 +1281,7 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
 				   unsigned long pfn, int prot, int stage)
 {
 	pte_t *pte, *start;
-	pteval_t pteval = ARM_SMMU_PTE_PAGE | ARM_SMMU_PTE_AF | ARM_SMMU_PTE_XN;
+	pteval_t pteval = ARM_SMMU_PTE_PAGE | ARM_SMMU_PTE_AF;
 
 	if (pmd_none(*pmd)) {
 		/* Allocate a new set of tables */
@@ -1315,10 +1315,11 @@ static int arm_smmu_alloc_init_pte(struct arm_smmu_device *smmu, pmd_t *pmd,
 			pteval |= ARM_SMMU_PTE_MEMATTR_NC;
 	}
 
+	if (prot & IOMMU_NOEXEC)
+		pteval |= ARM_SMMU_PTE_XN;
+
 	/* If no access, create a faulting entry to avoid TLB fills */
-	if (prot & IOMMU_EXEC)
-		pteval &= ~ARM_SMMU_PTE_XN;
-	else if (!(prot & (IOMMU_READ | IOMMU_WRITE)))
+	if (!(prot & (IOMMU_READ | IOMMU_WRITE)))
 		pteval &= ~ARM_SMMU_PTE_PAGE;
 
 	pteval |= ARM_SMMU_PTE_SH_IS;
include/linux/iommu.h +1 -1
index 379a617..5f6f71c 100644
@@ -27,7 +27,7 @@
 #define IOMMU_READ	(1 << 0)
 #define IOMMU_WRITE	(1 << 1)
 #define IOMMU_CACHE	(1 << 2) /* DMA cache coherency */
-#define IOMMU_EXEC	(1 << 3)
+#define IOMMU_NOEXEC	(1 << 3)
 
 struct iommu_ops;
 struct iommu_group;
Signature · 1 line
2.1.1
#2 lore raw

PATCH 2/3 iommu: add capability IOMMU_CAP_NOEXEC

In reply to Antonios Motakis

Some IOMMUs accept an IOMMU_NOEXEC protection flag in addition to IOMMU_READ and IOMMU_WRITE. Expose this as an IOMMU capability.

---
 include/linux/iommu.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/iommu.h +1 -0
index 5f6f71c..ba026f1 100644
@@ -61,6 +61,7 @@ enum iommu_cap {
 	IOMMU_CAP_CACHE_COHERENCY,	/* IOMMU can enforce cache coherent DMA
 					   transactions */
 	IOMMU_CAP_INTR_REMAP,		/* IOMMU supports interrupt isolation */
+	IOMMU_CAP_NOEXEC,		/* IOMMU_NOEXEC flag */
 };
 
 /*
Signature · 1 line
2.1.1
#3 lore raw

PATCH 3/3 iommu/arm-smmu: add IOMMU_CAP_NOEXEC to the ARM SMMU driver

In reply to Antonios Motakis

The ARM SMMU supports the IOMMU_NOEXEC protection flag. Add the corresponding IOMMU capability.

---
 drivers/iommu/arm-smmu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/arm-smmu.c +2 -0
index 566c176..c8fc02f 100644
@@ -1569,6 +1569,8 @@ static bool arm_smmu_capable(enum iommu_cap cap)
 		return true;
 	case IOMMU_CAP_INTR_REMAP:
 		return true; /* MSIs are just memory writes */
+	case IOMMU_CAP_NOEXEC:
+		return true;
 	default:
 		return false;
 	}
Signature · 1 line
2.1.1

A message that is not in the archive (sent off-list or not yet received): 1413205579-6124-1-git-send-email-a.motakis-lrHrjnjw1UfHK3s98zE1ajGjJy/[email protected]

#5 lore raw

Hi Antonios,

Quoted 4 lines · Antonios Motakis

This patch series applies to Joerg Roedel's iommu/next branch, commit 09b5269a. It replaces the IOMMU_EXEC flag used by the ARM SMMU driver to IOMMU_NOEXEC. This is more enforceable, since the lack of the flag on hardware that doesn't support it implies that the target memory will be executable.

Looks good to me; I'll take this via the arm-smmu tree and send it to Joerg along with anything else that gets queued for 3.19.

Thanks,

Will

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 8 lines · Will Deacon
Quoted 4 lines · Antonios Motakis

This patch series applies to Joerg Roedel's iommu/next branch, commit 09b5269a. It replaces the IOMMU_EXEC flag used by the ARM SMMU driver to IOMMU_NOEXEC. This is more enforceable, since the lack of the flag on hardware that doesn't support it implies that the target memory will be executable.

Looks good to me; I'll take this via the arm-smmu tree and send it to Joerg along with anything else that gets queued for 3.19.

The 0-day builder spotted a new warning from this series:

drivers/iommu/amd_iommu.c: In function 'amd_iommu_capable':

Quoted 1 line
Quoted 1 line

drivers/iommu/amd_iommu.c:3409:2: warning: enumeration value 'IOMMU_CAP_NOEXEC' not handled in switch [-Wswitch]

     switch (cap) {
     ^

I fixed it with the patch below, but I'd appreciate you and Joerg taking a look too.

Cheers,

Will

--->8

drivers/iommu/amd_iommu.c +2 -0
index 505a9adac2d5..3d78a8fb5a6a 100644
@@ -3411,6 +3411,8 @@ static bool amd_iommu_capable(enum iommu_cap cap)
                return true;
        case IOMMU_CAP_INTR_REMAP:
                return (irq_remapping_enabled == 1);
+       case IOMMU_CAP_NOEXEC:
+               return false;
        }
 
        return false;

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 12 lines · Will Deacon
Quoted 8 lines · Will Deacon
Quoted 4 lines · Antonios Motakis

This patch series applies to Joerg Roedel's iommu/next branch, commit 09b5269a. It replaces the IOMMU_EXEC flag used by the ARM SMMU driver to IOMMU_NOEXEC. This is more enforceable, since the lack of the flag on hardware that doesn't support it implies that the target memory will be executable.

Looks good to me; I'll take this via the arm-smmu tree and send it to Joerg along with anything else that gets queued for 3.19.

The 0-day builder spotted a new warning from this series:

Quoted 8 lines

drivers/iommu/amd_iommu.c: In function 'amd_iommu_capable':

Quoted 1 line
Quoted 1 line

drivers/iommu/amd_iommu.c:3409:2: warning: enumeration value 'IOMMU_CAP_NOEXEC' not handled in switch [-Wswitch]

     switch (cap) {
     ^

I fixed it with the patch below, but I'd appreciate you and Joerg taking a look too.

Maybe a "default:" case would be more appropriate, in order to avoid a similar situation in the future?

Quoted 19 lines

Cheers,

Will

--->8

drivers/iommu/amd_iommu.c +2 -0
index 505a9adac2d5..3d78a8fb5a6a 100644
@@ -3411,6 +3411,8 @@ static bool amd_iommu_capable(enum iommu_cap cap)
                return true;
        case IOMMU_CAP_INTR_REMAP:
                return (irq_remapping_enabled == 1);
+       case IOMMU_CAP_NOEXEC:
+               return false;
        }
 
        return false;
Signature · 2 lines
Antonios Motakis
Virtual Open Systems
#10 lore raw
In reply to a message not in the archive
Quoted 31 lines · Will Deacon
Quoted 8 lines · Will Deacon
Quoted 4 lines · Antonios Motakis

This patch series applies to Joerg Roedel's iommu/next branch, commit 09b5269a. It replaces the IOMMU_EXEC flag used by the ARM SMMU driver to IOMMU_NOEXEC. This is more enforceable, since the lack of the flag on hardware that doesn't support it implies that the target memory will be executable.

Looks good to me; I'll take this via the arm-smmu tree and send it to Joerg along with anything else that gets queued for 3.19.

The 0-day builder spotted a new warning from this series:

drivers/iommu/amd_iommu.c: In function 'amd_iommu_capable':

Quoted 1 line
Quoted 1 line

drivers/iommu/amd_iommu.c:3409:2: warning: enumeration value 'IOMMU_CAP_NOEXEC' not handled in switch [-Wswitch]

     switch (cap) {
     ^

I fixed it with the patch below, but I'd appreciate you and Joerg taking a look too.

Cheers,

Will

--->8

drivers/iommu/amd_iommu.c +0 -0
index 505a9adac2d5..3d78a8fb5a6a 100644

drivers/iommu/amd_iommu.c static bool amd_iommu_capable(enum iommu_cap cap) · line 3416

Quoted 6 lines
drivers/iommu/amd_iommu.c +2 -0
@@ -3411,6 +3411,8 @@ static bool amd_iommu_capable(enum iommu_cap cap)
                return true;
        case IOMMU_CAP_INTR_REMAP:
                return (irq_remapping_enabled == 1);
+       case IOMMU_CAP_NOEXEC:
+               return false;
        }

Looks good to me.