Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp986417ybs; Mon, 25 May 2020 04:29:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztn7ctEAAGz/C8RgV0XsENOR8TW3rLAcQgvMu8M4zTi13iENBM/29S/L12RDfWylLYNuvh X-Received: by 2002:a05:6402:4c6:: with SMTP id n6mr14339615edw.264.1590406153204; Mon, 25 May 2020 04:29:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590406153; cv=none; d=google.com; s=arc-20160816; b=a2rfh1jqoX1E+PIqznedmnihEZbm48FViAW4b5DeDQ39UzVUcDSqt/TFSXcip5GRre tjvfE8Ulf9RX3UJQHR48rHhbzsoowkeuBqoBW+CK6zccCy71xjUX2FebUXzY+t9gAVi3 rAlB0pRCWWbpvhCsUk6huk7c8SUpLQ+wIor2HNmjdBw+o8HIDg/wy+OxwOBu+mmvOJ01 YnSMEPIJj1oefAIeDZRvd3EefbW94dHjAglHnRmuVCbY2ZnQuHnJtaA/Qmh6M44N+tRt 8Ebk0sgADhy1aykLqMtXxQCj8Px00XzPvB7+9gv2rolrLx1BwUaDa944MEiqVNcyPzSq m5Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=/GZIUW3GlVQbAqcl72kGPXv+XS6NvSfO0zRU2J2P99Y=; b=yjjLJ4UpA4r7V8MzUBexmSSGlelETIAMFimmJ7Q6/63y6Mve5GwX6B0kdW/pmzXWeY brhvj4JHA998UYzy018JAEP4XJGjSrBEQOUGH+J477i1nz1yS8MH8hGMyP1goDvrKB7C 2bHgRN9xYl8RQV3qvvVqq9mh2OCy/IcRmpqR3wCUsNYBNF3SCGWS7WYtS7tHh7Dxa1R3 /9UJcu+aLVud0de43VcmTMBr/DpvmGJK/1I2QRsHGDmVcEYqklverccrpc0L9prwRYiB oqtLJrfyTz0nKdiddZmh34zjPaMRrAAkGmD2XT01oPm+TXTlRGIEV30Pkhb4919P64+e htDQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q12si9429065edn.500.2020.05.25.04.28.49; Mon, 25 May 2020 04:29:13 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388715AbgEYLZM (ORCPT + 99 others); Mon, 25 May 2020 07:25:12 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:36940 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389897AbgEYLZL (ORCPT ); Mon, 25 May 2020 07:25:11 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6B0142A7762008D953ED; Mon, 25 May 2020 19:25:09 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.173.221.230) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Mon, 25 May 2020 19:25:02 +0800 From: Keqian Zhu To: , , , CC: Catalin Marinas , Marc Zyngier , James Morse , Will Deacon , "Suzuki K Poulose" , Sean Christopherson , Julien Thierry , Mark Brown , "Thomas Gleixner" , Andrew Morton , Alexios Zavras , , , Keqian Zhu , Peng Liang Subject: [RFC PATCH 1/7] KVM: arm64: Add some basic functions for hw DBM Date: Mon, 25 May 2020 19:24:00 +0800 Message-ID: <20200525112406.28224-2-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20200525112406.28224-1-zhukeqian1@huawei.com> References: <20200525112406.28224-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.173.221.230] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare some basic functions used by following patches to support hardware DBM. Signed-off-by: Keqian Zhu Signed-off-by: Peng Liang --- arch/arm64/include/asm/kvm_mmu.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 30b0e8d6b895..8df078f0ee67 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -285,6 +285,30 @@ static inline bool kvm_s2pud_young(pud_t pud) return pud_young(pud); } +#ifdef CONFIG_ARM64_HW_AFDBM +static inline bool kvm_hw_dbm_enabled(void) +{ + return !!(read_sysreg(vtcr_el2) & VTCR_EL2_HD); +} + +static inline void kvm_set_s2pte_dbm(pte_t *ptep) +{ + pteval_t old_pteval, pteval; + + pteval = READ_ONCE(pte_val(*ptep)); + do { + old_pteval = pteval; + pteval |= PTE_DBM; + pteval = cmpxchg_relaxed(&pte_val(*ptep), old_pteval, pteval); + } while (pteval != old_pteval); +} + +static inline bool kvm_s2pte_dbm(pte_t *ptep) +{ + return !!(READ_ONCE(pte_val(*ptep)) & PTE_DBM); +} +#endif /* CONFIG_ARM64_HW_AFDBM */ + #define hyp_pte_table_empty(ptep) kvm_page_empty(ptep) #ifdef __PAGETABLE_PMD_FOLDED -- 2.19.1