Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2846642yba; Mon, 22 Apr 2019 14:10:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyibGqYSJmYkjEdF+q1EL0nWUSDeElHvnvRjvjfrTRRWHXpGvXC/sQRGaOTchdIh43vS+nX X-Received: by 2002:a62:6ec6:: with SMTP id j189mr23595430pfc.195.1555967409593; Mon, 22 Apr 2019 14:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555967409; cv=none; d=google.com; s=arc-20160816; b=gnW4qdx4Vz+pN1/lzcc3WTlYyt7bu3Vr1rLUwav8nY2Kq6RoKEUAjRBhrYZgbnGoVw OPiuZuwf87OdMdAR0ewrRN0pQm7noTHHJ5EfdiRf3A1oqXnWm7FVPH6pM1iW1O0E92Fs +uFVUWM98X03rnywhb9Pko2gyoe+BgURtKJlWh5AwrFLGnHtx28Qhjf6h3RTz9GDIask tgeYC+jA+G7dbQJk0iJJt8XgF+CVk/ymfxk1TQLsq828WMAr4IzKL5M/eA/D8yXkIBEo fr9dYtr7vYSmWKtHyZ8xx+tPo0YFafEdpZwySCiLHMwFshbfAaUICbVDqzfzVfclkQiA LVaA== 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=HjTpcMqIGw8xPe15xUX+GDW2nJrmmGFjGvsmNi1dq70=; b=ftCiv56LgqTNswf/vvRY4zcwwMOfXhYT5rc6niIJ1CKdS6gojBPY6e6Oa/wA9UWD/P gc3JEc+8109P1YcwXcrhDIWy7ZtszPa2P6yMDtNRZ+zDonO4m8sY4g8xtr5PVix9VJzZ aeK0XC1bmGb6cSBnYw7wMvU/PE0DxPfzV9I92mrpGHTVYao+AbstWz4O/9Ia8vV8J9fn qfZQGI3Pblh2pv3GIwqeBdD9DiAn/8Zxj4cxedUEU+mwEHw1TXTSeP9TJ/DG6egcPch9 lu0+LK7iIezr+D7gc00oQLQMc3qxG2NxFnqJA4YYlGPcdzbSBfLLpNBpyE48RfyA9nmn Xwsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pFpylcyO; 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 f5si13802484plo.13.2019.04.22.14.09.54; Mon, 22 Apr 2019 14:10:09 -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=pFpylcyO; 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 S1730259AbfDVTrY (ORCPT + 99 others); Mon, 22 Apr 2019 15:47:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730245AbfDVTrV (ORCPT ); Mon, 22 Apr 2019 15:47:21 -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 29B5B21906; Mon, 22 Apr 2019 19:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962440; bh=SWLbllo8DxeoSqq5pqLlUBhpVqixTFUZacJ0l7z86bM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pFpylcyOyelgnnGrIJ3Z/rWvYOF23TnDBAyIzKvNh8vQ/bESB0HljZEmAr98/BmC/ 1ZyCM8uHZBUC6AbPHGWpfnE2/bK3Y46PvrI5MbYBDuuqeNSI7jjaHu9bgwwzBuBUkL Az+dFBylK27D55aXM/FYo7NESiue81Sim/SW26TU= 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 4.19 65/68] iommu/amd: Reserve exclusion range in iova-domain Date: Mon, 22 Apr 2019 15:45:13 -0400 Message-Id: <20190422194516.11634-65-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-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 0b3877681e4a..8d9920ff4134 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3119,21 +3119,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 e062ab9687c7..be3801d43d48 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -2001,6 +2001,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); @@ -2047,9 +2050,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 e2b342e65a7b..69f3d4c95b53 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -373,6 +373,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