Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2309910ybt; Tue, 16 Jun 2020 02:40:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzd33v3/sp9WLzFy0LFUWQrtDMXQCJ1t4nl9VPInrwd/YhLKOe5dpz+VE9LAsIkkpss+uad X-Received: by 2002:a17:906:aec5:: with SMTP id me5mr2069340ejb.54.1592300427153; Tue, 16 Jun 2020 02:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592300427; cv=none; d=google.com; s=arc-20160816; b=0Eo5e+YonaWWixqxfEVr9Oi4vX1CfynP/1UyBR/CoX3ADHLVX2gWwR+xSxLfFMau2X c3QK8BN1jIV7WHpku4/W/DNp9QhDw8F/iassu5KrAKhD9iOzy1WUGyXQMANGwLfFQ/Ga oV+q4ipnVPFBcgMQEotNkNCiKhjfj0Wc5u9h4V98uNZTezqhXNMkY/qliwglCRj1fw1D FG9nO1mAP7ISAaddpegnVCJIk4yJtuGs24Hq7zw5HxtfudIYKUI2WWmtjZFzUiT9iJtK dtDuDzvVSAGIzkRjQv0KwCeMbuAIdhbnf4rPxpITb1myw81pzRjZSUz9LbNUG7Lxq2Dl fi8g== 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=LoUeq5fA7N8LHJmYqlNjvc3BfWhSKvfHO3n0M0u9z5o=; b=VIaSLqQ8KUTzwU9M0BCmWa5Y4jWLBWjw8Afs4mdR5WB1yIVx3PfCvvRpKV+ijNix47 o0THtfSl5QWNTetzsuwtQFVZIwH4DHu4BfYQaoWv97pMzRccM1erH3kVPbHNWtVTOQE7 zJvWMuG5KVyEH9idAHD7n5acbLyqaHRm6aQ5//Mr9DPeB6vX2zvTTHpZAmMpu7sSVAlz alvVNrwkE3CfAbsOUMlqXIUdgLRd1tOp3F9oWsuFDaysIbJhFEmV6UmJkBfr4GGHYkvi GK8XDJSo69IDFg7KbdIbN//+iFOZ6bRnF+x4jULWKagFkImAqqNnuQ4MzXqHJzuzKTMF 9aWA== 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 h21si10324215edv.274.2020.06.16.02.40.04; Tue, 16 Jun 2020 02:40:27 -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 S1727837AbgFPJh1 (ORCPT + 99 others); Tue, 16 Jun 2020 05:37:27 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6336 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726099AbgFPJgR (ORCPT ); Tue, 16 Jun 2020 05:36:17 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A7F67EB29739727ABAE9; Tue, 16 Jun 2020 17:36:13 +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:07 +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 05/12] KVM: arm64: Add KVM_CAP_ARM_HW_DIRTY_LOG capability Date: Tue, 16 Jun 2020 17:35:46 +0800 Message-ID: <20200616093553.27512-6-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 For that using arm64 DBM to log dirty pages has the side effect of long time dirty log sync, we should give userspace opportunity to enable or disable this feature, to realize some policy. Signed-off-by: Keqian Zhu --- arch/arm64/include/asm/kvm_host.h | 7 +++++++ arch/arm64/kvm/arm.c | 10 ++++++++++ arch/arm64/kvm/reset.c | 5 +++++ include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + 5 files changed, 24 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 9ea2dcfd609c..2bc3256759e3 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -95,6 +95,13 @@ struct kvm_arch { * supported. */ bool return_nisv_io_abort_to_user; + + /* + * Use hardware management of dirty status (DBM) to log dirty pages. + * Userspace can enable this feature if KVM_CAP_ARM_HW_DIRTY_LOG is + * supported. + */ + bool hw_dirty_log; }; #define KVM_NR_MEM_OBJS 40 diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 90cb90561446..850cc5cbc6f0 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -87,6 +87,16 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, r = 0; kvm->arch.return_nisv_io_abort_to_user = true; break; +#ifdef CONFIG_ARM64_HW_AFDBM + case KVM_CAP_ARM_HW_DIRTY_LOG: + if ((cap->args[0] & ~1) || !kvm_hw_dbm_enabled()) { + r = -EINVAL; + } else { + r = 0; + kvm->arch.hw_dirty_log = cap->args[0]; + } + break; +#endif default: r = -EINVAL; break; diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index d3b209023727..52bb801c9b2c 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -83,6 +83,11 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext) r = has_vhe() && system_supports_address_auth() && system_supports_generic_auth(); break; +#ifdef CONFIG_ARM64_HW_AFDBM + case KVM_CAP_ARM_HW_DIRTY_LOG: + r = kvm_hw_dbm_enabled(); + break; +#endif /* CONFIG_ARM64_HW_AFDBM */ default: r = 0; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 4fdf30316582..e0b12c43397b 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1031,6 +1031,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PPC_SECURE_GUEST 181 #define KVM_CAP_HALT_POLL 182 #define KVM_CAP_ASYNC_PF_INT 183 +#define KVM_CAP_ARM_HW_DIRTY_LOG 184 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h index fdd632c833b4..53908a8881a4 100644 --- a/tools/include/uapi/linux/kvm.h +++ b/tools/include/uapi/linux/kvm.h @@ -1017,6 +1017,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_VCPU_RESETS 179 #define KVM_CAP_S390_PROTECTED 180 #define KVM_CAP_PPC_SECURE_GUEST 181 +#define KVM_CAP_ARM_HW_DIRTY_LOG 184 #ifdef KVM_CAP_IRQ_ROUTING -- 2.19.1