Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp996617rwr; Thu, 27 Apr 2023 10:48:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7q+Z1F+VgY6BETHtga5SyMEQzbbao5RcO6OwwpiqFEkOSQp89gy7qjPdq0EcltAIczuBJf X-Received: by 2002:a05:6a20:3ca6:b0:f4:4ff5:11ab with SMTP id b38-20020a056a203ca600b000f44ff511abmr3032931pzj.58.1682617704167; Thu, 27 Apr 2023 10:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682617704; cv=none; d=google.com; s=arc-20160816; b=EfXUtlRygYR4oGbRtiYujkO/dk21uU5zCNGtVfF5fc21UjRzmtqUMdgf9A0JX3clXR 1/PfqMAB0/I4qAi3uuxO57naNcDqlrS6uQ/ZUGe+gj74wQBsymZG43AbQW17bKLL79jU aaBspRNO7oFWqfC7Zo5qQHdOZvLgZfkNuwveKOoMUlafH5tz0HuxpkSTfdWUZWIwq5gi oBEfxRn2cb6LvuMvfiPw/n+oXxgVx9KGRzjVJLlGnXn6KuJB6gFMWHV33btNbmAs7l/S 9hyfuCszc6iDH8sMOqDU12mTXk6u2q3alo0pQIKblUBPtUuGbCURwxcqUGgqI/pEOeJ2 +dgQ== 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=Yw3B4v1uTpbHl1nCN9CkOAPs7XudaP7/RLQdnh1rb2g=; b=mYDz1cs5xCN3njZnXiS0/OnlXmyD9SLWJ3Y/FZwh7HKSxgyh3eFv9Kr+3V8v7N1VTP mjJwoflRMP/x3vVi98k7EEWqWO1lZM3mDG7n9F/Qsu9qqT0a0HthdNwwFeQDxlTv4xp5 hnYUbf/GGbOswnO9tHjLgmYjTE/N+e5zyrHl4af+TkCqNLAN99L4uG1HZUx9Mr8rNff7 Z//DUWLkoAowBe5tatqdSDZGSdFtB9OFZ3OQIZ0aEHVgk0bxf8tpHeg5p7RJNgTd5mOC wIDqraC7YSGihczMwOlZsMGa/xI8FTnH0Cl+xJp7OUceOiOZNhT0MmAtBIm03eB+TTS0 QrGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RyThv+hq; 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 c14-20020a655a8e000000b0051b72db6281si19212887pgt.456.2023.04.27.10.48.11; Thu, 27 Apr 2023 10:48:24 -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=RyThv+hq; 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 S244389AbjD0Rp6 (ORCPT + 99 others); Thu, 27 Apr 2023 13:45:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244271AbjD0Rpo (ORCPT ); Thu, 27 Apr 2023 13:45:44 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F0CD3581; Thu, 27 Apr 2023 10:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682617540; x=1714153540; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/8RWr0U3j2KVbiC09idxwXgdGc0DHtm2IMJ6x0/p/c0=; b=RyThv+hqWTvnFm1xLzOXfVfzt1g/tF2pYztEScCt4IAiXkSlLH7+1Ztp ccRuOnWzFPRKzFde4i/SzVgZAFDChzYu1frGRRWcwNCRjeExfV8xogB6V 95DvowXkpXFjZOqsWIVaqitBJIFwDIpNxj5ML2/v3jn9oKKAXkcC0kPhk Ue5S5lmLtQG87S/rx3uS/nam6aX1zBPOgQjoNx8fmXMgvFVwP+s11Nxzy skOVMHWESevVeYEaKHe9BbFksZpY6/DLvqsYATQvC01Svg4RzdGwkAls7 AdvLsCYdsabUMdxOfcV2L9z6A4FNhv8QKGdpSsYhuuGjZoMFpoOvI6cCG Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="350398724" X-IronPort-AV: E=Sophos;i="5.99,232,1677571200"; d="scan'208";a="350398724" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2023 10:45:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="1024219712" X-IronPort-AV: E=Sophos;i="5.99,232,1677571200"; d="scan'208";a="1024219712" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.39.106]) by fmsmga005.fm.intel.com with ESMTP; 27 Apr 2023 10:45:21 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Robin Murphy" , Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , narayan.ranganathan@intel.com, Jacob Pan Subject: [PATCH v5 4/7] iommu/vt-d: Factoring out PASID set up helper function Date: Thu, 27 Apr 2023 10:49:34 -0700 Message-Id: <20230427174937.471668-5-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230427174937.471668-1-jacob.jun.pan@linux.intel.com> References: <20230427174937.471668-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 From: Lu Baolu To prepare non-RID_PASID attachment, factoring out common code to be reused. PASID entry set up is common for all DMA API PASIDs. Signed-off-by: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel/iommu.c | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 9ec45e0497cc..cb586849a1ee 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2429,6 +2429,26 @@ static int __init si_domain_init(int hw) return 0; } +static int dmar_domain_attach_device_pasid(struct dmar_domain *domain, + struct intel_iommu *iommu, + struct device *dev, ioasid_t pasid) +{ + int ret; + + /* PASID table is mandatory for a PCI device in scalable mode. */ + if (!sm_supported(iommu) && dev_is_real_dma_subdevice(dev)) + return -EOPNOTSUPP; + + if (hw_pass_through && domain_type_is_si(domain)) + ret = intel_pasid_setup_pass_through(iommu, domain, dev, pasid); + else if (domain->use_first_level) + ret = domain_setup_first_level(iommu, domain, dev, pasid); + else + ret = intel_pasid_setup_second_level(iommu, domain, dev, pasid); + + return 0; +} + static int dmar_domain_attach_device(struct dmar_domain *domain, struct device *dev) { @@ -2450,23 +2470,11 @@ static int dmar_domain_attach_device(struct dmar_domain *domain, list_add(&info->link, &domain->devices); spin_unlock_irqrestore(&domain->lock, flags); - /* PASID table is mandatory for a PCI device in scalable mode. */ - if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) { - /* Setup the PASID entry for requests without PASID: */ - if (hw_pass_through && domain_type_is_si(domain)) - ret = intel_pasid_setup_pass_through(iommu, domain, - dev, IOMMU_DEF_RID_PASID); - else if (domain->use_first_level) - ret = domain_setup_first_level(iommu, domain, dev, - IOMMU_DEF_RID_PASID); - else - ret = intel_pasid_setup_second_level(iommu, domain, - dev, IOMMU_DEF_RID_PASID); - if (ret) { - dev_err(dev, "Setup RID2PASID failed\n"); - device_block_translation(dev); - return ret; - } + ret = dmar_domain_attach_device_pasid(domain, iommu, dev, + IOMMU_DEF_RID_PASID); + if (ret) { + dev_err(dev, "Setup RID2PASID failed\n"); + device_block_translation(dev); } ret = domain_context_mapping(domain, dev); -- 2.25.1