Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3090395yba; Mon, 22 Apr 2019 19:42:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDNDW8Z2hLYHUMtywvNAH4KAJpTtcHlK29qrYp5mYiTqp9gPcASexwHMcpomTgTQ5j67zr X-Received: by 2002:a65:5342:: with SMTP id w2mr4024389pgr.220.1555987374639; Mon, 22 Apr 2019 19:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555987374; cv=none; d=google.com; s=arc-20160816; b=jJlQ9B3yM8J6zQfeYbWnjEujnNgFp8Sez/ReN+dOpNOar6pv49zZanALzJO+aWSK9G M6scJJivlPkwAwI61WZBhPdJIMVWCrJDgVK9n31wx39hhInYcAb6yTURx7potJGwzbpv XOqCxKoBswTBlS0NDnzz6tlhAhu/mN1LVGzzv4XOjN9aLFeRxB8osXPVC8pscfCqLjb/ LTMP3jU0HFbxpkjt+WbQxKRIFHI4mfW8adHrmKVT/cCXuIGshF04EZqT2Oemiyn6WCuv eN1+qf+QLJ6mjWa+f/cR5qXQ1KIfLNPEmmDBmE5nbEdef/dqeBgLkW0NRmg7QOelsqRa tfLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u9hsZgnqNZsxig44wCJFoB9+VPplTTzWZee5qDBd1eA=; b=z7dr5okE8/7YBGtbrLsWIPPOZzEvaCEI3K70df/OVppqdCApKirHp6ZV3rHHURsaRO bTQrGl4b1RSQpHTNDu9J94ZlMDxQ73hsOwHkovrSSHKepl0tZzPjxOnDnh6wJ40riSR1 Qe1kx4ti/YVaKsTvpFHvyNwCaGEp8HppoUWF444i7XJUBwD5WVPE9Tvi8f17xQq4Xwjz 2J2+SGnTQ6JFKJt1NFTeAiBXREJ4JvfPMyXi7VzT4PVmXuqMC8sCzjRqiU4+iBuS+8jp XWCZTM5JXx+CseHOeatosXyWHK+MGJQXy0J5JAv/jrKYnBZN8bf6yV7d21S3/d3ZKQ2D xVUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jjfhBAP9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si15728919pld.190.2019.04.22.19.42.37; Mon, 22 Apr 2019 19:42:54 -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; dkim=pass header.i=@kernel.org header.s=default header.b=jjfhBAP9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732245AbfDVUFT (ORCPT + 99 others); Mon, 22 Apr 2019 16:05:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46616 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729664AbfDVTpI (ORCPT ); Mon, 22 Apr 2019 15:45:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB3DD21902; Mon, 22 Apr 2019 19:45:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962307; bh=IAPikkAGx80dK1h5T9epE5Abk7jyy3k1wkTycyh9lBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jjfhBAP9sWOr6bN6PcptyyaUHBWT6h3bhLSS6rxdJtiYCSAbJ2Rxa9zNe17yXiSrq PCwqA3SohJKWYv9HcCX/49nJF4DgD160stQee8UQwyUzaVUbSkLuEOT66W0Tz0Wi4q /fFlN4hZm6FCwr1dyyQoF8SsuxNQ51FI9861pTZM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Joerg Roedel , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 5.0 94/98] iommu/amd: Reserve exclusion range in iova-domain Date: Mon, 22 Apr 2019 15:42:01 -0400 Message-Id: <20190422194205.10404-94-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel [ Upstream commit 8aafaaf2212192012f5bae305bb31cdf7681d777 ] 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 Reviewed-by: Gary R Hook Signed-off-by: Sasha Levin (Microsoft) --- 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 e628ef23418f..55b3e4b9d5dc 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3166,21 +3166,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) { pr_err("Out of memory allocating dm-regions for %s\n", dev_name(dev)); diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 66123b911ec8..84fa5b22371e 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.19.1