Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2310714ybt; Tue, 16 Jun 2020 02:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx11CcXurGNntq+pMk2/FCcL3GRwrJMm0R35J48PFh8F3tszjfQXuksQ9mwrahvWunNAL1+ X-Received: by 2002:a17:906:7c57:: with SMTP id g23mr1779194ejp.299.1592300525681; Tue, 16 Jun 2020 02:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592300525; cv=none; d=google.com; s=arc-20160816; b=U7Bh/ud8ct1z5zr2fTs4VjVwI1hoyuzEGg/rsd3CJCMXBCuDCK/oMOBo+t7xST72QN aGQu+XYk/pakYO7wp+Po1a7JnIboRSDkDbkGTh0t6iUO0xMqN358Y4qVQMFfIiv9/0mp AvgMk4doADciIdnGLB8Q6AYmbx81tDJVkBhxgarlR/Rx56dHOOGFChx0t/yGDCnT+9AR BdXOwDmOwf/wtG/B0MxtihCU86vbBOPnzSBdC0WR3gJJ4YmaKFSrkJj4IRFhd5LNaA4X OW++4yt+NEGcs5fh6gAbuia26QUSccn8feYVf1o8JiXvdRF8LACbX5iERDQrbp35PUUE kv/g== 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=o8paBzvvjmy9bEQlPJb4UdUaTDfvRvR2rEcPvsIWzOA=; b=IsEkUEeFOK3QdPG0tz/9uR9F/XM2gzuj9rXZoL9xHUQnqcyPIjchWiL5RMyryKTAx2 sJfhv7zjW4K8CbwMm9C4ouJt3M4W82uam4Ftc2Ky2q/kukuK6tnR1b3RMGzpmuBQlGrb ubRyE0KgE2YwPX6kV+TcOw0dlwnIfnVzkDop4Jna0dSnAV+XblO3K3tsI64ovpWG4+Mt d3+MATr+d0FYcmYNK26L+V6/o/aycZVueNlQPmFXARIu/EJAAVat44AwgEIq2VKk1wiy mOe5lDCqq8UhUlGcgrcf+Ou1DsH62DAQP5q52wyAzrYU/TFP92K387ZZ0CtSUnEW19RF 8KKQ== 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 t4si9903825eds.217.2020.06.16.02.41.43; Tue, 16 Jun 2020 02:42:05 -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 S1728522AbgFPJg5 (ORCPT + 99 others); Tue, 16 Jun 2020 05:36:57 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6265 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728332AbgFPJgV (ORCPT ); Tue, 16 Jun 2020 05:36:21 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id CB61C6A3FCE268A0B19E; 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:11 +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 09/12] KVM: arm64: Steply write protect page table by mask bit Date: Tue, 16 Jun 2020 17:35:50 +0800 Message-ID: <20200616093553.27512-10-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 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 --- 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 3aa0303d83f0..898e272a2c07 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1710,10 +1710,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