Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1495115ybt; Thu, 2 Jul 2020 06:59:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHjPPBRPgEHS24CYa0ESjrbfaBUo61FzzRs8ztxUHWxcMTp0leQgS2Gd96dLf6wv4LyLsy X-Received: by 2002:a17:906:2b12:: with SMTP id a18mr27268505ejg.186.1593698341403; Thu, 02 Jul 2020 06:59:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593698341; cv=none; d=google.com; s=arc-20160816; b=Ek4Q6WjGymQLEu/vifhWeVWwC1Y8Vufy3FcJ0xryquMDLpt4L18LF57sZLF8zhagKJ SiqNdBQKXZPkfewXwteVJG9E4qRy7Frrr/qfp6a4OCeuvYUGeWH6uAP3GZANHo2MwRmk YgaJYKgd45t/1vCd8NNTqHyD/58A+CcwX6vSY3dqvX5Xf/eFp+cCWG9+E22PvXPtzS5D rRokq0nTRdR5vweSsh+L6Y45VSdGb/ot0qHrgyJXkRoO9iHpHgFVv/DaAZrCw6OtO9F9 nuaD8Qxoarl69AfsPAbqNoHEcMUKqmQtKJaF29L8YfwSkhUBcwbY8JOx7yp9rwDY489z AEww== 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=Di87jO57ttS7NAcp+0fFciNWdEmFGS6oIPb0VwJHNS0=; b=P2mPWPCFjuX3LxZHnLoN00BoNiIbV09ZBrJ1o8ZBepvnh1AtbALIu88j8BobTWm4Uu CnxhfHntufe22kHgjmACXOM56Z4n8MYvT7FXlDgyhOQ4QDPWIDqN805mlaiFlzjcE78F i3aTGuTM2MrfRxS/6yJ/Pz4oMua56Xl25Tja5pjIU6z3lP1ALRMoEQfJbRx37WjwmbWv MizE3fd3YzK0pZvda/13fs8eo9BryJh7HNNHFKATk/xQ6+rUSyCocIRKC43h4Zge/cbB nxWA9CWUjhd1D1lgE72dn5HHidgVnPfkyW9frP9F8FZLH5P+g4e6XWiRDL3grIiohe7Q tXoQ== 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 bd18si5997314edb.31.2020.07.02.06.58.38; Thu, 02 Jul 2020 06:59:01 -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 S1729572AbgGBN41 (ORCPT + 99 others); Thu, 2 Jul 2020 09:56:27 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:43064 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729473AbgGBN4Z (ORCPT ); Thu, 2 Jul 2020 09:56:25 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8FA50E69E0B83810267D; Thu, 2 Jul 2020 21:56:15 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.22) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Thu, 2 Jul 2020 21:56:05 +0800 From: Keqian Zhu To: , , , CC: Catalin Marinas , Marc Zyngier , James Morse , Will Deacon , "Suzuki K Poulose" , Steven Price , "Sean Christopherson" , Julien Thierry , Mark Brown , "Thomas Gleixner" , Andrew Morton , Alexios Zavras , , , , Keqian Zhu Subject: [PATCH v2 5/8] KVM: arm64: Steply write protect page table by mask bit Date: Thu, 2 Jul 2020 21:55:53 +0800 Message-ID: <20200702135556.36896-6-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20200702135556.36896-1-zhukeqian1@huawei.com> References: <20200702135556.36896-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.22] 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 Signed-off-by: Peng Liang --- arch/arm64/kvm/mmu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d0c34549ef3b..adfa62f1fced 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1703,10 +1703,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_le(i, &mask)) { + start = (base_gfn + i) << PAGE_SHIFT; + end = (base_gfn + i + 1) << PAGE_SHIFT; + stage2_wp_range(kvm, start, end); + } + } } /* -- 2.19.1