From mboxrd@z Thu Jan 1 00:00:00 1970 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 03D70C001E0 for ; Tue, 15 Aug 2023 01:19:44 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:To:Subject:Cc: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OEh2IpSbRroqRsUlfOZDK6hLLsWEmpiNypMioasHy1M=; b=eHqQoei5ZjO8sq +8nyWbcER/3B9xKyz6Fx/2ScO/LkNiVoN3Qy2m3/jtiVV9ANWjjwuY3ie8kT9GZO3EkgypdxwFO0P KXZwcvUYwISqB10PtsN2sYMpR7HaCue9Je+lbxBYfB7yloQP9dQrejJ/ZZpkEwjbfK6xfwNwo67Pt fP6q+cwhtzQ6YpH/4NuaLwS8HIXCwkDCWM+kshU8Rseu5eCsX+kkVmJ2fnZpU2CfTAkWr47dLeTsH OjL5vRicojcfiNhL0xXJOdK1/cGKO3rmvws5xR8xIR6iCUIRZYKAW4Zo3szgOB9FfyO6BHhVarA/B 1q+iQfimvvbX17W7aR1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qViiL-000f0m-1z; Tue, 15 Aug 2023 01:19:17 +0000 Received: from mgamail.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qViiH-000ezq-1Y; Tue, 15 Aug 2023 01:19:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692062353; x=1723598353; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=QvD+OczAXQfY3EnI/faV3RaAbFUkc5kfqnTaF1n9e4M=; b=gLPSXIYC+nWUJ4rrJM1sWpvMAPnMjOJ9uL04nmcovxbhdMn4OqRGSHYp N+De+0mkxy+SIHp4VnuJ7RPx5Ua71Ug6b4gu0t2jsNc9fM1jvqyiSeuZS exnxpMVpu8DAEAlJXMcXbo0dxgw/pck8g+a4Zi4Gh3OaMTM4+4HxzC+4a MMwDQ6+QXlIKUJmnlDMr0bi4jPA0M3Ri7XcjD8R8tsVp6FJiImfAjaIWe 7KB3cArQtlI5/5ORe6j1/4Xqp+3cjerXKKejtg6XOuWP+M7tfgvxvPyUD mv62PD0eW/8MKJJ39X3QfhDniQrtdDW+rAp+BkjlJdD/d7pbTMeONii5g Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="438516168" X-IronPort-AV: E=Sophos;i="6.01,173,1684825200"; d="scan'208";a="438516168" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 18:19:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10802"; a="823667919" X-IronPort-AV: E=Sophos;i="6.01,173,1684825200"; d="scan'208";a="823667919" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.254.215.149]) ([10.254.215.149]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 18:19:01 -0700 Message-ID: Date: Tue, 15 Aug 2023 09:18:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Cc: baolu.lu@linux.intel.com, Andy Gross , Alim Akhtar , Bjorn Andersson , AngeloGioacchino Del Regno , Baolin Wang , Christophe Leroy , Gerald Schaefer , Heiko Stuebner , iommu@lists.linux.dev, Jernej Skrabec , Jonathan Hunter , Joerg Roedel , Kevin Tian , Konrad Dybcio , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-s390@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, Russell King , linuxppc-dev@lists.ozlabs.org, Matthias Brugger , Matthew Rosato , Michael Ellerman , Nicholas Piggin , Orson Zhai , Rob Clark , Robin Murphy , Samuel Holland , Thierry Reding , Krishna Reddy , Chen-Yu Tsai , Will Deacon , Yong Wu , Chunyan Zhang , Dmitry Osipenko , Marek Szyprowski , Nicolin Chen , Niklas Schnelle , Steven Price , Thierry Reding Subject: Re: [PATCH v6 08/25] iommu: Reorganize iommu_get_default_domain_type() to respect def_domain_type() Content-Language: en-US To: Jason Gunthorpe References: <8-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com> From: Baolu Lu In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_181913_563088_D6FB795D X-CRM114-Status: GOOD ( 19.53 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023/8/15 1:25, Jason Gunthorpe wrote: > Ah, I went over all this again and decided to try again, it is too > complicated. This patch can do what the commit message says and the > following patches are even simpler: Yes. This method is more concise. Some nits below. > > /* > * Combine the driver's choosen def_domain_type across all the devices in a > * group. Drivers must give a consistent result. > */ > static int iommu_get_def_domain_type(struct iommu_group *group, > struct device *dev, int cur_type) > { > const struct iommu_ops *ops = group_iommu_ops(group); > int type; > > if (!ops->def_domain_type) > return cur_type; > > type = ops->def_domain_type(dev); > if (!type || cur_type == type) > return cur_type; > if (!cur_type) > return type; > > dev_err_ratelimited( > dev, > "IOMMU driver error, requesting conflicting def_domain_type, %s and %s, for devices in group %u.\n", > iommu_domain_type_str(cur_type), iommu_domain_type_str(type), > group->id); > > /* > * Try to recover, drivers are allowed to force IDENITY or DMA, IDENTITY > * takes precedence. > */ > if (cur_type || type == IOMMU_DOMAIN_IDENTITY) > return IOMMU_DOMAIN_IDENTITY; No need to check cur_type. It already returned if cur_type is 0. > return cur_type; > } > > /* > * A target_type of 0 will select the best domain type. 0 can be returned in > * this case meaning the global default should be used. > */ > static int iommu_get_default_domain_type(struct iommu_group *group, > int target_type) > { > struct device *untrusted = NULL; > struct group_device *gdev; > int driver_type = 0; > > lockdep_assert_held(&group->mutex); > > /* > * ARM32 drivers supporting CONFIG_ARM_DMA_USE_IOMMU can declare an > * identity_domain and it will automatically become their default > * domain. Later on ARM_DMA_USE_IOMMU will install its UNMANAGED domain. > * Override the selection to IDENTITY. > */ > if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) { > static_assert(!(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) && > IS_ENABLED(CONFIG_IOMMU_DMA))); IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) is duplicate with the condition in the if statement. So only static_assert(!IS_ENABLED(CONFIG_IOMMU_DMA)); ? > driver_type = IOMMU_DOMAIN_IDENTITY; > } > > for_each_group_device(group, gdev) { > driver_type = iommu_get_def_domain_type(group, gdev->dev, > driver_type); No need to call this in the loop body? > > if (dev_is_pci(gdev->dev) && to_pci_dev(gdev->dev)->untrusted) { > /* > * No ARM32 using systems will set untrusted, it cannot > * work. > */ > if (WARN_ON(IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU))) > return -1; > untrusted = gdev->dev; > } > } > > if (untrusted) { > if (driver_type && driver_type != IOMMU_DOMAIN_DMA) { > dev_err_ratelimited( > untrusted, > "Device is not trusted, but driver is overriding group %u to %s, refusing to probe.\n", > group->id, iommu_domain_type_str(driver_type)); > return -1; > } > driver_type = IOMMU_DOMAIN_DMA; > } > > if (target_type) { > if (driver_type && target_type != driver_type) > return -1; > return target_type; > } > return driver_type; > } Best regards, baolu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel