Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3890437rwl; Mon, 27 Mar 2023 22:49:55 -0700 (PDT) X-Google-Smtp-Source: AKy350YSMBLyf02euf5HaSyf9b4JPYpl6i8Jhx361FjxfVvEkgBZ8hnr1ToSIyYEYYOcWVxN6NQ5 X-Received: by 2002:a17:902:e74c:b0:1a1:b11d:6af5 with SMTP id p12-20020a170902e74c00b001a1b11d6af5mr18059768plf.52.1679982595344; Mon, 27 Mar 2023 22:49:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679982595; cv=none; d=google.com; s=arc-20160816; b=or8zuet+RsOLad25MyFqi/S6CYQ79lP02AgwWdqLuRarTLHOZwH3j7a9EVMu8OLRx1 j+rEwkVnOAFC6UP2p7AsJL0PtT4a75ERhftejbYrfyWVDKB7Oo9MHXRyMc3tr7l6+68y 5ZO7SrXwI0B/rAXIHXJDM06iP7+THFp3owijRPXJUdXRAJzlKJ6DMfJhXYIkkWBotwIR 4icJSa22bDmL152y88MBE3fcYalFBJZY/9yltEWsXdicn6SBQkAVPpAauWRTOCeENBOo g8z7imnjdUDhCegk1r2ZQK5JJ4BRsg8zqOGeUcOCWR7Os8JLV447z5EU0Xf5USFwh0lJ B01Q== 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=SNukOhxypVrifwJg98NZCFmnCo/7BxqZrE2dYViEQYo=; b=MhvBIfQVUl8OlsTFzWnZ5bd45Ir2h2a7iE8nSKU7OfdmyGHEdk74lOi3dLJDxypOUP qJnIc6ajLoaYSE4bcfjvxvQKabAfqdLIYtNlDeJULsoxqmo5dd+ankdQ8EhAfWSgr0hJ M04MzE6/MW72myJfWGnIfiDgO79On3kVr3P3fl80CjyXByISNnI1tieh9IXQMJzRcHAW 5BdS5LmAU0IXzq59qWTjNKj8taX/DAhMLI+DtHfEDHTDTx6bNMnryt0ypWy4RhOi3mbx THhFB0H3NHkWByMUSHe3Evw6SCEWL2DaOIYBgk8YAWwxLh9tDXcr8VVznbMoHw3ozfqV 2xxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Lx4f9PP2; 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 d13-20020a63ed0d000000b00502ec718ab8si28067997pgi.284.2023.03.27.22.49.43; Mon, 27 Mar 2023 22:49:55 -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=Lx4f9PP2; 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 S230095AbjC1FtS (ORCPT + 99 others); Tue, 28 Mar 2023 01:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjC1FtQ (ORCPT ); Tue, 28 Mar 2023 01:49:16 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D811BFD; Mon, 27 Mar 2023 22:49:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679982556; x=1711518556; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=3umUbM9oJ7s5zHn3EjA5OyrI/C10PnQfI+nvrcZjrQI=; b=Lx4f9PP2UGTscM40Jk/86a9VW92Wc/LpMSlihXuYvO0tJps1hdCaLUkM Il9A7wWUHN2KP1KpnDioK5VGcABPSNPE3sxkPx768DpigXJqOvUD4xCnx csvLnGNmnTDZoAoZZDpRxtbIoxvlsbyjAx5QburGghjavhHmxn6BCc0ja 2GRJm33/XXhd1zP/CMx8hhVDDJkTgaAjTE2ZUso5KOWq5FonVL/pSTSHB chikQI/z/N99yLVS+lWHIxmqUXlSVxvvj+zJi2JNrXecbzAXdjfmVH6M3 wAQT1Jb7QI1/yMLBGOgQpFFwAmTbu/My7J6uokuFiZO9LUoii1XzGoJKJ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="324371759" X-IronPort-AV: E=Sophos;i="5.98,296,1673942400"; d="scan'208";a="324371759" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 22:49:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="714128861" X-IronPort-AV: E=Sophos;i="5.98,296,1673942400"; d="scan'208";a="714128861" Received: from allen-box.sh.intel.com (HELO [10.239.159.48]) ([10.239.159.48]) by orsmga008.jf.intel.com with ESMTP; 27 Mar 2023 22:49:05 -0700 Message-ID: <71b60cc2-4ab0-3777-6bc9-3a6a4174f743@linux.intel.com> Date: Tue, 28 Mar 2023 13:49:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Cc: baolu.lu@linux.intel.com, Robin Murphy , Will Deacon , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" Subject: Re: [PATCH v2 5/8] iommu/vt-d: Make device pasid attachment explicit Content-Language: en-US To: Jacob Pan , LKML , iommu@lists.linux.dev, Jason Gunthorpe , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org References: <20230327232138.1490712-1-jacob.jun.pan@linux.intel.com> <20230327232138.1490712-6-jacob.jun.pan@linux.intel.com> From: Baolu Lu In-Reply-To: <20230327232138.1490712-6-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 3/28/23 7:21 AM, Jacob Pan wrote: > diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h > index 65b15be72878..b6c26f25d1ba 100644 > --- a/drivers/iommu/intel/iommu.h > +++ b/drivers/iommu/intel/iommu.h > @@ -595,6 +595,7 @@ struct dmar_domain { > > spinlock_t lock; /* Protect device tracking lists */ > struct list_head devices; /* all devices' list */ > + struct list_head dev_pasids; /* all attached pasids */ > > struct dma_pte *pgd; /* virtual address */ > int gaw; /* max guest address width */ > @@ -708,6 +709,7 @@ struct device_domain_info { > u8 ats_supported:1; > u8 ats_enabled:1; > u8 dtlb_extra_inval:1; /* Quirk for devices need extra flush */ > + u8 dev_attached:1; /* Device context activated */ > u8 ats_qdep; > struct device *dev; /* it's NULL for PCIe-to-PCI bridge */ > struct intel_iommu *iommu; /* IOMMU used by this device */ > @@ -715,6 +717,12 @@ struct device_domain_info { > struct pasid_table *pasid_table; /* pasid table */ > }; > > +struct device_pasid_info { > + struct list_head link_domain; /* link to domain siblings */ > + struct device *dev; /* physical device derived from */ > + ioasid_t pasid; /* PASID on physical device */ > +}; The dev_pasids list seems to be duplicate with iommu_group::pasid_array. The pasid_array is de facto per-device as the PCI subsystem requires ACS to be enabled on the upstream path to the root port. pci_enable_pasid(): 385 if (!pci_acs_path_enabled(pdev, NULL, PCI_ACS_RR | PCI_ACS_UF)) 386 return -EINVAL; For such PCI topology, pci_device_group() always assigns an exclusive iommu group (a.k.a. singleton group). So, how about moving the pasid_array from struct iommu_group to struct dev_iommu? With this refactoring, the individual iommu driver has no need to create their own pasid array or list. Instead of using iommu_group::mutex, perhaps the pasid_array needs its own lock in struct dev_iommu after moving. Best regards, baolu