Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2310538ybt; Tue, 16 Jun 2020 02:41:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHVaroeQgaeMFKT2VlrX/1EXWOfz96ioqt9iLVX8CcXuXcoAkXOhYqfo3EmV92wcLEpWbQ X-Received: by 2002:a17:907:9495:: with SMTP id dm21mr1883908ejc.357.1592300501619; Tue, 16 Jun 2020 02:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592300501; cv=none; d=google.com; s=arc-20160816; b=p+F4j3Dj/h57MsgbhEyne2ddEcC6+yf+n+fWOOnWVgpfA/GML4XUknV1/cQopDBHK3 HfZUy30OUudwSpcF1uhsh5QNSt/uvwgvJtAspbVrrtC1M/F5xY856VXUXcZHt7UZzBv0 +JwBq2R37gQFNpHQEnJeO2031V9tMKjo/SCZso1n5BWJCi00VTqklNog4A4Yp19i7vOr 7YwUTl6XZW7NjYiaWiyXENe66LroBRQOyWRdGp00yLa4GCr6QW7TLlMsmtW6z7oUlz6j vHVb6oJgI03+iSuyV6sKzqpfmXSD7SutwxuvW1mcaNgVamPv0TNLUV1d+g3Fouw8kkb4 L9UA== 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=kkiel1QCAa/In184dsM2f6+tjKaT3cy3BRO95KHKhzI=; b=Gm3N6UzdB9EvHSpkFiDt4QrqfNkv6+ul+sh16NOnXgjL1fGj6N7g9KOK6PPcFpGyfr oN+bT38LZ8tvmcZQYpZXOKpYbng0VBBecQ1RsjdmJyejLYYyWmO8jDPtP4vlbe8tgqzs bRscyVTeGtZz/RXHvTynTG7utWFJMRUtvKXcNNf916/YmvrIbuB+AIFgsYjOjdPn11Ev cmN7XCzuyH9qtAyNS9mlUe+OVC1PoF/kK8QMFuT6GMBsmJaBqLXxfMytzHiHiM72AKoJ 5mkYVDIZQtIGQc7Mq6LdwiC9T6yO8FiOIX87ry8gzWiYrnIJOtrWclkixPoit4udOscW aEQg== 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 z4si10068150ejj.723.2020.06.16.02.41.19; Tue, 16 Jun 2020 02:41: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 S1728553AbgFPJg7 (ORCPT + 99 others); Tue, 16 Jun 2020 05:36:59 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:47332 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728240AbgFPJgV (ORCPT ); Tue, 16 Jun 2020 05:36:21 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id AD27B10AC27B32B7709B; Tue, 16 Jun 2020 17:36:18 +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:08 +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 06/12] KVM: arm64: Set DBM bit of PTEs during write protecting Date: Tue, 16 Jun 2020 17:35:47 +0800 Message-ID: <20200616093553.27512-7-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 During write protecting PTEs, if hardware dirty log is enabled, set the DBM bit of PTEs when they are *already writable*. This ensures some mechanisms that rely on "write fault", such as CoW, are not broken. Signed-off-by: Keqian Zhu Signed-off-by: Peng Liang --- arch/arm64/kvm/mmu.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index f08b0fbca0a0..742c7943176f 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1536,19 +1536,24 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, /** * stage2_wp_ptes - write protect PMD range + * @kvm: kvm instance for the VM * @pmd: pointer to pmd entry * @addr: range start address * @end: range end address */ -static void stage2_wp_ptes(pmd_t *pmd, phys_addr_t addr, phys_addr_t end) +static void stage2_wp_ptes(struct kvm *kvm, pmd_t *pmd, + phys_addr_t addr, phys_addr_t end) { pte_t *pte; pte = pte_offset_kernel(pmd, addr); do { - if (!pte_none(*pte)) { - if (!kvm_s2pte_readonly(pte)) - kvm_set_s2pte_readonly(pte); + if (!pte_none(*pte) && !kvm_s2pte_readonly(pte)) { +#ifdef CONFIG_ARM64_HW_AFDBM + if (kvm->arch.hw_dirty_log && !kvm_s2pte_dbm(pte)) + kvm_set_s2pte_dbm(pte); +#endif + kvm_set_s2pte_readonly(pte); } } while (pte++, addr += PAGE_SIZE, addr != end); } @@ -1575,7 +1580,7 @@ static void stage2_wp_pmds(struct kvm *kvm, pud_t *pud, if (!kvm_s2pmd_readonly(pmd)) kvm_set_s2pmd_readonly(pmd); } else { - stage2_wp_ptes(pmd, addr, next); + stage2_wp_ptes(kvm, pmd, addr, next); } } } while (pmd++, addr = next, addr != end); -- 2.19.1