Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2310837ybt; Tue, 16 Jun 2020 02:42:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbhJTo/rTtmVQBMPXBR+vysx+sMgu2q8uft2QM+hqcStWHF/GvqPVFH7HcA3QvHtPKAeEw X-Received: by 2002:a17:906:2e1a:: with SMTP id n26mr1852125eji.425.1592300537970; Tue, 16 Jun 2020 02:42:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592300537; cv=none; d=google.com; s=arc-20160816; b=j+0n9zHeZhEr357VuTI6MU5Bh6IFUYa1r8xvaI7w+e6g5ABIyVKcIJFuKJ+S32PLE4 ez8BQZX4NgR87y0BvD3EX3kdbX3hsgQtWfdvP0mVrN0i5oAPIXgGbX+//B6J4knfWIx7 EGROTedQ2eprOWQceBO6JkzDdQsMBKpTrHImlI6edNpJWtvZBDMOpWnjOOuXTIB13RGA lh1l9xvSNq9J3xzFP9hzit0i/EwoW2qNQhoO2NcgkrtBYXAoghVTglU3B6v7WkB7D1Oo jX7x4PdgYcqY9tZiQS/yFpztjNNUABXnHWRUJhY7yC01CF+Y2pbGojLwPS0FMQuqzZng f99A== 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=VrbBB/VKpISeYA2+tJouAMtv8ooGD2GOIaUZPoHs7Vo=; b=TfQghY705D2yCDWD796JQYQ5mPhG6EEa6wHz2X5RD/0GFguAy9pp+TjuSAQEESemxl XeBEBzXx8cUTjlp3wJzYLy9VdtKaNuczfk6lPjR16Hk2ONpVh/Ow+140NApINRqDB0FP CKEvNLEKYc4Iji+JZ+UAAFYyxFrKukkG4aGri+mHcmiBut59Xi7ZJlSOhfqnylWeGP6E aEDMNlPW/q63veZFLDm2zCeZWxdPDUsRcUda2euEGJw5ubfq5m+Hve5STk/z6Ts0xxQR fjlUVU2up+8/yL7T5tVXo33QH9xm+zXB2DY3IFZaUFkcNqYX2gkEegEa5KL4jW6n4CQe aIHQ== 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 z23si10461062ejw.331.2020.06.16.02.41.55; Tue, 16 Jun 2020 02:42:17 -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 S1728266AbgFPJgR (ORCPT + 99 others); Tue, 16 Jun 2020 05:36:17 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6337 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728250AbgFPJgP (ORCPT ); Tue, 16 Jun 2020 05:36:15 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B02EF4A35D21C942F8BC; Tue, 16 Jun 2020 17:36:13 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.173.221.230) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Tue, 16 Jun 2020 17:36:04 +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 Subject: [PATCH 01/12] KVM: arm64: Add some basic functions to support hw DBM Date: Tue, 16 Jun 2020 17:35:42 +0800 Message-ID: <20200616093553.27512-2-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20200616093553.27512-1-zhukeqian1@huawei.com> References: <20200616093553.27512-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 to support hardware DBM for PTEs. Signed-off-by: Keqian Zhu Signed-off-by: Peng Liang --- arch/arm64/include/asm/kvm_mmu.h | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index b12bfc1f051a..e0ee6e23d626 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -265,6 +265,42 @@ 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 void kvm_clear_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