From patchwork Tue Nov 8 07:34:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 16919 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2553613wru; Tue, 8 Nov 2022 00:05:38 -0800 (PST) X-Google-Smtp-Source: AMsMyM4VNvPqm+4y1ebvEp6AqJ8tK4E6GfxkH+Al0WUxEW8PV26dkOGq6Jde9fXOLdToG+P494jF X-Received: by 2002:a05:6402:696:b0:461:ecca:e8a with SMTP id f22-20020a056402069600b00461ecca0e8amr911954edy.139.1667894738706; Tue, 08 Nov 2022 00:05:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667894738; cv=none; d=google.com; s=arc-20160816; b=EcGBtxXsXiEDrwdDi3IU2In91/U08mQBNh6desfk7XjLn/w+s6o8VFjh6omHEnhJWS xw7OKWVtmJ+6lOm3OPwAmbDgcW+fKIba+OFW93pxrSDrJ7xwnufn37614rVz/cet3HUi if6b9YTzqiOCEGmAohBAeSM+emHIn3Wq/im8i1iRGaToFNomi3MPYjVLsm+MOlJh/TAq yMJ1CqXlIhFDol9lvQgUseSIf/g8/NixvMOAf8FZL6TB4NXd8MOYFqpxYRAcb0aGNNsj rvqC8seLYc8FrT6YFRTy+Cy8ov3TjSJPtBrdvyWH89JsjJw6BzsL29PXvjfx4oCfsHqJ 4bGA== 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=RdWIZp5AmyZwMgfIC5iNflDooMSbxRehFJwlfe0y7bU=; b=BTs7+WFJg5qGtT3j03Awlf8MIBtA3UNTepDwynlm/ESjesQgMgLgnwANuHtaR++8N9 DNle6i3K8rPu+bfXBYeQvUY0Plm/DsVjiKUoq82JCVxWU3Q+HN6DvgQTBwztvyFlF6mb AcYAOQEbE1N+Dvrr8gSKZulN+d1jMUDiT8Ff7FgKesVrC23Uv3VJy923NqdiWXccLWbZ yWh5F/sRadqdZ+LH10hV1+2C2tv2C/YtjABFkn1JjwXuEOZpheybuSMMpIW0HVEYv/b+ uLcT3KSxgNinHWgelqzttUohfE/WcNhdvjgnZS+RfenGZy8Q979xqyCuIOuarOK7pwZE F8jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G+7AjoCK; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a509e05000000b00461c12f1f4csi10846770ede.478.2022.11.08.00.05.12; Tue, 08 Nov 2022 00:05:38 -0800 (PST) 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=G+7AjoCK; 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 S233832AbiKHHmT (ORCPT + 99 others); Tue, 8 Nov 2022 02:42:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbiKHHli (ORCPT ); Tue, 8 Nov 2022 02:41:38 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD1F9E3B for ; Mon, 7 Nov 2022 23:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667893296; x=1699429296; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=La92Ayvnwa0vkurcX0IYDOYl3Lt67lg9NIa8NEWq5NA=; b=G+7AjoCKQFEjdQPGcDZB4tpVzH4bOEWyOWQpCDvileCjgebTeeBb+Eeb cWcbMGYGe1GYZ0s//BUegxZszDYWGMGQMRsIjO9I8y08q4e9QGM+hyra+ 2yrNc8yg+BXFxrDUYa/KA6IdAvJ4Mrbd5BZbzY0DBFkdUg3A/yc6mFv4u TGiESVNIjZK8a2JSf/wd2SsHcEb5QTGVAKQNUyvFIXRJ5DqQe97QNyTHu pZf0MGVsZExBG6TwQ/igQE6k0Rl8f27TTrLdL2RHALK+dIbIhOX2Tal63 jcnoOCULo1NAQxyg15uw1HPaMpN3CUubj7iS4tp/aInfvXLW1PQIZAb2z Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="309340034" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="309340034" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 23:41:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="699821988" X-IronPort-AV: E=Sophos;i="5.96,147,1665471600"; d="scan'208";a="699821988" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga008.fm.intel.com with ESMTP; 07 Nov 2022 23:41:17 -0800 From: Lu Baolu To: iommu@lists.linux.dev Cc: Joerg Roedel , Kevin Tian , Will Deacon , Robin Murphy , Liu Yi L , Jacob jun Pan , linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 8/8] iommu/vt-d: Use real field for indication of first level Date: Tue, 8 Nov 2022 15:34:08 +0800 Message-Id: <20221108073408.1005721-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108073408.1005721-1-baolu.lu@linux.intel.com> References: <20221108073408.1005721-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748914393734782943?= X-GMAIL-MSGID: =?utf-8?q?1748914393734782943?= The dmar_domain uses bit field members to indicate the behaviors. Add a bit field for using first level and remove the flags member to avoid duplication. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 15 +++++---------- drivers/iommu/intel/iommu.c | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 251a609fdce3..7b7234689cb4 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -515,14 +515,6 @@ struct context_entry { u64 hi; }; -/* - * When VT-d works in the scalable mode, it allows DMA translation to - * happen through either first level or second level page table. This - * bit marks that the DMA translation for the domain goes through the - * first level page table, otherwise, it goes through the second level. - */ -#define DOMAIN_FLAG_USE_FIRST_LEVEL BIT(1) - struct iommu_domain_info { struct intel_iommu *iommu; unsigned int refcnt; /* Refcount of devices per iommu */ @@ -539,6 +531,11 @@ struct dmar_domain { u8 iommu_coherency: 1; /* indicate coherency of iommu access */ u8 force_snooping : 1; /* Create IOPTEs with snoop control */ u8 set_pte_snp:1; + u8 use_first_level:1; /* DMA translation for the domain goes + * through the first level page table, + * otherwise, goes through the second + * level. + */ spinlock_t lock; /* Protect device tracking lists */ struct list_head devices; /* all devices' list */ @@ -548,8 +545,6 @@ struct dmar_domain { /* adjusted guest address width, 0 is level 2 30-bit */ int agaw; - - int flags; /* flags to find out type of domain */ int iommu_superpage;/* Level of superpages supported: 0 == 4KiB (no superpages), 1 == 2MiB, 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f8f6092ea23c..ccefa3b52240 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -383,11 +383,6 @@ static inline int domain_type_is_si(struct dmar_domain *domain) return domain->domain.type == IOMMU_DOMAIN_IDENTITY; } -static inline bool domain_use_first_level(struct dmar_domain *domain) -{ - return domain->flags & DOMAIN_FLAG_USE_FIRST_LEVEL; -} - static inline int domain_pfn_supported(struct dmar_domain *domain, unsigned long pfn) { @@ -501,7 +496,7 @@ static int domain_update_iommu_superpage(struct dmar_domain *domain, rcu_read_lock(); for_each_active_iommu(iommu, drhd) { if (iommu != skip) { - if (domain && domain_use_first_level(domain)) { + if (domain && domain->use_first_level) { if (!cap_fl1gp_support(iommu->cap)) mask = 0x1; } else { @@ -579,7 +574,7 @@ static void domain_update_iommu_cap(struct dmar_domain *domain) * paging and 57-bits with 5-level paging). Hence, skip bit * [N-1]. */ - if (domain_use_first_level(domain)) + if (domain->use_first_level) domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw - 1); else domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw); @@ -947,7 +942,7 @@ static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, domain_flush_cache(domain, tmp_page, VTD_PAGE_SIZE); pteval = ((uint64_t)virt_to_dma_pfn(tmp_page) << VTD_PAGE_SHIFT) | DMA_PTE_READ | DMA_PTE_WRITE; - if (domain_use_first_level(domain)) { + if (domain->use_first_level) { pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US; if (iommu_is_dma_domain(&domain->domain)) pteval |= DMA_FL_PTE_ACCESS; @@ -1536,7 +1531,7 @@ static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, if (ih) ih = 1 << 6; - if (domain_use_first_level(domain)) { + if (domain->use_first_level) { qi_flush_piotlb(iommu, did, PASID_RID2PASID, addr, pages, ih); } else { unsigned long bitmask = aligned_pages - 1; @@ -1590,7 +1585,7 @@ static inline void __mapping_notify_one(struct intel_iommu *iommu, * It's a non-present to present mapping. Only flush if caching mode * and second level. */ - if (cap_caching_mode(iommu->cap) && !domain_use_first_level(domain)) + if (cap_caching_mode(iommu->cap) && !domain->use_first_level) iommu_flush_iotlb_psi(iommu, domain, pfn, pages, 0, 1); else iommu_flush_write_buffer(iommu); @@ -1606,7 +1601,7 @@ static void intel_flush_iotlb_all(struct iommu_domain *domain) struct intel_iommu *iommu = info->iommu; u16 did = domain_id_iommu(dmar_domain, iommu); - if (domain_use_first_level(dmar_domain)) + if (dmar_domain->use_first_level) qi_flush_piotlb(iommu, did, PASID_RID2PASID, 0, -1, 0); else iommu->flush.flush_iotlb(iommu, did, 0, 0, @@ -1779,7 +1774,7 @@ static struct dmar_domain *alloc_domain(unsigned int type) domain->nid = NUMA_NO_NODE; if (first_level_by_default(type)) - domain->flags |= DOMAIN_FLAG_USE_FIRST_LEVEL; + domain->use_first_level = true; domain->has_iotlb_device = false; INIT_LIST_HEAD(&domain->devices); spin_lock_init(&domain->lock); @@ -2212,7 +2207,7 @@ __domain_mapping(struct dmar_domain *domain, unsigned long iov_pfn, attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP); attr |= DMA_FL_PTE_PRESENT; - if (domain_use_first_level(domain)) { + if (domain->use_first_level) { attr |= DMA_FL_PTE_XD | DMA_FL_PTE_US | DMA_FL_PTE_ACCESS; if (prot & DMA_PTE_WRITE) attr |= DMA_FL_PTE_DIRTY; @@ -2482,7 +2477,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain, if (hw_pass_through && domain_type_is_si(domain)) ret = intel_pasid_setup_pass_through(iommu, domain, dev, PASID_RID2PASID); - else if (domain_use_first_level(domain)) + else if (domain->use_first_level) ret = domain_setup_first_level(iommu, domain, dev, PASID_RID2PASID); else @@ -4422,7 +4417,7 @@ static void domain_set_force_snooping(struct dmar_domain *domain) * Second level page table supports per-PTE snoop control. The * iommu_map() interface will handle this by setting SNP bit. */ - if (!domain_use_first_level(domain)) { + if (!domain->use_first_level) { domain->set_pte_snp = true; return; }