Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1401429pxb; Thu, 4 Feb 2021 11:58:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3BxmFnS2GlEZk4HGHqDksFhbpZUZr4RJCkzNH/xmZaSG5ar7AnMu8gmcigUQPn1OerLWq X-Received: by 2002:a05:6402:524f:: with SMTP id t15mr258132edd.158.1612468694879; Thu, 04 Feb 2021 11:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612468694; cv=none; d=google.com; s=arc-20160816; b=CqUZRPEbeyyyri1dTjSejO+mE6SWTd0+ud9K4StL2WuyY1WvjNJEwxNdCQ0hYvkpgj WF26LA1x4j3CvzCZmJ6HVM4qvBD+ptzLBAvWEngbYOr7CSoPki5NfxbfgPPmKInIbrMt qunA9dZFTahzga823h4paHXGOuQq8qI/jmjQZGxPBfKV6u1I76aWPs/L8E4s5PaMKsXD rfWWeLCj8ZT477vZiwLn4dIsKUH6VntHEC4Z8BitRWRFjl54xk1VGfgPJp/Ei5NcLzLn r3v5nvy5yi1OLWKekhJoenYElaKApKtFe6GBaGXhSRllAaORlxUPzIAHM6mqyl9tyKEg CVBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=s9aAI7IQMPfrioIz33E/veetpuAuyG5nKf0LSGLX8to=; b=G8xKNPp/Hdeyk5cFVccsOEJ+z5u4Go0hKo1w1lAO/B35B40x3f3vaiyiWtPwlCrJN0 OWe/kYuO5QQOcbVofVpGKgTCpRzpdEPH+f1yA+Z3URuo9eWpx8Cmy1Khz9HTy8LxK3sI Jsn0/ZDZG7y2lbxIy5dj/CAKgtlvtzwPofqn7mYWQP7iQSBL+z9gNyKoWZnHN7hKHgyA imzu0ZqtyKn77Kw57m6BCJNZ51BpWpJ3mbKNStzhQ5j1iOphvGTJJ8+aMRwVK16FX6Ni Dnric1QTKVmAfDymMmJbm2VKhyqKittrcSbce67iKANBmQAl4HTs4AD6ZTkTC3JbWmaW 3YmA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m25si4098849eda.322.2021.02.04.11.57.50; Thu, 04 Feb 2021 11:58:14 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239638AbhBDT4k (ORCPT + 99 others); Thu, 4 Feb 2021 14:56:40 -0500 Received: from foss.arm.com ([217.140.110.172]:36562 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239444AbhBDTvw (ORCPT ); Thu, 4 Feb 2021 14:51:52 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 25137D6E; Thu, 4 Feb 2021 11:50:58 -0800 (PST) Received: from [10.57.49.26] (unknown [10.57.49.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 838793F73B; Thu, 4 Feb 2021 11:50:55 -0800 (PST) Subject: Re: [RFC PATCH 01/11] iommu/arm-smmu-v3: Add feature detection for HTTU To: Keqian Zhu , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org, Will Deacon , Alex Williamson , Marc Zyngier , Catalin Marinas Cc: Mark Rutland , jiangkunkun@huawei.com, Suzuki K Poulose , Cornelia Huck , lushenming@huawei.com, Kirti Wankhede , James Morse , wanghaibin.wang@huawei.com References: <20210128151742.18840-1-zhukeqian1@huawei.com> <20210128151742.18840-2-zhukeqian1@huawei.com> From: Robin Murphy Message-ID: Date: Thu, 4 Feb 2021 19:50:53 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <20210128151742.18840-2-zhukeqian1@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-28 15:17, Keqian Zhu wrote: > From: jiangkunkun > > The SMMU which supports HTTU (Hardware Translation Table Update) can > update the access flag and the dirty state of TTD by hardware. It is > essential to track dirty pages of DMA. > > This adds feature detection, none functional change. > > Co-developed-by: Keqian Zhu > Signed-off-by: Kunkun Jiang > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 16 ++++++++++++++++ > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 8 ++++++++ > include/linux/io-pgtable.h | 1 + > 3 files changed, 25 insertions(+) > > 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 8ca7415d785d..0f0fe71cc10d 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -1987,6 +1987,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain, > .pgsize_bitmap = smmu->pgsize_bitmap, > .ias = ias, > .oas = oas, > + .httu_hd = smmu->features & ARM_SMMU_FEAT_HTTU_HD, > .coherent_walk = smmu->features & ARM_SMMU_FEAT_COHERENCY, > .tlb = &arm_smmu_flush_ops, > .iommu_dev = smmu->dev, > @@ -3224,6 +3225,21 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) > if (reg & IDR0_HYP) > smmu->features |= ARM_SMMU_FEAT_HYP; > > + switch (FIELD_GET(IDR0_HTTU, reg)) { We need to accommodate the firmware override as well if we need this to be meaningful. Jean-Philippe is already carrying a suitable patch in the SVA stack[1]. > + case IDR0_HTTU_NONE: > + break; > + case IDR0_HTTU_HA: > + smmu->features |= ARM_SMMU_FEAT_HTTU_HA; > + break; > + case IDR0_HTTU_HAD: > + smmu->features |= ARM_SMMU_FEAT_HTTU_HA; > + smmu->features |= ARM_SMMU_FEAT_HTTU_HD; > + break; > + default: > + dev_err(smmu->dev, "unknown/unsupported HTTU!\n"); > + return -ENXIO; > + } > + > /* > * The coherency feature as set by FW is used in preference to the ID > * register, but warn on mismatch. > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > index 96c2e9565e00..e91bea44519e 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h > @@ -33,6 +33,10 @@ > #define IDR0_ASID16 (1 << 12) > #define IDR0_ATS (1 << 10) > #define IDR0_HYP (1 << 9) > +#define IDR0_HTTU GENMASK(7, 6) > +#define IDR0_HTTU_NONE 0 > +#define IDR0_HTTU_HA 1 > +#define IDR0_HTTU_HAD 2 > #define IDR0_COHACC (1 << 4) > #define IDR0_TTF GENMASK(3, 2) > #define IDR0_TTF_AARCH64 2 > @@ -286,6 +290,8 @@ > #define CTXDESC_CD_0_TCR_TBI0 (1ULL << 38) > > #define CTXDESC_CD_0_AA64 (1UL << 41) > +#define CTXDESC_CD_0_HD (1UL << 42) > +#define CTXDESC_CD_0_HA (1UL << 43) > #define CTXDESC_CD_0_S (1UL << 44) > #define CTXDESC_CD_0_R (1UL << 45) > #define CTXDESC_CD_0_A (1UL << 46) > @@ -604,6 +610,8 @@ struct arm_smmu_device { > #define ARM_SMMU_FEAT_RANGE_INV (1 << 15) > #define ARM_SMMU_FEAT_BTM (1 << 16) > #define ARM_SMMU_FEAT_SVA (1 << 17) > +#define ARM_SMMU_FEAT_HTTU_HA (1 << 18) > +#define ARM_SMMU_FEAT_HTTU_HD (1 << 19) > u32 features; > > #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) > diff --git a/include/linux/io-pgtable.h b/include/linux/io-pgtable.h > index ea727eb1a1a9..1a00ea8562c7 100644 > --- a/include/linux/io-pgtable.h > +++ b/include/linux/io-pgtable.h > @@ -97,6 +97,7 @@ struct io_pgtable_cfg { > unsigned long pgsize_bitmap; > unsigned int ias; > unsigned int oas; > + bool httu_hd; This is very specific to the AArch64 stage 1 format, not a generic capability - I think it should be a quirk flag rather than a common field. Robin. [1] https://jpbrucker.net/git/linux/commit/?h=sva/current&id=1ef7d512fb9082450dfe0d22ca4f7e35625a097b > bool coherent_walk; > const struct iommu_flush_ops *tlb; > struct device *iommu_dev; >