Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6673967iob; Wed, 11 May 2022 02:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyrpqhE8UtmIfkKCI0lp2PDQ4z84CVmIMaM+eFbaGF3FfQNLJjH3l0Orsu46GCbCZTNwgO X-Received: by 2002:aa7:93b3:0:b0:50d:56d2:e752 with SMTP id x19-20020aa793b3000000b0050d56d2e752mr24495898pff.82.1652262790582; Wed, 11 May 2022 02:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652262790; cv=none; d=google.com; s=arc-20160816; b=K2e7YLTHqO2ENc3DQTy6OgCPmxo9s2PUtAW8h6V7obC8XWym9ZnxjIae5qzh8lge8h Ux4qq37xBOz/pWn1ESx9GT4GpWhFpefScgWy03Rp8JNCflklQogXFXxV46Vwy2B9l1QS 4BIN1VGkac9kKuf3fxLH6WCbVCCrUBwIC0+tBusJWhw7C91Txop0mFENOSp6LopNdWXq 59k9TI4F2iWBZ/6lrKH/XcA5Js2kr5BGPpeDeQoT5G8qiQdso0+OlVa958XMvPCOp0ac I9QprNiFQMjlFyk2jWoo4FLYr2eLwhMX6/02Bl89mDn+63ksgiBEsAYwVZg3eWBS+Nm0 KJAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=M4aeMJFFFKV21hSaluDeCVxCbgPrszET6TE6+DuKZy0=; b=FrHM+Z9mFVsRDKuAjc6o0vAMK21XheTYzIFf0KicUQgPgrR2pKTzMq/yVAYp0+BWdF RI2kMZGqEvmIHGrXnF7n4Zo4kBd/jXVcws9Dwy7kpb5vjmphWnw44Wm6XVcsyd7GSrL2 gucPZ3X6LYdp0RrDbHlUK453JXZK9Wmv7oPPsIx0bW72IBztUXpYo+ZlhqCz4F21/9YP uAkVxbFgUWqAOuHs4Kf/nKECJgraNsUHudGW5H1n4AcxSO8O1kaY3NmdZthlx7PNLmj7 3UYWFHtqk40f05SI+2YNCZkGV4FsU6sXQ78F5PzRakIuqxx19cza6f7cs7WLcJ4iygRW 418Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pHErwaiX; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a631844000000b003c14d8d1270si2240507pgy.562.2022.05.11.02.52.57; Wed, 11 May 2022 02:53:10 -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=@linaro.org header.s=google header.b=pHErwaiX; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243238AbiEKIBW (ORCPT + 99 others); Wed, 11 May 2022 04:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239763AbiEKIBT (ORCPT ); Wed, 11 May 2022 04:01:19 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACE5F39159 for ; Wed, 11 May 2022 01:01:17 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id d6so1547839ede.8 for ; Wed, 11 May 2022 01:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=M4aeMJFFFKV21hSaluDeCVxCbgPrszET6TE6+DuKZy0=; b=pHErwaiX6ufGPbr+xXjlPt1Yc3gEtnWaSm8ytmYX710fnKTCNneuXmpcCLCEGqTExG m7Hs6QUMpa2kf0CWT3yM0LTy2PyrJCG8N6qYBW7tQGijpTswQh71X3v6WO+XdWu0TuDe 09GmCLxd2aNLZu2aOIBXK4Nofo/Fe5dGXd/AkIQ8ZA4sJ3cl31BKatHndrY1YfzV4Cm+ Oz1Uu7sXr1ERXN6NrCvL7Vi7oHCV30QoCD8jBzDjIsjjJvfrXNxSGICoehoho0L32G9m oLc7zw+8k22xvyS5HFxdVTtPJYJTjRW5Ps+XqcmHsp6UZroC3Oe4leN4M4Nu5ri+XNXa INXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=M4aeMJFFFKV21hSaluDeCVxCbgPrszET6TE6+DuKZy0=; b=R7OOgJLBtZ+ZdI+XL0ftNcHbkw/LQcGThd037rgi22LEZS+EBAtSC8AGt5ObnTGWSF QNhfs/b3gbjCqBj5CAb39w9P+R3ZAohvpdoYIMrvfwH7NgZbO4uhM41pwWapWBaxA3eb CkKt4hbLALmhf9cXR1fesjS+2kzYFC0OBJXYLJWFUpCz8DlpujjGq8B51QBxDsyZ//6F 0uELoMFStHHmOTGB+t7Oxk0t1kO9xdaDB54loUN1MIbTlLNM4Cqe/2z+H5EsDVjW5UR1 lb0w57yqYrHUH32hJlj/q4iGEm+tzVrpvTwqVfs/ZrmPXyl5MyiXuCgmbv3jIHT447nl Nyhw== X-Gm-Message-State: AOAM532e0BK4cFW5vL2CTeOI+HeMUQgp7BTljkmMyoZLsRQccC+7pfQb OrCwSM1iRzRzYct5OLPfUTuuyJ5DrYWpHv4L X-Received: by 2002:a05:6402:e9f:b0:41c:df21:b113 with SMTP id h31-20020a0564020e9f00b0041cdf21b113mr27914392eda.217.1652256076253; Wed, 11 May 2022 01:01:16 -0700 (PDT) Received: from myrica (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id h12-20020a05640250cc00b0042617ba63d5sm783085edb.95.2022.05.11.01.01.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:01:15 -0700 (PDT) Date: Wed, 11 May 2022 09:00:50 +0100 From: Jean-Philippe Brucker To: Baolu Lu Cc: Jason Gunthorpe , Joerg Roedel , Christoph Hellwig , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Vinod Koul , Eric Auger , Liu Yi L , Jacob jun Pan , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 02/12] iommu: Add pasid_bits field in struct dev_iommu Message-ID: References: <20220510061738.2761430-1-baolu.lu@linux.intel.com> <20220510061738.2761430-3-baolu.lu@linux.intel.com> <20220510143405.GE49344@nvidia.com> <3fe05f18-6726-276a-8c42-79e0b134dfdc@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3fe05f18-6726-276a-8c42-79e0b134dfdc@linux.intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Wed, May 11, 2022 at 10:25:48AM +0800, Baolu Lu wrote: > On 2022/5/10 22:34, Jason Gunthorpe wrote: > > On Tue, May 10, 2022 at 02:17:28PM +0800, Lu Baolu wrote: > > > > > int iommu_device_register(struct iommu_device *iommu, > > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > > > index 627a3ed5ee8f..afc63fce6107 100644 > > > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > > > @@ -2681,6 +2681,8 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev) > > > smmu->features & ARM_SMMU_FEAT_STALL_FORCE) > > > master->stall_enabled = true; > > > + dev->iommu->pasid_bits = master->ssid_bits; > > > return &smmu->iommu; > > > err_free_master: > > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > > index 2990f80c5e08..99643f897f26 100644 > > > +++ b/drivers/iommu/intel/iommu.c > > > @@ -4624,8 +4624,11 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev) > > > if (pasid_supported(iommu)) { > > > int features = pci_pasid_features(pdev); > > > - if (features >= 0) > > > + if (features >= 0) { > > > info->pasid_supported = features | 1; > > > + dev->iommu->pasid_bits = > > > + fls(pci_max_pasids(pdev)) - 1; > > > + } > > > > It is not very nice that both the iommu drivers have to duplicate the > > code to read the pasid capability out of the PCI device. > > > > IMHO it would make more sense for the iommu layer to report the > > capability of its own HW block only, and for the core code to figure > > out the master's limitation using a bus-specific approach. > > Fair enough. The iommu hardware capability could be reported in > > /** > * struct iommu_device - IOMMU core representation of one IOMMU hardware > * instance > * @list: Used by the iommu-core to keep a list of registered iommus > * @ops: iommu-ops for talking to this iommu > * @dev: struct device for sysfs handling > */ > struct iommu_device { > struct list_head list; > const struct iommu_ops *ops; > struct fwnode_handle *fwnode; > struct device *dev; > }; > > I haven't checked ARM code yet, but it works for x86 as far as I can > see. Arm also supports non-PCI PASID by reading a firmware property: device_property_read_u32(dev, "pasid-num-bits", &master->ssid_bits); should be the only difference Thanks, Jean > > > > > It is also unfortunate that the enable/disable pasid is inside the > > iommu driver as well - ideally the PCI driver itself would do this > > when it knows it wants to use PASIDs. > > > > The ordering interaction with ATS makes this look quite annoying > > though. :( > > > > I'm also not convinced individual IOMMU drivers should be forcing ATS > > on, there are performance and functional implications here. Using ATS > > or not is possibly best left as an administrator policy controlled by > > the core code. Again we seem to have some mess. > > Agreed with you. This has already been in my task list. I will start to > solve it after the iommufd tasks. > > Best regards, > baolu