Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1628727ybb; Fri, 29 Mar 2019 08:11:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxp+Mm6qnqVYLRcpBWY3HonANXQYOwlKVDFzCl+0lyqttkup3KQGPh4OPWra3Xta71VhZIn X-Received: by 2002:a17:902:7d81:: with SMTP id a1mr42054065plm.202.1553872309707; Fri, 29 Mar 2019 08:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553872309; cv=none; d=google.com; s=arc-20160816; b=zXl2dlfvZNc58YKJzOwLsYG5xNMWCBMzRQOFfIWmZsh7i76nZQtsTarkgZx0ggtFeF xdaKNOzpTEr5KnlQyIeiX3/gBLQ6zk6JT8OU0SoFR1u31RDSUNAHmbuihRWkQg+0IACe 8vnj3GvmIQ7RY0swWH4FA4CFs/kTYWyH1Kq/zlI0vesjcq2zq0stMgKRDnskC6WXjtNK F/h2wOT9ZFdoncuFbYgvI/294PL7NMlJy0QHQzOzN4bhHtSEwlwE4WmmbWG4vYau2LsT vC4gjfBmdVRbLarRMlnlydJgNg9AsuxSp5Fda/sfyS2hmer201CSqz43AYb/wKziMu+t G19Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=p/SF5UDnnsoikuP9+i9chV5gvhPw5CFNUl+Uo9nx9IM=; b=V0N4xOZLgEHSK+L2gIKQYlESja6yU6dkxP9l3hEpo48TeuEbg6Rq1fE10BKI1lhLSS mK3IZ16NXQLpTiFRLKFuY7jMgooOKhE9PqpBhvmRuDbqr1BVVOmp0fL+Z//9Q3TPvR1D QHoPhVUX4hSosp1dxpysl+ymcbbwOurPGLoWsVD0B6EiGjs/qXkoR6ogtfeJyqHvWh27 /Kp5ROOkikwVz3ALViLRs53Y5KZ9H2sHEhQJ+0P8To/rHhR9rPyMkI/6EDfOib3i+tdh 0vx7R0LY1L4swxfemR4Dbowi49KnRCig/4Ao3X0AgulsLPPce+Zg0XY9U1fH6rdyKgda 6Dgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h14si2047671pgv.168.2019.03.29.08.11.32; Fri, 29 Mar 2019 08:11:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729379AbfC2PKl (ORCPT + 99 others); Fri, 29 Mar 2019 11:10:41 -0400 Received: from 8bytes.org ([81.169.241.247]:59770 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728848AbfC2PKl (ORCPT ); Fri, 29 Mar 2019 11:10:41 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 2C68A303; Fri, 29 Mar 2019 16:10:40 +0100 (CET) From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, Gary R Hook , Joerg Roedel Subject: [PATCH v2] iommu/amd: Reserve exclusion range in iova-domain Date: Fri, 29 Mar 2019 16:10:37 +0100 Message-Id: <20190329151037.19112-1-joro@8bytes.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel If a device has an exclusion range specified in the IVRS table, this region needs to be reserved in the iova-domain of that device. This hasn't happened until now and can cause data corruption on data transfered with these devices. Treat exclusion ranges as reserved regions in the iommu-core to fix the problem. Fixes: be2a022c0dd0 ('x86, AMD IOMMU: add functions to parse IOMMU memory mapping requirements for devices') Signed-off-by: Joerg Roedel --- drivers/iommu/amd_iommu.c | 9 ++++++--- drivers/iommu/amd_iommu_init.c | 7 ++++--- drivers/iommu/amd_iommu_types.h | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 21cb088d6687..f7cdd2ab7f11 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3169,21 +3169,24 @@ static void amd_iommu_get_resv_regions(struct device *dev, return; list_for_each_entry(entry, &amd_iommu_unity_map, list) { + int type, prot = 0; size_t length; - int prot = 0; if (devid < entry->devid_start || devid > entry->devid_end) continue; + type = IOMMU_RESV_DIRECT; length = entry->address_end - entry->address_start; if (entry->prot & IOMMU_PROT_IR) prot |= IOMMU_READ; if (entry->prot & IOMMU_PROT_IW) prot |= IOMMU_WRITE; + if (entry->prot & IOMMU_UNITY_MAP_FLAG_EXCL_RANGE) + /* Exclusion range */ + type = IOMMU_RESV_RESERVED; region = iommu_alloc_resv_region(entry->address_start, - length, prot, - IOMMU_RESV_DIRECT); + length, prot, type); if (!region) { dev_err(dev, "Out of memory allocating dm-regions\n"); return; diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index f773792d77fd..1b1378619fc9 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2013,6 +2013,9 @@ static int __init init_unity_map_range(struct ivmd_header *m) if (e == NULL) return -ENOMEM; + if (m->flags & IVMD_FLAG_EXCL_RANGE) + init_exclusion_range(m); + switch (m->type) { default: kfree(e); @@ -2059,9 +2062,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table) while (p < end) { m = (struct ivmd_header *)p; - if (m->flags & IVMD_FLAG_EXCL_RANGE) - init_exclusion_range(m); - else if (m->flags & IVMD_FLAG_UNITY_MAP) + if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE)) init_unity_map_range(m); p += m->length; diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index eae0741f72dc..87965e4d9647 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -374,6 +374,8 @@ #define IOMMU_PROT_IR 0x01 #define IOMMU_PROT_IW 0x02 +#define IOMMU_UNITY_MAP_FLAG_EXCL_RANGE (1 << 2) + /* IOMMU capabilities */ #define IOMMU_CAP_IOTLB 24 #define IOMMU_CAP_NPCACHE 26 -- 2.16.4