Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7369788yba; Thu, 2 May 2019 08:43:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1HfbsXRjvGY28fuDvliE7n3KKHIZ/AGoKKl7Is+frf+Cpq5+dvNcCcntlrS9b+EjBoJUF X-Received: by 2002:a63:f40d:: with SMTP id g13mr4735997pgi.345.1556811816994; Thu, 02 May 2019 08:43:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556811816; cv=none; d=google.com; s=arc-20160816; b=U5aKfb/9mGUvcAgbULBOhEzCLFCl4t/AIfknzU2SVXKhUCVX1ckp3QM0utI874zgG3 Leku1qDxk9f5Zo+YgNcchgwqpXO4XnMg3tDIaHtB1iepiG5iXj/0vxsci7kIXoTx29jt h+chLDuQQnLICYR/HrGvYr+K0NRIblb9SUNocvuxXTRmRdRbqxK3olk4WTFR9E2alL4V TKr6MmAAACrpfgQJLmf2uGIqFr7js1WRV3idw0+E9CjVZwgcZ9SOnAgL1c7MzXQYQSx3 8BVFxTQHtSJBeVyMkculOyIy3Lou4TAV6gEfSW49G6MxYA/C5ZpGKF198UjrD2VBtWlQ IsWg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=A6lYSySpAtRfHuCTYVcbfbwKxputfVZirYpCm9mCyjA=; b=Vo/0+5GpUXqddDboXyvQWCMOmvvNenoL9aRyEdwVi27Jk4x3s4Trx4PLKiOTYvnaZi iozsqs9Vl0ws1zfuk0kyUY6sFi9xzZjfNPFOgUwLB08sThiFORAGFrb0knxFB6zvwEgY 8J/dWzok01fMZ9oVnfK9K2Clzer8eRoL166fJ09Zabj1fS+KnskmlY9eR9iTjkog7DyN rmVu97YacQXQCKInFMhJoPoSMvspUpzeJ5MTMt8Lec5p1ovsYGy7H9He2Hj+ce0prfBj SXBNhZswfAvxK+VejDRGTOLq2HFUKfNZ3+eUm1G8E3tcwgVFrtTtmHc+7wFiVq+H+2bM FVog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UcFITOh2; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si42497187pgj.46.2019.05.02.08.43.22; Thu, 02 May 2019 08:43:36 -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=UcFITOh2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727769AbfEBP2U (ORCPT + 99 others); Thu, 2 May 2019 11:28:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:45384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbfEBP2O (ORCPT ); Thu, 2 May 2019 11:28:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AD4522085A; Thu, 2 May 2019 15:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810893; bh=1VVvQ42yPx4UFn5CcpwxO3KJv48pAmeUFKCkKRMgnGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UcFITOh2ZUslxwf8xSWcNtQgxcV92ZNfyG/TT9teVNZUxiOonXrE4Ij4+fTfW6xaa +LMeTfegN7luMu5nKwaEULXDVZsAvx+wmZdx5qlktu9qOjsTZ3AybyFPB1iF7k7Y/W qWIxRLMqsc2bNdyl6o2k+9cyDWHpEAv+LgSKDwUg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Joerg Roedel , Gary R Hook , "Sasha Levin (Microsoft)" Subject: [PATCH 4.19 69/72] iommu/amd: Reserve exclusion range in iova-domain Date: Thu, 2 May 2019 17:21:31 +0200 Message-Id: <20190502143338.751301775@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143333.437607839@linuxfoundation.org> References: <20190502143333.437607839@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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