From patchwork Fri Sep 14 14:30:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 146706 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp780278ljw; Fri, 14 Sep 2018 07:30:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY5POI1NSNV8z9ShBVsQ0G9wJ0I69ohlRbtQaMo0N6m5RmLg6toekl7V6A/GmyBNCcK6JRS X-Received: by 2002:a62:4bc6:: with SMTP id d67-v6mr12908383pfj.175.1536935444678; Fri, 14 Sep 2018 07:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536935444; cv=none; d=google.com; s=arc-20160816; b=AfseUb+SVmTxsZmf6H2GbRl101Si9d92GGD31gChOH0K88Ew1vP/nwhBN/I84qnRa8 suZjLZPVogob25xnMq0mUvvnpz34t5hACNUg4+E0RaGZqmmh7DJF+bY0lweKqLJzCGsC xDfe4ULr9dnhn7kuH+GINQPS5KcrPJA1ez6OeEYaiLeOng8ca60ywtasM9htNTrV2OzN 2+iTfnEkuOAFxP3e1zXogjvd5XYibZ/zwH9Uuz4EL8BDuluvE0n+3c/nYlgNA7kYKhk3 lqHP7ItlB47fMhZWfCbgg7AlK6LkGubRDA6XUPowEvHuVu+uAPmB/Ho7sHcDP3jexgSw SBkg== 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; bh=CxhohGZZRSZLez5qmBG5B0gm6SqMT8QtZzQHSdPgqN8=; b=AjgWJ68mCslTnu843/sL8YTY2uZyTECV3gBm0jmkcgrIKyXdai47wwIbucSYiFmD/K Neisz20FJG6PVon63CMcVfdpDRCXDsAm9jvdonwuVg1yMNF1iy6DI3H+ZV+lpqOr1gs9 zl0vTwK64UPTZikT0jUnVpaTdDllcAN729hqOCv3TXzXItICNhsXcbmwyl/Sa9doNGNp cdjaDWpsNH8FOfVyp4TB6eYNhfoJWacumxa/3sxaPJX8viP5BE+nvsVVA/94OpxxAiPx TjS3TUEIf8seBQsdYgVtb7dab3z2GHohzP+1yFBfQ+GB8c1gdWZIeZaBon9ixhJWAH5E 4+jw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y13-v6si7532929pgl.555.2018.09.14.07.30.44; Fri, 14 Sep 2018 07:30:44 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728332AbeINTp2 (ORCPT + 32 others); Fri, 14 Sep 2018 15:45:28 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34240 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbeINTp0 (ORCPT ); Fri, 14 Sep 2018 15:45:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1EA8E15BF; Fri, 14 Sep 2018 07:30:41 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.emea.arm.com [10.4.12.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 549373F575; Fri, 14 Sep 2018 07:30:39 -0700 (PDT) From: Robin Murphy To: joro@8bytes.org, will.deacon@arm.com, thunder.leizhen@huawei.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linuxarm@huawei.com, guohanjun@huawei.com, huawei.libin@huawei.com, john.garry@huawei.com Subject: [PATCH v7 4/6] iommu: Add bootup option "iommu.non_strict" Date: Fri, 14 Sep 2018 15:30:22 +0100 Message-Id: <41f81c46348db4acd9a542184f10e7ca24f6c219.1536935328.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.19.0.dirty In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhen Lei Add a bootup option to make the system manager can choose which mode to be used. The default mode is strict. Signed-off-by: Zhen Lei [rm: move handling out of SMMUv3 driver] Signed-off-by: Robin Murphy --- .../admin-guide/kernel-parameters.txt | 13 ++++++++++ drivers/iommu/iommu.c | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) -- 2.19.0.dirty diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9871e649ffef..406b91759b62 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1749,6 +1749,19 @@ nobypass [PPC/POWERNV] Disable IOMMU bypass, using IOMMU for PCI devices. + iommu.non_strict= [ARM64] + Format: { "0" | "1" } + 0 - strict mode, default. + Release IOVAs after the related TLBs are invalid + completely. + 1 - non-strict mode. + Put off TLBs invalidation and release memory first. + It's good for scatter-gather performance but lacks + full isolation, an untrusted device can access the + reused memory because the TLBs may still valid. + Please take full consideration before choosing this + mode. Note that, VFIO will always use strict mode. + iommu.passthrough= [ARM64] Configure DMA to bypass the IOMMU by default. Format: { "0" | "1" } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 8c15c5980299..2cabd0c0a4f3 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -41,6 +41,7 @@ static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_IDENTITY; #else static unsigned int iommu_def_domain_type = IOMMU_DOMAIN_DMA; #endif +static bool iommu_dma_non_strict __read_mostly; struct iommu_callback_data { const struct iommu_ops *ops; @@ -131,6 +132,24 @@ static int __init iommu_set_def_domain_type(char *str) } early_param("iommu.passthrough", iommu_set_def_domain_type); +static int __init iommu_dma_setup(char *str) +{ + int ret; + + ret = kstrtobool(str, &iommu_dma_non_strict); + if (ret) + return ret; + + if (iommu_dma_non_strict) { + pr_warn("WARNING: iommu non-strict mode is chosen.\n" + "It's good for scatter-gather performance but lacks full isolation\n"); + add_taint(TAINT_WARN, LOCKDEP_STILL_OK); + } + + return 0; +} +early_param("iommu.non_strict", iommu_dma_setup); + static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) { @@ -1072,6 +1091,13 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) group->default_domain = dom; if (!group->domain) group->domain = dom; + + if (dom && iommu_dma_non_strict) { + int attr = 1; + iommu_domain_set_attr(dom, + DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, + &attr); + } } ret = iommu_group_add_device(group, dev);