Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp265697pxa; Thu, 27 Aug 2020 01:25:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLVtdzm7zFJuUYLN3gOPNYqZXmvXScb+4pPUN9EYJy+mdj491BHx/4kjhcz9HVyUMIKqVY X-Received: by 2002:a17:906:1f43:: with SMTP id d3mr13829057ejk.295.1598516741345; Thu, 27 Aug 2020 01:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598516741; cv=none; d=google.com; s=arc-20160816; b=MErmzLkWzNJrs/Oj2H/A+3Xsg1jE2Ji90U82IMaoHcVfcmS70kQ6Rap9hReUdUKlKG eqbmOeFCzHOp2qOaIL06B/y2ez3wR3mFAF825JtumVR56TkB4u0hedH8hq/bJ/GU1U2N sEGDTUwWwuuzuHo1cF1MJ3R9SRFsFAMnMNwZHJu7FrotgewrqAg+D8DBKaVENbu2dCKU IuFusQhN+ofkiCd9aXpjXhlJMStwx9HKP4J03yP/P4KHzYiPjI6xQekd/4AXMulmuYoo 2xdXSqx8AKCVFVkveQd6KaHv+MNr/AT4mqB//8+WgpRmPdF4+d+qtSmQ7zaN6EPGznLY 6QDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=mUlukQd6UnUm2kk4wZcfQXr7kJJOyYsG9Lf6NG29eZY=; b=c0oaqpdxlYMyqLouDBZXQ3WufJET9so/Py6tPLmQrWsvqrW5dJ42sUCY60g4aRw/OX GNebxFGW+KzuAZJ760y25h8rrTzzFFxHuaMoSHhB5xo8TTqI5n/K+w8VLyp9hU29dMRG pCirfvqE+p+glEchnMAGmF7SeNXSpRLEhDm2U8qAXa8IyO83FUz84UMhi1nR1FWiG+9w wi0q7yhEEB5fbAEpNw4u1ntuxYTN6ddww2EZK20rFH/ElS74DAtgkpQhPX7ffttAvYTw 3PeoX8wx2tftlKF8xaex1ue6QB1+37uZ9nD6kCDPaUYNjmmkBhofcZDSJlwtyv4oMYu9 DD2Q== 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 df28si1007999edb.550.2020.08.27.01.25.18; Thu, 27 Aug 2020 01:25:41 -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 S1728327AbgH0IYC (ORCPT + 99 others); Thu, 27 Aug 2020 04:24:02 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:45902 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726395AbgH0IXz (ORCPT ); Thu, 27 Aug 2020 04:23:55 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6EE67404E57DEB67FD5B; Thu, 27 Aug 2020 16:23:53 +0800 (CST) Received: from huawei.com (10.174.187.31) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Thu, 27 Aug 2020 16:23:43 +0800 From: Yifei Jiang To: , , , , , , CC: , , , , , , , , , Yifei Jiang Subject: [PATCH RFC 2/2] target/kvm: Add interfaces needed for log dirty Date: Thu, 27 Aug 2020 16:22:51 +0800 Message-ID: <20200827082251.1591-3-jiangyifei@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20200827082251.1591-1-jiangyifei@huawei.com> References: <20200827082251.1591-1-jiangyifei@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Originating-IP: [10.174.187.31] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add two interfaces of log dirty for kvm_main.c, and detele the interface kvm_vm_ioctl_get_dirty_log which is redundantly defined. CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT is added in defconfig. Signed-off-by: Yifei Jiang Signed-off-by: Yipeng Yin --- arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/mmu.c | 43 ++++++++++++++++++++++++++++++++++++ arch/riscv/kvm/vm.c | 6 ----- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index d36e1000bbd3..857d799672c2 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -19,6 +19,7 @@ CONFIG_SOC_VIRT=y CONFIG_SMP=y CONFIG_VIRTUALIZATION=y CONFIG_KVM=y +CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y CONFIG_HOTPLUG_CPU=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index 2356dc52ebb3..91fcffc70e5d 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -26,6 +26,7 @@ config KVM select KVM_MMIO select HAVE_KVM_VCPU_ASYNC_IOCTL select SRCU + select KVM_GENERIC_DIRTYLOG_READ_PROTECT help Support hosting virtualized guest machines. diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 88bce80ee983..df2a470c25e4 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -358,6 +358,43 @@ void stage2_wp_memory_region(struct kvm *kvm, int slot) kvm_flush_remote_tlbs(kvm); } +/** + * kvm_mmu_write_protect_pt_masked() - write protect dirty pages + * @kvm: The KVM pointer + * @slot: The memory slot associated with mask + * @gfn_offset: The gfn offset in memory slot + * @mask: The mask of dirty pages at offset 'gfn_offset' in this memory + * slot to be write protected + * + * Walks bits set in mask write protects the associated pte's. Caller must + * acquire kvm_mmu_lock. + */ +static void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, + struct kvm_memory_slot *slot, + 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; + + stage2_wp_range(kvm, start, end); +} + +/* + * kvm_arch_mmu_enable_log_dirty_pt_masked - enable dirty logging for selected + * dirty pages. + * + * It calls kvm_mmu_write_protect_pt_masked to write protect selected pages to + * enable dirty logging for them. + */ +void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn_offset, unsigned long mask) +{ + kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); +} + + int stage2_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa, unsigned long size, bool writable) { @@ -433,6 +470,12 @@ void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot) { } +void kvm_arch_flush_remote_tlbs_memslot(struct kvm *kvm, + struct kvm_memory_slot *memslot) +{ + kvm_flush_remote_tlbs(kvm); +} + void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free) { } diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 4f2498198cb5..f7405676903b 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -12,12 +12,6 @@ #include #include -int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) -{ - /* TODO: To be added later. */ - return -ENOTSUPP; -} - int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { int r; -- 2.19.1