Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp342032ybb; Thu, 28 Mar 2019 03:46:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxB9zWSxkqoV6/tvVFqLaNV398dFGcNyjVGygbIVZdwUz74WpIAgIomogffluFqQthbgd+H X-Received: by 2002:a62:1795:: with SMTP id 143mr5861536pfx.104.1553769961233; Thu, 28 Mar 2019 03:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553769961; cv=none; d=google.com; s=arc-20160816; b=fRa4FgBiw3o0SI7tIxBvpf6R7SMqk9wGMMdhTvlRxb5nJGEKVJ9FG7UJjfi48F8qBI TUkzISrWGflbLhWNcLyYIZRXN+INqDcOcy+Zi0fqy/YnJnIGX5HZ2HpUu00QcogWjFbG 9b5tEHLKF75vl0orWuOfqQAH+qK4C9BatQL0QJxiW1Cj5kMaeSSSmi3HL/tnStdefB+Z hMYNYmGG0S0h5xDIbEE7UFnP3eB9Y8gXMDH/zoO4Fseu9qOPpWD/FEBwNow98poVvvPe NWuUNI4jzLLc5siylR7uymauKs9dweXpc/C0qMmnmFLE9PgnixyAA2CidV1exm9l7+eH vKfw== 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=1O1CSxx7kzA+e71yYhxTV+DvQcw4pcTviIN90lwR9wo=; b=iSXCYNrbwdHKCd7zmq3BOcZGzKcFjPBcVDbfOSA9BcJEkL0Df2TEgt8LYcYwidU8RL hRquuF3HvLySsFMt1ob+Js9MJFZS9uEEsCQ9zLkU64NcLS8TLmA8Glwy8wpzL7R6SMPy 1JGPcqjT0CukQ6f7SQzHJxdb79kbuPijlbpbaObxlzflG+VcKFYdBZ3vGx0QnO1Xm5Tp ql1fwUBkOJlRvH/BZMeD+FD7Rw6wXQDubYYHFl1hxoGO4u8Op9e8A94A3kbjOuwi1H8U vrH32eFCdeCQDZgeWXyC+zJDCBKO8IOxugTuARqc6VxL3T+YNIj/BXcZ+nDE14JrShvN 894w== 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 k193si21265112pfc.150.2019.03.28.03.45.45; Thu, 28 Mar 2019 03:46:01 -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 S1726214AbfC1KpE (ORCPT + 99 others); Thu, 28 Mar 2019 06:45:04 -0400 Received: from 8bytes.org ([81.169.241.247]:59502 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbfC1KpE (ORCPT ); Thu, 28 Mar 2019 06:45:04 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id ED9B2327; Thu, 28 Mar 2019 11:45:02 +0100 (CET) From: Joerg Roedel To: iommu@lists.linux-foundation.org Cc: linux-kernel@vger.kernel.org, Joerg Roedel Subject: [PATCH] iommu/amd: Reserve exclusion range in iova-domain Date: Thu, 28 Mar 2019 11:44:59 +0100 Message-Id: <20190328104459.18589-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 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 21cb088d6687..2a8d2806d5b9 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 & (1 << 2)) + /* 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; -- 2.16.4