Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp985617ybs; Mon, 25 May 2020 04:27:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP7MwKEtn1OV3061jI/Tt7vAJwoODUUA83guLMPyx9VQbaN64KQjIOJhilz14tZgGKbNS7 X-Received: by 2002:aa7:d8d3:: with SMTP id k19mr14868015eds.348.1590406071524; Mon, 25 May 2020 04:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590406071; cv=none; d=google.com; s=arc-20160816; b=HyJ2TBIKL495ocoLP5e6QrZI4NRsJeOcXuV3IhBPjYWHloBhBy3DRTcF1Fy8Gz99M5 xZvUtU6CkLJaj3VMyXuATF0/o/FxDdGWTVuZxgpgAZHdHCsuG6RXVyH/PC65XHPcvfan 90ur6URWJ35oR9Vdqe1jBmwZ/MBmdst1fFPcLTCOC68M/KWS8jBc6dLD9m9zoUnXIzuQ Ut7bFtgomZ5rqHSoERTq3alvSFDAzqLHseAjPiFEkOHsZaARBCdpMd9AxorX/ilAzFw+ D5V+s47ixuW38MC5O+HVg9wnGP0ZiejBDr2Rt0eyZUHqOwiVUcy17wKyqL7I8YIza3K+ 17aw== 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=n5T1tjzuvZQhijJyrqoBIE85roR1XrnzRGIcjmNEX7k=; b=ZrCCBH+SRXMB4PB/1KPMiTDbSDJrtYWIAk9tZ2korX2NyfpKlCZVMza44/GkdD6kad YaG/4t1e2RC/9c4i7hPs18cLAZgmOeLo7y8Uo4ZoI1r7w4ruINloJ4qjpD0pg1p/CHEi WTfOSSUiq7grT9HG6+s4fgZYGYGl4O0jKT1kLJeNg/Z8K+SgRtt7z/rsR1sYdp8YU2RU NGNTodyheohKV0sQDQZQMC2vu7TZ4b0Wy3cseGZK+Bag4tfmEE1c8AhMsFEeSIylETNx 47WJ++gHYk+sq8y25aTgymxQcmOfjzAaK/rgD6ljd0mIjpw5fac7QaxI8eK93mLW42O4 Kg1A== 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 bo9si8795573edb.433.2020.05.25.04.27.28; Mon, 25 May 2020 04:27:51 -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 S2390213AbgEYLZe (ORCPT + 99 others); Mon, 25 May 2020 07:25:34 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:46934 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390172AbgEYLZR (ORCPT ); Mon, 25 May 2020 07:25:17 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 737446457F0D4572A428; Mon, 25 May 2020 19:25:14 +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:05 +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: [RFC PATCH 4/7] KVM: arm64: Steply write protect page table by mask bit Date: Mon, 25 May 2020 19:24:03 +0800 Message-ID: <20200525112406.28224-5-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 During dirty log clear, page table entries are write protected according to a mask. In the past we write protect all entries corresponding to the mask from ffs to fls. Though there may be zero bits between this range, we are holding the kvm mmu lock so we won't write protect entries that we don't want to. We are about to add support for hardware management of dirty state to arm64, holding kvm mmu lock will be not enough. We should write protect entries steply by mask bit. Signed-off-by: Keqian Zhu --- virt/kvm/arm/mmu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index ff8df9702e04..779859b85d6d 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1568,10 +1568,16 @@ static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, gfn_t gfn_offset, unsigned long mask) { phys_addr_t base_gfn = slot->base_gfn + gfn_offset; - phys_addr_t start = (base_gfn + __ffs(mask)) << PAGE_SHIFT; - phys_addr_t end = (base_gfn + __fls(mask) + 1) << PAGE_SHIFT; + phys_addr_t start, end; + u32 i; - stage2_wp_range(kvm, start, end); + for (i = __ffs(mask); i <= __fls(mask); i++) { + if (test_bit(i, &mask)) { + start = (base_gfn + i) << PAGE_SHIFT; + end = (base_gfn + i + 1) << PAGE_SHIFT; + stage2_wp_range(kvm, start, end); + } + } } /* -- 2.19.1