Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1496304ybt; Thu, 2 Jul 2020 07:00:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNQLZOjTDpBRByOmCQu75hiwxB4nTuW4QzkGhTXzfVrHaYdrA1x78oGzW5b4/7JM/WMcQr X-Received: by 2002:a05:6402:1766:: with SMTP id da6mr33775403edb.48.1593698442808; Thu, 02 Jul 2020 07:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593698442; cv=none; d=google.com; s=arc-20160816; b=KRmAQywxrGSUDz7c9pQZQcbADcUNV7i5v1VFTLXkqO5Rw3+CXV/Z1MmvoM3MlNODnM juUexnFuuu8hDjqEvnsGTwFlycEmSKegnlfDSTr0ing6t7+5loHeDFlH2LqJu4rDfTxQ FwukxImhAk9Spa6ch/25qIO/Zkbsu6JFDu/qJJtdt1Wu98T1kfQsd1EtdUoYlk9/xrH6 JU9lWcLvg/YqO8BUbbdPUVVQFwUC7wchiCaWfSkmTXLJL+CQR/T4mWbqGGZS4o+mJbQR Fv+wlmngNNp4eQuQXLquavUYGyBmJS6ogpAjFRg8YujxBjK1EmYKQdvlWflKrRsJAVjK nZ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=wOfOAqk0N7vLI8nnEPeth8ndADHRTy+PK7Ilf+qhhFs=; b=jzH3s97cs4XR9NXTDkwWYkaPc5oN8T8WY1DR6Mig8vb6OITX/eBEStjaBqwIYfanRy IIleuM7aFL53DqHY9dpKxYm52WtcNI+K1hAHH9NYcdn6tN5y4mS3GTiRMH5XNd+XsRPp ddgQhsvfSOGg1tDRfjF55qfWSOJXhS8uASKeSNg3k/W8a7vu6cG9EhPoMuSf7kDPcRHj 8NquWnJ9zVQIyAHGEjC2jSEG9g9fWiGjYd8kuCDrDq16UDerQBknqDrlNFND7MBCpWQn O87NYoDBO9IktdiLfvxiaX9MNnvHTzt5oCVjtUyHMwvA5K9n9iJiNbKEsNjsvhmSERri n5hA== 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 t10si5919706ejs.137.2020.07.02.07.00.19; Thu, 02 Jul 2020 07:00:42 -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 S1729591AbgGBN5R (ORCPT + 99 others); Thu, 2 Jul 2020 09:57:17 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7354 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729263AbgGBN5K (ORCPT ); Thu, 2 Jul 2020 09:57:10 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 913E96BE24CEBCEA50BE; Thu, 2 Jul 2020 21:56:10 +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:00 +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 0/8] KVM: arm64: Support HW dirty log based on DBM Date: Thu, 2 Jul 2020 21:55:48 +0800 Message-ID: <20200702135556.36896-1-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 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 This patch series add support for dirty log based on HW DBM. It works well under some migration test cases, including VM with 4K pages or 2M THP. I checked the SHA256 hash digest of all memory and they keep same for source VM and destination VM, which means no dirty pages is missed under hardware DBM. Some key points: 1. Only support hardware updates of dirty status for PTEs. PMDs and PUDs are not involved for now. 2. About *performance*: In RFC patch, I have mentioned that for every 64GB memory, KVM consumes about 40ms to scan all PTEs to collect dirty log. This patch solves this problem through two ways: HW/SW dynamic switch and Multi-core offload. HW/SW dynamic switch: Give userspace right to enable/disable hw dirty log. This adds a new KVM cap named KVM_CAP_ARM_HW_DIRTY_LOG. We can achieve this by change the kvm->arch.vtcr value and kick vCPUs out to reload this value to VCTR_EL2. Then userspace can enable hw dirty log at the begining and disable it when dirty pages is little and about to stop VM, so VM downtime is not affected. Multi-core offload: Offload the PT scanning workload to multi-core can greatly reduce scanning time. To promise we can complete in time, I use smp_call_fuction to realize this policy, which utilize IPI to dispatch workload to other CPUs. Under 128U Kunpeng 920 platform, it just takes about 5ms to scan PTs of 256 RAM (use mempress and almost all PTs have been established). And We dispatch workload iterately (every CPU just scan PTs of 512M RAM for each iteration), so it won't affect physical CPUs seriously. 3. About correctness: Only add DBM bit when PTE is already writable, so we still have readonly PTE and some mechanisms which rely on readonly PTs are not broken. 4. About PTs modification races: There are two kinds of PTs modification. The first is adding or clearing specific bit, such as AF or RW. All these operations have been converted to be atomic, avoid covering dirty status set by hardware. The second is replacement, such as PTEs unmapping or changement. All these operations will invoke kvm_set_pte finally. kvm_set_pte have been converted to be atomic and we save the dirty status to underlying bitmap if dirty status is coverred. Change log: v2: - Address Steven's comments. - Add support of parallel dirty log sync. - Simplify and merge patches of v1. v1: - Address Catalin's comments. Keqian Zhu (8): KVM: arm64: Set DBM bit for writable PTEs KVM: arm64: Scan PTEs to sync dirty log KVM: arm64: Modify stage2 young mechanism to support hw DBM KVM: arm64: Save stage2 PTE dirty status if it is covered KVM: arm64: Steply write protect page table by mask bit KVM: arm64: Add KVM_CAP_ARM_HW_DIRTY_LOG capability KVM: arm64: Sync dirty log parallel KVM: Omit dirty log sync in log clear if initially all set arch/arm64/include/asm/kvm_host.h | 5 + arch/arm64/include/asm/kvm_mmu.h | 43 ++++- arch/arm64/kvm/arm.c | 45 ++++- arch/arm64/kvm/mmu.c | 307 ++++++++++++++++++++++++++++-- arch/arm64/kvm/reset.c | 5 + include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + virt/kvm/kvm_main.c | 3 +- 8 files changed, 389 insertions(+), 21 deletions(-) -- 2.19.1