From patchwork Mon Jul 10 08:22:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 13306421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 174C7EB64D9 for ; Mon, 10 Jul 2023 08:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=jc3HTZdRIEevlhhPtWvRj+oiTnCv730GoFyW8lvA4tU=; b=f8UdOnOvT7CBlb k6mB2YbrH9IfpTRdvnmIqRle47W2EaAebTOjUWR4/qqXYGr6FqdpsBBhay+Ir2LS8bFMGnlhPmdE/ 7fvbQ9tlqZYzdPRTm8jELtOfzxlBR/epeYSVkTk+krTsPR1lvUmAncErl6cy97db4paxtKGmVLCQD WW6WSNRydfL6DM74E4fvCitmDalnZ6NPnDxLzDyFnTk8ReQitL0+yrWMnefxsiXwvqyaDjaAClHRe IfNUgzHHk2w3lQ6QR1uJZUSF1vTYSnfO5sqZBXrBQaa5yqtlC/0bOw9BnVEUQ5HCpXmtpqYvbleMd 8EQmGihHYxyaYxXCvVfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qImBG-00AppU-1r; Mon, 10 Jul 2023 08:23:38 +0000 Received: from smtp-out2.suse.de ([195.135.220.29]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qImBD-00Apna-0m for linux-arm-kernel@lists.infradead.org; Mon, 10 Jul 2023 08:23:36 +0000 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2FBA51F38D; Mon, 10 Jul 2023 08:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1688977409; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=dirNkRoYAPOKgnokI62rBUKnm7Cm3Bq2fLafnXLX2rM=; b=2WvQvESn1/36HSzhMXVcSdjik+t5nYMXFKF1KG0UIusg8sySF8R7ITMWNIFtYhJeqKxy2O 2KPFJpEbMJJaKLPNuVQjBi00LhQBwiIaRrPmGrF4blFthGkD+N2RyyqB/WriWGWOjCFh2N cdQ+D4xx8pVLj0yAENQAG3kCj9N2/Ww= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1688977409; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=dirNkRoYAPOKgnokI62rBUKnm7Cm3Bq2fLafnXLX2rM=; b=SOrq1aFHj7y8/rOc5/XQp3i66j+CCZYnz5Q8FmAeO+0g1n+bwvV7x4RLNNfRR9K8JGsuoH /EGw8tcK+oLYHoBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B91FA13A05; Mon, 10 Jul 2023 08:23:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id pNAqKwDAq2QcDAAAMHmgww (envelope-from ); Mon, 10 Jul 2023 08:23:28 +0000 From: Stanimir Varbanov To: linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RFC PATCH] iommu: arm-smmu-nvidia: Add default domain type implementation op Date: Mon, 10 Jul 2023 11:22:52 +0300 Message-ID: <20230710082252.9702-1-svarbanov@suse.de> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230710_012335_442806_F9F6870C X-CRM114-Status: GOOD ( 15.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stanimir Varbanov , Will Deacon , Joerg Roedel , Thierry Reding , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add def_domain_type implementation op and override default IOMMU domain Kconfig option (CONFIG_IOMMU_DEFAULT_PASSTHROUGH=y), which could be enabled on some distros. The current quirk has been done for Tegra234 machine, because I found the issue on it. The issue itself appears on USB host controller which cannot be initialized without IOMMU translation. Something more, we proved that IOMMU translation is needed for display and GPU drivers as well. I evaluated few possible options to solve that: a) select default IOMMU domain from .def_domain_type op b) Unset CONFIG_IOMMU_DEFAULT_PASSTHROUGH=n c) add iommu.passthrough=0 on the kernel cmdline d) firmware - ACPI / DT a) This option is implemented in the proposed patch. b) Since that the community has agreed that pass-through is preferred as a default IOMMU domain option because this will avoid performance impacts on some of the platforms [1]. On the other side we have examples where you cannot even install Linux distribution on a machine where the storage media cannot be detected and the system just hangs. c) - This option involves installer's knowledge of platforms/devices which needs IOMMU translations. d) - IORT ACPI table / DT - I'm not sure is that option even possible but firmware looks like a good place for such. Please, treat this as an RFC and a call for proper solution. [1] https://marc.info/?l=linux-arm-kernel&m=148864682514762 Signed-off-by: Stanimir Varbanov --- drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c index 87bf522b9d2e..691b57d1e699 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-nvidia.c @@ -286,6 +286,22 @@ static int nvidia_smmu_init_context(struct arm_smmu_domain *smmu_domain, return 0; } +static int nvidia_smmu_def_domain_type(struct device *dev) +{ + if (of_machine_is_compatible("nvidia,tegra234")) + return IOMMU_DOMAIN_DMA; + + return 0; +} + +static int nvidia_smmu_single_def_domain_type(struct device *dev) +{ + if (of_machine_is_compatible("nvidia,tegra234")) + return IOMMU_DOMAIN_DMA; + + return 0; +} + static const struct arm_smmu_impl nvidia_smmu_impl = { .read_reg = nvidia_smmu_read_reg, .write_reg = nvidia_smmu_write_reg, @@ -297,11 +313,13 @@ static const struct arm_smmu_impl nvidia_smmu_impl = { .context_fault = nvidia_smmu_context_fault, .probe_finalize = nvidia_smmu_probe_finalize, .init_context = nvidia_smmu_init_context, + .def_domain_type = nvidia_smmu_def_domain_type, }; static const struct arm_smmu_impl nvidia_smmu_single_impl = { .probe_finalize = nvidia_smmu_probe_finalize, .init_context = nvidia_smmu_init_context, + .def_domain_type = nvidia_smmu_single_def_domain_type, }; struct arm_smmu_device *nvidia_smmu_impl_init(struct arm_smmu_device *smmu)