Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp321561rwe; Fri, 26 Aug 2022 05:49:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR5E9ksKPw4gK3y9jxzaSq+AHEuFcUMyh5Aib180HgPaG3FpgcDVBtnCKdw/gZ5gK58zwXD6 X-Received: by 2002:a05:6402:1250:b0:447:dd0e:213a with SMTP id l16-20020a056402125000b00447dd0e213amr2969419edw.359.1661518172110; Fri, 26 Aug 2022 05:49:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661518172; cv=none; d=google.com; s=arc-20160816; b=Yz0bETVn+V9dyjFjCgr6j1SLGXSosyArJ82RKMcGZURx+62Jw3GPrIwC6raXd+KQCL GiCBvqTJEADwMYpLhxuvH/JQSg/s77ASlx1dKppazymMjB64bE3QVRUvr0pgGhZueot7 PUXEljlFfesLnvgcr8m9FU16Qt/acL+BBI+g3Yddl5mNQLvf8dsbPHAS3zGyG5FBbGh4 6a0N/QP71ZteVEnZ45tchATe1+xZ2902TNDo1IPm+pcSvg9S422ZikoxSRf5aWdYO9sz SYBWHRxchc3pH5RysccVPNKzuuccOxv8MExWWGf+/MaSGqzkm8EG58tiShCz3Bm8fHXZ uSkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1v08WzYavA64oCtPUVYeZls54uu4Mt7LzAsosJTzJjI=; b=mvLTcdjkw/AujpEl34fcDa3ac0S5Z1cPkAufd3IkzivABCkwhFg9W3ZAIXSSnfnD0e JOQN9p5wGnmnL7WRwgzNJ1YLxK3PBb9U4ELhouMfPZqofzN7PpqMHDd3/Zj3A6FAJh0I GGYdJGP9wVz4gV843r9539qQ1DXsQouL2rloCP+k0FhywlRl65szlJ37LAaVqtZg7aPB rCE2+2Hjtkb7J9JvI2YYj8U3hckoXWVcB37qVcUSj0Ig9OGzh7ISk7mJI0lmlsmJOZtb 1Oe08U7MXUGizYyxbAXnHxKBHGLfLBOL0/wHgMpu+VXZTFYXJqhDfavpbOrFcJZcJrZ0 W4vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZHFtGUfL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x16-20020a170906135000b0073317d6b047si1005367ejb.569.2022.08.26.05.49.05; Fri, 26 Aug 2022 05:49:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZHFtGUfL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343910AbiHZMSO (ORCPT + 99 others); Fri, 26 Aug 2022 08:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343491AbiHZMR7 (ORCPT ); Fri, 26 Aug 2022 08:17:59 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 522BEDD4F8; Fri, 26 Aug 2022 05:17:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661516275; x=1693052275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BlPDAsITnFdD30Pt137P5Fo8l26pHF5dP5Ti1dDDyHg=; b=ZHFtGUfLaeHdYpbojDYNHq1gu2bi5rvmuIkH0zlUl5IB9f75KRG1gPnX xT7xJcx3geSKiMdn8Zrn2ckaJg2nVYifbP4Z3LW6rgbgfKOQQFttuxLJq Zezs+cUnrMzJ6Zy4bJEzqpjcpSbuxi/A9jXyUxnQKoockJhiIojXA5Tx+ T6dhXunn7i75ct7Am53bQSYheHMjlwuVEmjT4AaFPFBTBv3q2f5VMuKtc 09fd8VrB6uy4rj7ClVSgDDmDujOzjEVXmj+tkfHeR826woch6wULSe7GU 9icmhuOlo+LaJEcTiQ+0Y5OcKxLhQiRZfFe41Ta4bd6RbhlXMRIejKVQd A==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="292072128" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="292072128" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 05:17:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="606747653" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 26 Aug 2022 05:17:49 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v12 07/17] iommu: Try to allocate blocking domain when probing device Date: Fri, 26 Aug 2022 20:11:31 +0800 Message-Id: <20220826121141.50743-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826121141.50743-1-baolu.lu@linux.intel.com> References: <20220826121141.50743-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allocate the blocking domain when probing devices if the driver supports blocking domain allocation. Otherwise, revert to the previous behavior, that is, use UNMANAGED domain instead when the blocking domain is needed. Signed-off-by: Lu Baolu Tested-by: Zhangfei Gao Tested-by: Tony Zhu --- drivers/iommu/iommu.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 2c9488d966ab..e985f4d5895f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -318,6 +318,10 @@ int iommu_probe_device(struct device *dev) mutex_lock(&group->mutex); iommu_alloc_default_domain(group, dev); + /* Try to allocate a blocking domain */ + group->blocking_domain = __iommu_domain_alloc(dev->bus, + IOMMU_DOMAIN_BLOCKED); + /* * If device joined an existing group which has been claimed, don't * attach the default domain. @@ -1778,6 +1782,10 @@ int bus_iommu_probe(struct bus_type *bus) /* Try to allocate default domain */ probe_alloc_default_domain(bus, group); + /* Try to allocate blocking domain */ + group->blocking_domain = + __iommu_domain_alloc(bus, IOMMU_DOMAIN_BLOCKED); + if (!group->default_domain) { mutex_unlock(&group->mutex); continue; @@ -3165,18 +3173,15 @@ static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) if (group->blocking_domain) return 0; - group->blocking_domain = - __iommu_domain_alloc(dev->dev->bus, IOMMU_DOMAIN_BLOCKED); - if (!group->blocking_domain) { - /* - * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED - * create an empty domain instead. - */ - group->blocking_domain = __iommu_domain_alloc( - dev->dev->bus, IOMMU_DOMAIN_UNMANAGED); - if (!group->blocking_domain) - return -EINVAL; - } + /* + * For drivers that do not yet understand IOMMU_DOMAIN_BLOCKED + * create an empty domain instead. + */ + group->blocking_domain = __iommu_domain_alloc(dev->dev->bus, + IOMMU_DOMAIN_UNMANAGED); + if (!group->blocking_domain) + return -EINVAL; + return 0; } -- 2.25.1