From patchwork Thu Sep 20 16:10:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 147105 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2188255ljw; Thu, 20 Sep 2018 09:10:44 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda0VjK/NFAWGGVzNFYXjDReb3ZcwxSSncIxFdxkPwSJr14qju2MsAP24YvGaNoS9cqE7/G1 X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr40409931plq.337.1537459844134; Thu, 20 Sep 2018 09:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537459844; cv=none; d=google.com; s=arc-20160816; b=KPkVIsYOaYDPDb3r+VrBTN919LVvG7Shh/3M00CxnvhvQ0t0zSsN7VkVDXpvNZbHYI TG6ygCrE1R5HhuLJqbL/WT/YYZIvFc57TmXoOROc72uK0tHMJKpra+1QfYGv2BgMl/mo 59vlZ/wmH/zwu4ee6kaohdfv3r1Wjp+btqaHzx+HhW9kWjLbxGwFS1nAwzd5OMgsqmxX UVV765bIrg7l35UaMX73skYJ9hGA6Hl5iSBOXj5kgZ4PSf7f+C5UYVKxxCHYr43KrtcY 0xyg3frMBUykabVuK1qVi1W87TtnKuwLPJunjnUnbjWfkNiGRH+awxYOUJ09mtW8Bgbb RK6A== 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=hZlktJ7rcez4NbFb2cGZ6ZTHai70+pWhbqdcFyL+zOU=; b=ROmhfCp0V4QMK2QNlSwRLg84cahoeMeV4Xr9yDRKuXrB4+di1/jz5NsSOjEcL+s1fM Sw4MBybVBZorCpqSFcd2bXtQ1ic6JFPSWrHJdnLbcWyrUeRXGdYydWibZQ+YC3pgvwUI xtQf4yhnoNPJq1Z7B5K2cMjysOEUMC/j+AJ1ASy/8FOchV6MCxF8V2ozzFeni8DbeRLe fz8mGRvQ0M7n3uJdhTvmf0RMRodFhKrDG99ido55ZpOVmo7Fg9/CwL/bA6QVkWlUCe5o wG3c3g8ii1o5KgQP7ZG0gZmDjLjnZkh+/DalR1uk/rz69aaAkge0VOw47slT/5y+/lGO Pp9g== 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 x14-v6si1401922pfi.138.2018.09.20.09.10.43; Thu, 20 Sep 2018 09:10: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 S1731109AbeITVyw (ORCPT + 32 others); Thu, 20 Sep 2018 17:54:52 -0400 Received: from foss.arm.com ([217.140.101.70]:48580 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731009AbeITVyv (ORCPT ); Thu, 20 Sep 2018 17:54:51 -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 7DB3615BE; Thu, 20 Sep 2018 09:10:40 -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 B3C513F557; Thu, 20 Sep 2018 09:10:38 -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 v8 3/7] iommu: Add "iommu.strict" command line option Date: Thu, 20 Sep 2018 17:10:23 +0100 Message-Id: <799fad801970298385af3abc8ca82620ad62c000.1537458163.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 generic command line option to enable lazy unmapping via IOVA flush queues, which will initally be suuported by iommu-dma. This echoes the semantics of "intel_iommu=strict" (albeit with the opposite default value), but in the driver-agnostic fashion of "iommu.passthrough". Signed-off-by: Zhen Lei [rm: move handling out of SMMUv3 driver, clean up documentation] Signed-off-by: Robin Murphy --- v8: - Rename "non-strict" to "strict" to better match existing options - Rewrite doc text/commit message - Downgrade boot-time message from warn/taint to info .../admin-guide/kernel-parameters.txt | 12 ++++++++++ drivers/iommu/iommu.c | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) -- 2.19.0.dirty diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 9871e649ffef..92ae12aeabf4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1749,6 +1749,18 @@ nobypass [PPC/POWERNV] Disable IOMMU bypass, using IOMMU for PCI devices. + iommu.strict= [ARM64] Configure TLB invalidation behaviour + Format: { "0" | "1" } + 0 - Lazy mode. + Request that DMA unmap operations use deferred + invalidation of hardware TLBs, for increased + throughput at the cost of reduced device isolation. + Will fall back to strict mode if not supported by + the relevant IOMMU driver. + 1 - Strict mode (default). + DMA unmap operations invalidate IOMMU hardware TLBs + synchronously. + 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..02b6603f0616 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_strict __read_mostly = true; struct iommu_callback_data { const struct iommu_ops *ops; @@ -131,6 +132,21 @@ 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_strict); + if (ret) + return ret; + + if (!iommu_dma_strict) + pr_info("Enabling deferred TLB invalidation for DMA; protection against malicious/malfunctioning devices may be reduced.\n"); + + return 0; +} +early_param("iommu.strict", iommu_dma_setup); + static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) { @@ -1072,6 +1088,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_strict) { + int attr = 1; + iommu_domain_set_attr(dom, + DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, + &attr); + } } ret = iommu_group_add_device(group, dev);