Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp658186pxj; Tue, 18 May 2021 11:11:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw01F2AUixIcNQz5IEWvrnNPQT97w+LY1uR0qHWjJMNUBr0KXuPosZgapb7AVqZ5GXWhUqW X-Received: by 2002:a02:92cc:: with SMTP id c12mr6916089jah.30.1621361478882; Tue, 18 May 2021 11:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621361478; cv=none; d=google.com; s=arc-20160816; b=ehKr04u0LKJ6SIk/xyKNsGSl9mi8J84bbVLGfLCbZ/Uq8X83w0Ifupi3kx6vy1bjC9 rp4oSTvTXEpZhSmQyiFnY9hhCx/2hoSh54Ce574yF0bm1gbflQY+5F07kosGeJQLMWTO hqw9bwP7mOUEYBpm+grcRf+taOEXuk3ilh916cb2E4qJbFpwFN0XsgZp4R263NtxPuYB 53thWxgijNRg+2lVw9NDoCdR2Si9PHEO4N/9gfqPFO9Z4enjf+366lisHSJM1ItF1CSf l/H5sXuRQTwbfMllqgOIxDvag3hQ9VqU5k7FM31ItG3XabgOYWTcu1Ohb0uHflsBFGBY YX+w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sWXBK5RCZkd3vTBq0VYxo+4FgFn96zrcI3LwF1souyg=; b=BH90Ob0RwRLbjJJ/hHga2VAWafJCrEbJ53ccE+IDYieW5xYaauM7vviEEwriPGdrXv 2CdnKGHGe+xYzjUgU9n6jNzeybg2VgT/mLHgVAS5cdzgvw1q7yBKVWjKiL0etgFauyWW Jx38X7F14X/fnE8kagVMDr9MMgvw60AU4J1XEJHi/Td3OthIjzQAPFoq7tWask6l1vSL zs+kFmGCVphgJOMjAwf01Kxwh6ZFiic6TOh5Vd+MaEWLYXh9p9Lu3Ze9YeUqwX0+eRFh f4K26nGrtFOfFTtCK/ivaoF+KUA1e6WOMsqvxwvklcD1XCQ67rZqeLWKvnKj0/kX2sPR xjNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zlTlOld4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si525891iov.17.2021.05.18.11.11.06; Tue, 18 May 2021 11:11:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zlTlOld4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344165AbhEQQL3 (ORCPT + 99 others); Mon, 17 May 2021 12:11:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236801AbhEQPsP (ORCPT ); Mon, 17 May 2021 11:48:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4164F61D3E; Mon, 17 May 2021 14:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262703; bh=2eQ1qHTJq6cqie3db6kFAzA/7Phu+3ozOdCWCnigtUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zlTlOld4LZyV5SPypunSojuGKPnMRGjtsJBGhlGPzXUYI1SpbFGnwASSG5lLOflWu i1Uqq9Uzu0iEZgCDClSqBzZUa0ganJc7MbFuNZuNqceVTLZxpasxsFDnv5MOLOXwhO 1CjZgYySEzriqWm7MoU0tKM6JvesiEjvzEdGXOg8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ashok Raj , Lu Baolu , Joerg Roedel Subject: [PATCH 5.10 263/289] iommu/vt-d: Preset Access/Dirty bits for IOVA over FL Date: Mon, 17 May 2021 16:03:08 +0200 Message-Id: <20210517140313.999886927@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu Baolu commit a8ce9ebbecdfda3322bbcece6b3b25888217f8e3 upstream. The Access/Dirty bits in the first level page table entry will be set whenever a page table entry was used for address translation or write permission was successfully translated. This is always true when using the first-level page table for kernel IOVA. Instead of wasting hardware cycles to update the certain bits, it's better to set them up at the beginning. Suggested-by: Ashok Raj Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20210115004202.953965-1-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/intel/iommu.c | 14 ++++++++++++-- include/linux/intel-iommu.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1028,8 +1028,11 @@ static struct dma_pte *pfn_to_dma_pte(st 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(domain)) { pteval |= DMA_FL_PTE_XD | DMA_FL_PTE_US; + if (domain->domain.type == IOMMU_DOMAIN_DMA) + pteval |= DMA_FL_PTE_ACCESS; + } if (cmpxchg64(&pte->val, 0ULL, pteval)) /* Someone else set it while we were thinking; use theirs. */ free_pgtable_page(tmp_page); @@ -2359,9 +2362,16 @@ static int __domain_mapping(struct dmar_ return -EINVAL; attr = prot & (DMA_PTE_READ | DMA_PTE_WRITE | DMA_PTE_SNP); - if (domain_use_first_level(domain)) + if (domain_use_first_level(domain)) { attr |= DMA_FL_PTE_PRESENT | DMA_FL_PTE_XD | DMA_FL_PTE_US; + if (domain->domain.type == IOMMU_DOMAIN_DMA) { + attr |= DMA_FL_PTE_ACCESS; + if (prot & DMA_PTE_WRITE) + attr |= DMA_FL_PTE_DIRTY; + } + } + if (!sg) { sg_res = nr_pages; pteval = ((phys_addr_t)phys_pfn << VTD_PAGE_SHIFT) | attr; --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -42,6 +42,8 @@ #define DMA_FL_PTE_PRESENT BIT_ULL(0) #define DMA_FL_PTE_US BIT_ULL(2) +#define DMA_FL_PTE_ACCESS BIT_ULL(5) +#define DMA_FL_PTE_DIRTY BIT_ULL(6) #define DMA_FL_PTE_XD BIT_ULL(63) #define ADDR_WIDTH_5LEVEL (57)