Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp938822pxa; Thu, 27 Aug 2020 21:55:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3BhuJPQqLhhQEGscuzV0CoA0Q6JXWhVQwC+p18/p0+f3WZs57Y1pOdjiZQmOPusCiwvzf X-Received: by 2002:a50:ba8c:: with SMTP id x12mr64010ede.319.1598590536265; Thu, 27 Aug 2020 21:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598590536; cv=none; d=google.com; s=arc-20160816; b=t19x34l+EW4yDGrigpolwVo4kZMoBCldhIeHP7E+goVK5njv6MwjgCtWfhfr65HMB6 3fgfGEu/Ag30ucxe3qP9KK9QdeISwui03GEjPj+ZgkYuvhjtGC8sZZo1YhaX9eUhqN1Q /O1WipimJOdHq3rg6IBfw+yg/8b4+D2EzrZmIF1MOPSjaOSzGp+p2umxks28UZRZuBtd LhzPuE5XYLdsrBEElbpOLcv6HZtWEWAOK0ZRFo/xcuPUsqtOGF8lzHqQXii2MhIO5RTT +znHiaDqKKlmSKkAgafK5Mifsv0ratvykY7xi3AeQy3pzBh1UPljIDpQrTpewcqpESaX bLxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xCkPRCKVOyv6UdC08SrLjktcyNyR3bWo2BWIKaXwLIU=; b=p2ANiLtaVcIYOiXFlOzkWHrvinq7frcIQwg8A7CfJ/nfBTMvTy71fiHuu456AINKZv iXESqCfqBOQ7HPN8QPf4OKta188sKYm8J2KueF8XGUanCfI5pI9JnC26XSc/JjtK7+jC pK9o9aG+j5hH8OXlJ/clJ4Pz+BmdXWEPeObkU5+rexABaZEqjMiXYc1wnCQNDDHKop+y oTfr7tlgd4c5x0YUFcpWahwDqWofznorx3C5RLHd5QtEf85JGixOku0+tBGnyp6Tcge6 +MCgg2ivTzOALtQ8Flt9LLaewUITiELzkqmrSRem+68FNXZ2THaBpKYdUQKp4qI94yzE AZRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=wzNVuFCj; 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 b23si2777873ejb.465.2020.08.27.21.55.06; Thu, 27 Aug 2020 21:55:36 -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; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=wzNVuFCj; 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 S1726338AbgH1EyG (ORCPT + 99 others); Fri, 28 Aug 2020 00:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbgH1EyG (ORCPT ); Fri, 28 Aug 2020 00:54:06 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98ACCC061264 for ; Thu, 27 Aug 2020 21:54:05 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id z9so46960wmk.1 for ; Thu, 27 Aug 2020 21:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xCkPRCKVOyv6UdC08SrLjktcyNyR3bWo2BWIKaXwLIU=; b=wzNVuFCj/YGjuC6NDV1gHwffImireBFCVYVdrHj0WUr+2vvzYZTAgyeaw28x2dUPbd ShRUHS3rP6pBj/FcTwkdikNlfeGx1bWm7WEKfEBmWiEz88ZxRXe1AW8Kh5Xr3w95ZWOL uEhmg2WHxPEEvrNNBPr3SeykviI0capLfcMCr2WBcnYmQ84GYJYfxoWbI6GtvVjSlMpD 6xi87zx7+KFN+ckqJiXSKbzlyFqWY0+REM6PQJGxTAifwXNGrlEMz+pdRTl7AGAPKNG/ KwjOIJsHc0Opqh3TdvhPlFlqCdC0Dt7M1TzJLiHSACfAwNSWnvbjVieHE0Jndxidt1hH BM6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xCkPRCKVOyv6UdC08SrLjktcyNyR3bWo2BWIKaXwLIU=; b=IW5y9+zQDO3x3G90sH6kuSjJVTTep8CujAvyOTdfx4acVwpp5D/anSDltGK26ClU/Z Xl5s0seZ+zCoCHKBKil4eLne+otid5esxfBIjuNQop9gwubGxNpSLhm9ynRFdnZpnbBf Q6pD0DIBh7qKNRY/cPBHuosiYDuEKC2XitErzycyyKwYHhlhpeAiIeO7DthQsx1EBrwS EzqEmEEL2R73T/IigNFHkEr5VCNMJ4fdXnzkB/tSIdFv+1CEo0uGKYmleDGpudOQ8t4m eX4YnI91aNxBJNz4SUXuI0xptYdEE1LQO9SNvPT9a3Duhy0CzjnWV1/4XRXpYnGR16sR etzg== X-Gm-Message-State: AOAM532UHnxUCcqAkuNCDUNhsMkFXs48GU75PWufJUYfdpkeFSXqiHif WiX3jFOtDaCeDHMDjC5rVRLRcy9g8Dks85b1+CBMdQ== X-Received: by 2002:a1c:1b17:: with SMTP id b23mr101507wmb.152.1598590444059; Thu, 27 Aug 2020 21:54:04 -0700 (PDT) MIME-Version: 1.0 References: <20200827082251.1591-1-jiangyifei@huawei.com> <20200827082251.1591-3-jiangyifei@huawei.com> In-Reply-To: <20200827082251.1591-3-jiangyifei@huawei.com> From: Anup Patel Date: Fri, 28 Aug 2020 10:23:52 +0530 Message-ID: Subject: Re: [PATCH RFC 2/2] target/kvm: Add interfaces needed for log dirty To: Yifei Jiang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Alistair Francis , Atish Patra , deepa.kernel@gmail.com, kvm-riscv@lists.infradead.org, KVM General , linux-riscv , "linux-kernel@vger.kernel.org List" , "Zhangxiaofeng (F)" , wu.wubin@huawei.com, Zhanghailiang , "dengkai (A)" , yinyipeng Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 27, 2020 at 1:54 PM Yifei Jiang wrote: > > 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 > > I already have a similar change as part of v14 KVM RISC-V series. Let us coordinate better. Please let us know in-advance for any KVM RISC-V feature you plan to work on. Otherwise, this leads to efforts wasted at your end or at our end. Regards, Anup