Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3802098pxb; Tue, 26 Jan 2021 05:18:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4xb/ii3+UzeaP673/fATNONX/S9IOBWivFBQ6CgfQg6hLtWzELqvABLhtmISGeroMjuOk X-Received: by 2002:a17:906:3685:: with SMTP id a5mr3305888ejc.544.1611667136951; Tue, 26 Jan 2021 05:18:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611667136; cv=none; d=google.com; s=arc-20160816; b=0O3NJC/r/Es7NF1bqpXHG2JLpnFkDvjwgwl9hT9OjpHNfnMTkM2PNWmq0LV11Va+oO zMYOEawHAYG1zzS7jmJefghES+2cMuVw9ZG2XxliYaVlStrAzaRMeWD4hlDr4g7dJI4Q G8u/3utmB7V5u37Qig0brs0hLHl2YNPjlm57BN9Oa3zqkzX/Fby5opkzgW6unG4Um93n xwSrhzqW6cCVkdJ3AzITJYzwSKiU7au0f91uDoj5Cn1nJbDUNYiGxQXrG52+N1J0H4Bc RdSvFAlhTqr4mPatl5n2thkgU51Wdrp+lG2Flybzj2WHZhOU/QESvOS+k5vKL6czY8M6 zFuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=U+OOvEhOv2rSV6eltKmxAAzJnT6SumnW80jfCbS+EtI=; b=k2sRkdpB4oKw0d2TA7GcsXsaN94MuByzhBHFvE0C4mkDoirNvNBhzXoP3RIhZsraGI kg71BzbuX0z4dqjf/ViDndmDPUI/LUyy7P84sRSmXj5mpMgQ02s2d24ITny8DIIjpzVV R1+cLfnqMuhcz41NsTXvH0o3Rlt2FhhjquJMNbzo9y/0xa2qGmjkIt00nRiu4V46CKBn ES0tESy/mRHxs5wq8ROrDNKKWAv84Y7Q8HPOlYpoulx7xnWWNOoUs9saacOjTxNYYhnJ yqJAuhyyeBGsuyn+eO8LyA2GqjWdj9XL6W4hP6Nc4MvNvwtFxY0tWFieSCKyl4YRf2mp N3ig== 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 g1si3843180ejf.121.2021.01.26.05.18.32; Tue, 26 Jan 2021 05:18:56 -0800 (PST) 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 S2391856AbhAZNQL (ORCPT + 99 others); Tue, 26 Jan 2021 08:16:11 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11509 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391849AbhAZMrN (ORCPT ); Tue, 26 Jan 2021 07:47:13 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DQ5yX0p1NzjDQL; Tue, 26 Jan 2021 20:44:04 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Tue, 26 Jan 2021 20:45:06 +0800 From: Keqian Zhu To: , , , , Marc Zyngier , Will Deacon , Catalin Marinas CC: Alex Williamson , Kirti Wankhede , Cornelia Huck , Mark Rutland , James Morse , Robin Murphy , Suzuki K Poulose , , , , , Subject: [RFC PATCH 6/7] kvm: arm64: Only write protect selected PTE Date: Tue, 26 Jan 2021 20:44:43 +0800 Message-ID: <20210126124444.27136-7-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210126124444.27136-1-zhukeqian1@huawei.com> References: <20210126124444.27136-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function write protects all PTEs between the ffs and fls of mask. There may has unset bit between this range. It works well under pure software dirty log, as software dirty log is not working during this process. But it will unexpectly clear dirty status of PTE when hardware dirty log is enabled. So change it to only write protect selected PTE. Signed-off-by: Keqian Zhu --- arch/arm64/kvm/mmu.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 18717fd12731..2f8c6770a4dc 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -589,10 +589,14 @@ 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; + int rs, re; - stage2_wp_range(&kvm->arch.mmu, start, end); + bitmap_for_each_set_region(&mask, rs, re, 0, BITS_PER_LONG) { + start = (base_gfn + rs) << PAGE_SHIFT; + end = (base_gfn + re) << PAGE_SHIFT; + stage2_wp_range(&kvm->arch.mmu, start, end); + } } /* -- 2.19.1