Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp73563rdb; Mon, 18 Sep 2023 08:33:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFb7I1Li+O5lrU03yEfshMoxm3BZOqploS9evTFAVZmNbSi992BxkyBTug7E0C3HSwTbGLs X-Received: by 2002:a05:6a20:1442:b0:157:b453:dbb9 with SMTP id a2-20020a056a20144200b00157b453dbb9mr9647040pzi.6.1695051208984; Mon, 18 Sep 2023 08:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695051208; cv=none; d=google.com; s=arc-20160816; b=uSbssfagGaL4X0kSQWWmF/fSmMqVUMP1H9mj45bUAULXqy40M04e4iF71pC3TkeE7i vCYLVzYdVK9xtVL/tkpWKL2knCNO2X3+tvV/0AWDeL19bNPG6FzkwmbuAvXNSrPCc6yX JBmD26II3jehynXoQvHKnrnuoc8tWbTE6WehVAgW50fTbpgRivC6hwEfo5Ehk/eEghXj SHKizfPWMm82/zxP35OhpkFjeg7NRVfm8dlrvkBbCGpAg93k8n4iImMtkAYfbhdCeP9u qvovCYLZwV1NC7GHjayRPwn0jaEPS0XD5qBOE01tcQclA50jQtKVnmx27asV/F+vmkdl lD/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=xEoIYUFVlUQikHAmzot3uizHB7P4yMlFM/Mch3K3Utc=; fh=d4tV7DCjlGhZJ8MZ3nDsDs1MAuixqNSGYmk5hHWm430=; b=K1mzQxOjHtsmc/+O1b+pFeFwe1oiheEO5VUYfzwSk4DnnYNL/AwQXIJaGZZBsbZig7 qpHc76EaWtWSXMhW1LIX8rQicUyFAZkivRga6ZDmdkh8MDB+jVgOJkSfmpdwq4W6zz6h /0H69tWsRWEinaR3vWEffFGit0XztmEhXQp6CwqxOAWsg2/UNmcetUEXRmQk9finmInf OK3w4l9YmwuZZ7qnWKR6Nj4pr/CYaHD5/XHYTOMI6L58XOlKHQs8C2BBqVW6rWKbfDqE ErDd3Kip7JvPJw0q4w3VIoaX+nqMN9Lq53pDWbub4sbl/AkdND1kY4roireiW1pNxqsH SaTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QbDy/rHB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id ck7-20020a056a00328700b00690a77be748si504139pfb.235.2023.09.18.08.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 08:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QbDy/rHB"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 3D7F180203C2; Sun, 17 Sep 2023 23:15:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239722AbjIRGOf (ORCPT + 99 others); Mon, 18 Sep 2023 02:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239799AbjIRGOM (ORCPT ); Mon, 18 Sep 2023 02:14:12 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13B89121 for ; Sun, 17 Sep 2023 23:14:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695017647; x=1726553647; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=kUpHOK5IBjbqfbjc9MQ81MuDWUW3Xr1pW4Y/QY8RBCE=; b=QbDy/rHBS7N0L08Lb2/NsJoZqLSBaq4wHJ0Sg5zeWPl1G5uoOEbaR1VF vcIPenAkmXODF04mWFaQtu93DNqAyQj+8G8EEQJF9Um3AzvL+xVoMJFp9 2LY+JDH/m0scehIYN1uqjU5srwZWldFeregAMdGkZX8SP05GyntVRPlLg MhVeQwaydLlZrx4yDe8bAs9SOMvFZe30JwIqGKHh3FRMknS9x29SgaZdj mZWaDJKUW0hQKPHMcdtSNxhLOg42RapEIdC0jftEbD49JjtOyN88qqG/z 0UMQdrzeglcFfV3m5npXxJmtV3klVGHpNVySwCsSW2XCqBMkHqSgHhTDZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="364618652" X-IronPort-AV: E=Sophos;i="6.02,155,1688454000"; d="scan'208";a="364618652" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2023 23:14:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10836"; a="722351024" X-IronPort-AV: E=Sophos;i="6.02,155,1688454000"; d="scan'208";a="722351024" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga006.jf.intel.com with ESMTP; 17 Sep 2023 23:14:04 -0700 Message-ID: Date: Mon, 18 Sep 2023 14:10:58 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jgg@nvidia.com Subject: Re: [PATCH v3 4/7] iommu: Switch __iommu_domain_alloc() to device ops Content-Language: en-US To: Robin Murphy , joro@8bytes.org, will@kernel.org References: <404d8395cf4252c6fe6d98f317f3570127451778.1694693889.git.robin.murphy@arm.com> From: Baolu Lu In-Reply-To: <404d8395cf4252c6fe6d98f317f3570127451778.1694693889.git.robin.murphy@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 17 Sep 2023 23:15:14 -0700 (PDT) On 9/16/23 12:58 AM, Robin Murphy wrote: > @@ -1997,16 +1995,13 @@ void iommu_set_fault_handler(struct iommu_domain *domain, > } > EXPORT_SYMBOL_GPL(iommu_set_fault_handler); > > -static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, > +static struct iommu_domain *__iommu_domain_alloc(struct device *dev, > unsigned type) > { > - const struct iommu_ops *ops = bus ? bus->iommu_ops : NULL; > + const struct iommu_ops *ops = dev_iommu_ops(dev); > struct iommu_domain *domain; > unsigned int alloc_type = type & IOMMU_DOMAIN_ALLOC_FLAGS; > > - if (!ops) > - return NULL; > - > domain = ops->domain_alloc(alloc_type); > if (!domain) > return NULL; > @@ -2030,9 +2025,28 @@ static struct iommu_domain *__iommu_domain_alloc(const struct bus_type *bus, > return domain; > } > > +static int __iommu_domain_alloc_dev(struct device *dev, void *data) > +{ > + struct device **alloc_dev = data; > + > + if (!dev_has_iommu(dev)) > + return 0; > + > + WARN_ONCE(*alloc_dev && dev_iommu_ops(dev) != dev_iommu_ops(*alloc_dev), > + "Multiple IOMMU drivers present, which the public IOMMU API can't fully support yet. You may still need to disable one or more to get the expected result here, sorry!\n"); > + > + *alloc_dev = dev; > + return 0; > +} > + > struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus) > { > - return __iommu_domain_alloc(bus, IOMMU_DOMAIN_UNMANAGED); > + struct device *dev = NULL; > + > + if (bus_for_each_dev(bus, NULL, &dev, __iommu_domain_alloc_dev)) > + return NULL; __iommu_domain_alloc_dev() always returns 0. Hence above if condition will never be true. Perhaps, in __iommu_domain_alloc_dev(), if (WARN_ON(*alloc_dev && dev_iommu_ops(dev) != dev_iommu_ops(*alloc_dev)) return -EPERM; ? > + > + return __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANAGED); Is it possible that all devices on this bus have dev_has_iommu() to be false? If so, we probably need something like below: if (!dev_has_iommu(dev)) return -ENODEV; ? > } > EXPORT_SYMBOL_GPL(iommu_domain_alloc); > > @@ -3228,13 +3242,17 @@ static int __iommu_group_alloc_blocking_domain(struct iommu_group *group) > if (group->blocking_domain) > return 0; > > - group->blocking_domain = __iommu_domain_alloc(dev->bus, IOMMU_DOMAIN_BLOCKED); > + /* noiommu groups should never be here */ > + if (WARN_ON(!dev_has_iommu(dev))) > + return -ENODEV; > + > + group->blocking_domain = __iommu_domain_alloc(dev, 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->bus, IOMMU_DOMAIN_UNMANAGED); > + group->blocking_domain = __iommu_domain_alloc(dev, IOMMU_DOMAIN_UNMANAGED); > if (!group->blocking_domain) > return -EINVAL; > } Best regards, baolu