From patchwork Tue Aug 25 15:42:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sai Prakash Ranjan X-Patchwork-Id: 11735935 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F303614F6 for ; Tue, 25 Aug 2020 15:45:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C6BA620782 for ; Tue, 25 Aug 2020 15:45:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xPLODkYe"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="FE1kxGs2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6BA620782 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=w7dmaNrTUwy8UClc6ig4hkQl5M2xGcTZVFR9IHsRF5s=; b=xPLODkYelrKlZ9P/FhqWSMPoKk 6TJEDLA+RF+h1s70MAvqf4yZjfLxzXBD9hogNlpyL/0RU8648kj6WV133eQwGYFgPf4ujzRqYdI7t 6H1JODPHutcBiuphZkclOfUqkFkdARHkgjv4SAqpfakrSzajH7owIJ+K8ahW/PdCfkxO+yXF380n/ Wyd5ozlVBT/pg26XFvPbB/FF47dp/k5GaOSTP7oewvlidJneqQLwy5o8aAwL1+Rg2C1GgNtCjNHYw pAzbD3f5GFCJiHPaGO7QygSBQv60qP2VRpvVlneSK6WjFhvzucOn/jq+WUsitH9vXtnf8cUlElglP weYSRKFw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAb6X-0001S9-BE; Tue, 25 Aug 2020 15:43:21 +0000 Received: from m43-7.mailgun.net ([69.72.43.7]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAb6R-0001R2-Ow for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 15:43:19 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1598370198; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=vPjwRTcbHtJglbBEf+g+zBKRbHTS9GuM+a7BNj5yuBU=; b=FE1kxGs2eVfHA6D5MMrzMmwDMJsOsKx1YfB83Puo5ZFr51tq/yRo8r27OpMCAAn+9nZetECh uuytDbEZ6WqaE6ctqmLj+MqFTpeSwry53iuWl0shmnv2KPbzX88B5qa9eei3ndiOs3KC/Bxa fqvr9NI82Z0qcqI5Bn0VCm289rQ= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyJiYzAxZiIsICJsaW51eC1hcm0ta2VybmVsQGxpc3RzLmluZnJhZGVhZC5vcmciLCAiYmU5ZTRhIl0= Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n05.prod.us-east-1.postgun.com with SMTP id 5f45318d9b97d7ba7b2bcf7e (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 25 Aug 2020 15:43:09 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 61619C4339C; Tue, 25 Aug 2020 15:43:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from blr-ubuntu-253.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan) by smtp.codeaurora.org (Postfix) with ESMTPSA id 65BAAC433C6; Tue, 25 Aug 2020 15:43:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 65BAAC433C6 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=saiprakash.ranjan@codeaurora.org From: Sai Prakash Ranjan To: Will Deacon , Robin Murphy , Joerg Roedel , Tomasz Figa , Stephen Boyd , Douglas Anderson Subject: [PATCH] iommu: Add support to filter non-strict/lazy mode based on device names Date: Tue, 25 Aug 2020 21:12:49 +0530 Message-Id: <20200825154249.20011-1-saiprakash.ranjan@codeaurora.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_114318_280049_33D0E275 X-CRM114-Status: GOOD ( 19.71 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [69.72.43.7 listed in list.dnswl.org] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sai Prakash Ranjan Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently the non-strict or lazy mode of TLB invalidation can only be set for all or no domains. This works well for development platforms where setting to non-strict/lazy mode is fine for performance reasons but on production devices, we need a more fine grained control to allow only certain peripherals to support this mode where we can be sure that it is safe. So add support to filter non-strict/lazy mode based on the device names that are passed via cmdline parameter "iommu.nonstrict_device". Example: iommu.nonstrict_device="7c4000.sdhci,a600000.dwc3,6048000.etr" Signed-off-by: Sai Prakash Ranjan --- drivers/iommu/iommu.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) base-commit: e46b3c0d011eab9933c183d5b47569db8e377281 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 609bd25bf154..fd10a073f557 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -32,6 +32,9 @@ static unsigned int iommu_def_domain_type __read_mostly; static bool iommu_dma_strict __read_mostly = true; static u32 iommu_cmd_line __read_mostly; +#define DEVICE_NAME_LEN 1024 +static char nonstrict_device[DEVICE_NAME_LEN] __read_mostly; + struct iommu_group { struct kobject kobj; struct kobject *devices_kobj; @@ -327,6 +330,32 @@ static int __init iommu_dma_setup(char *str) } early_param("iommu.strict", iommu_dma_setup); +static int __init iommu_nonstrict_filter_setup(char *str) +{ + strlcpy(nonstrict_device, str, DEVICE_NAME_LEN); + return 1; +} +__setup("iommu.nonstrict_device=", iommu_nonstrict_filter_setup); + +static bool iommu_nonstrict_device(struct device *dev) +{ + char *filter, *device; + + if (!dev) + return false; + + filter = kstrdup(nonstrict_device, GFP_KERNEL); + if (!filter) + return false; + + while ((device = strsep(&filter, ","))) { + if (!strcmp(device, dev_name(dev))) + return true; + } + + return false; +} + static ssize_t iommu_group_attr_show(struct kobject *kobj, struct attribute *__attr, char *buf) { @@ -1470,7 +1499,7 @@ static int iommu_get_def_domain_type(struct device *dev) static int iommu_group_alloc_default_domain(struct bus_type *bus, struct iommu_group *group, - unsigned int type) + unsigned int type, struct device *dev) { struct iommu_domain *dom; @@ -1489,7 +1518,7 @@ static int iommu_group_alloc_default_domain(struct bus_type *bus, if (!group->domain) group->domain = dom; - if (!iommu_dma_strict) { + if (!iommu_dma_strict || iommu_nonstrict_device(dev)) { int attr = 1; iommu_domain_set_attr(dom, DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, @@ -1509,7 +1538,7 @@ static int iommu_alloc_default_domain(struct iommu_group *group, type = iommu_get_def_domain_type(dev); - return iommu_group_alloc_default_domain(dev->bus, group, type); + return iommu_group_alloc_default_domain(dev->bus, group, type, dev); } /** @@ -1684,7 +1713,7 @@ static void probe_alloc_default_domain(struct bus_type *bus, if (!gtype.type) gtype.type = iommu_def_domain_type; - iommu_group_alloc_default_domain(bus, group, gtype.type); + iommu_group_alloc_default_domain(bus, group, gtype.type, NULL); }