Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp985500ybs; Mon, 25 May 2020 04:27:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSK2eCAWFwcUNcKe5D6tdGERO/0zfmbaW/aZc+x/VYo/2hhcSTVF48T+RfJN6TbGK/6Uqv X-Received: by 2002:a17:906:81ce:: with SMTP id e14mr18017587ejx.76.1590406061132; Mon, 25 May 2020 04:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590406061; cv=none; d=google.com; s=arc-20160816; b=THvJX/IyizvCs5BGxjMP1SIh8MVzYZ0eoMl/dv1jC3GwkJG+UXs7UBqDAWznBv9afj 7RhcKqVbBY8F0i031nsz0949Ij1g/IeFcFJ5H+2iBBFWPOgeVuXdRTlJwjvTSvlfZnKR 13cu/S8nIssr8exLFMDYS6wR+Z1nTDNsooyyyAHngkp0f21Svrb/qXsYxjfRsYUJHJbq NHUMaOINwx5yhQr/63vV8d6VPJAU1JmsqCt549dcrifCnd9yjYPjeMEVhqpo5cwqqjFj jKb5Qek7SHRUKo6bPh0G/GR/McP1CZ2x7/wPnEfhj5SZ6ZG93Kra7DiLuuNeUy7Pg7n/ Wsqw== 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=Lg8BIymUnrS7PeXlWQLSDeGksLk+8TMbgFpl3zbTPPw=; b=dnsyLuSV4PR2ZyzVt4Qy46AwO1VZP6KxteFrlZg+2mgKQruDLp69miy71Op7J3SoNd 1pLEU90ASWBply/lTsdopO+cBqSlRx+hffFXP10bcdRFoX4/sfspXKzF/sDlPIDXV8pC F9Kg/UNeqHalbTBV4B/VO8gRdJYao4t5llF9xX0CnMo+w6pRpXghCFfo7o+QlVERR/6l 387A80DWb3K1PtL8dzUVm4CkcR2fVV4IRqsoRq4WyIEGJDsyPYV/CBirIy2zh4wGdqBF qheujtehDUItWIefyVG0ouhalUwXdiDHz4wuxUHQic2HNdD5uXbOB0y6LU4KbjNgC8kr 3yvQ== 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 p16si8576879ejd.80.2020.05.25.04.27.15; Mon, 25 May 2020 04:27:41 -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 S2388506AbgEYLZO (ORCPT + 99 others); Mon, 25 May 2020 07:25:14 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:36936 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390155AbgEYLZL (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 6277791ED5DCDAB77912; 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:03 +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 2/7] KVM: arm64: Set DBM bit of PTEs if hw DBM enabled Date: Mon, 25 May 2020 19:24:01 +0800 Message-ID: <20200525112406.28224-3-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 In user_mem_abort, for normal case (mem_type is PAGE_S2), set DBM bit of PTEs if hw DBM enabled. We also check and set DBM bit during write protect PTEs to make it works well if we miss some cases. Signed-off-by: Keqian Zhu Signed-off-by: Peng Liang --- arch/arm64/include/asm/pgtable-prot.h | 1 + virt/kvm/arm/mmu.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h index 1305e28225fc..f9910ba2afd8 100644 --- a/arch/arm64/include/asm/pgtable-prot.h +++ b/arch/arm64/include/asm/pgtable-prot.h @@ -79,6 +79,7 @@ extern bool arm64_use_ng_mappings; }) #define PAGE_S2 __pgprot(_PROT_DEFAULT | PAGE_S2_MEMATTR(NORMAL) | PTE_S2_RDONLY | PAGE_S2_XN) +#define PAGE_S2_DBM __pgprot(_PROT_DEFAULT | PAGE_S2_MEMATTR(NORMAL) | PTE_S2_RDONLY | PAGE_S2_XN | PTE_DBM) #define PAGE_S2_DEVICE __pgprot(_PROT_DEFAULT | PAGE_S2_MEMATTR(DEVICE_nGnRE) | PTE_S2_RDONLY | PTE_S2_XN) #define PAGE_NONE __pgprot(((_PAGE_DEFAULT) & ~PTE_VALID) | PTE_PROT_NONE | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index e3b9ee268823..dc97988eb2e0 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1426,6 +1426,10 @@ static void stage2_wp_ptes(pmd_t *pmd, phys_addr_t addr, phys_addr_t end) pte = pte_offset_kernel(pmd, addr); do { if (!pte_none(*pte)) { +#ifdef CONFIG_ARM64_HW_AFDBM + if (kvm_hw_dbm_enabled() && !kvm_s2pte_dbm(pte)) + kvm_set_s2pte_dbm(pte); +#endif if (!kvm_s2pte_readonly(pte)) kvm_set_s2pte_readonly(pte); } @@ -1827,7 +1831,15 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, ret = stage2_set_pmd_huge(kvm, memcache, fault_ipa, &new_pmd); } else { - pte_t new_pte = kvm_pfn_pte(pfn, mem_type); + pte_t new_pte; + +#ifdef CONFIG_ARM64_HW_AFDBM + if (kvm_hw_dbm_enabled() && + pgprot_val(mem_type) == pgprot_val(PAGE_S2)) { + mem_type = PAGE_S2_DBM; + } +#endif + new_pte = kvm_pfn_pte(pfn, mem_type); if (writable) { new_pte = kvm_s2pte_mkwrite(new_pte); -- 2.19.1