From patchwork Thu Sep 13 16:42:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 146635 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp812698ljw; Thu, 13 Sep 2018 09:42:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZSjKu0cRdAuQ6FQFTrG8ChCUKf1akSmAGv+3YnB+HoMbh4Aj8/KDtEIr8zjJUIn67lwwgN X-Received: by 2002:a63:d857:: with SMTP id k23-v6mr7970772pgj.106.1536856976834; Thu, 13 Sep 2018 09:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536856976; cv=none; d=google.com; s=arc-20160816; b=Y/Sj/v4Xnf/oS9ECm/2YQf6Gts9LRizibmegrEHuIM74uxZnBDcTHWtsQ53apC8o2R pEf+CI3s/zM4+QZyoh1aVwVUv+8bOBzRJcWqnczUZPHJjnYqFR7FLlX5X9VTEuGAIAok 3PD05Nk5XzyFvUckZdErgl56WjBIXNMTOFwP60sxYCwRbE0Nt0gDiC+fumkvFH9km1Nh VigsCS3Bdo0uc9k9dxJ/+0hvFNQlAMmUXJ/YiDa7uWDUjZKw/Nh2qxVwWICnwfLcJRqb 8IMYizj3sd9MR05qcXFnluREnOHtalyy5NELgyB1g2MjtqwSTGo9d+t5SDwvUKkTzg7n Q9vA== 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=HlQCIJcDGbf8MlvcgxIrSI2BVoFoO56b4FRl8XMW144=; b=QLQuUfvmJu81/cPM7hJ6oqbP6dhzb2t3Pv6i1PqdC7+mUwqZFqAZFh+t2ETSgUp2HH YfKArqDk5ttOLKNq2xmW/Zwe3RFkhSyRIwPGv6ENjJSA6frg9KKALmg70MVOdLueBsl4 JxnyEf2rwOEj/dhxKZvamHc7oXjPpA2tE/nhQx0WdAIi4uB2geFJPtvua9vG/vIWvPDc RZbPgCg2JeV/IMycPmjjA3pkgSMrJ3L9GGMnTvnz9KnqPAgOVWYXEQ5BroT9aHCQHNbp E+TT1HfAIYZK4gtP2dv/icxjwyTdsYNZiACdgUyqQBbE/+W7kVfKTK810vdtTei+K5z4 J1OQ== 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 r84-v6si4440313pfj.355.2018.09.13.09.42.56; Thu, 13 Sep 2018 09:42:56 -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 S1728468AbeIMVxK (ORCPT + 32 others); Thu, 13 Sep 2018 17:53:10 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51170 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728430AbeIMVxJ (ORCPT ); Thu, 13 Sep 2018 17:53:09 -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 76FDD1684; Thu, 13 Sep 2018 09:42:52 -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 AC5243F703; Thu, 13 Sep 2018 09:42:50 -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 v6 7/7] iommu/dma: Add bootup option "iommu.non_strict" Date: Thu, 13 Sep 2018 17:42:24 +0100 Message-Id: <94fe2e15d36565e13218b007b9d5d9d08f190e5e.1536856828.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: make it a generic iommu-dma feature] Signed-off-by: Robin Murphy --- .../admin-guide/kernel-parameters.txt | 13 +++++++++++++ drivers/iommu/dma-iommu.c | 18 ++++++++++++++++++ 2 files changed, 31 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/dma-iommu.c b/drivers/iommu/dma-iommu.c index d91849fe4ebe..04d4c5453acd 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -62,6 +62,24 @@ struct iommu_dma_cookie { static bool iommu_dma_non_strict __read_mostly; +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 inline size_t cookie_msi_granule(struct iommu_dma_cookie *cookie) { if (cookie->type == IOMMU_DMA_IOVA_COOKIE)