Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp3087803pxy; Wed, 4 Aug 2021 01:52:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8Vh1mY+4pKJBWvVSPPjov/jbzJPPIxsshBgSIdm0388xo9XID/1BFCYDxLD6eRnd5MdaE X-Received: by 2002:a05:6402:648:: with SMTP id u8mr25011473edx.162.1628067163185; Wed, 04 Aug 2021 01:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628067163; cv=none; d=google.com; s=arc-20160816; b=U+SP8zN06AUehTEQHvvaWY6K5wABrUl6hJBLH4smAsEm0rgRhKTWg/0Etfz2ft0fHo ypp/FsnU+4+ZSD30jh9SDnHe4v49im38OovXTkKUyJdtu6ZiGcqostJyAtzXR1ZWhwWa 7QZ/Cx2JOT2a6TEUtjkBJz+pIIUK5MJszRhJFvSgFBYwC28p77kZ3w7NBd8rysLWYKOR RVQl1Hyi47UFxcM1XN2Af91l+eA5oGuIZmYTKfkmRqkq1JKA1xB3v8OHCpBsKZ5frFiW lW9z53psFozPQWwvzw6QosU9IeBrYsuoAW5AJgha7s5v2q31dNFBA73IPfLLBDKx6vN/ 8WRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XNEs/6yr9b8hBQJj2GN/2tEZCeGoJUsw90alOL/69is=; b=OFW1k1XYo2lhdFFDOMqnqjALTwuLcurvRnx1nuLfo+PwbmAeiEbdRhEgcJFQYazX9c jC1S73LCw5qiSP/7EsZ/MZgRVZXA44lavckUkNRNyE9FBfpjBwKs9DeYqUircyp1l7je WMAmXs/kCvuPmwP+MBuLOZzP53Efal/+gliJVSf60zOhL/jKIKDDGix6BH5whmIgya7Q 2tl/xGvzyiRGonmwhof8Ssh1vtYnlmuWZmjbWI2HzGM7dtYd0tggTIRq7CKtf5zgaEOM UtukAzUvpaHSjRUhFYDpy5y0QEEYvlPVtBGbM54x8jRg2VR/EaOfTlXaqO+swyavcka1 RUQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=MRfa7s2F; 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 k16si1635685edo.475.2021.08.04.01.52.19; Wed, 04 Aug 2021 01:52:43 -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=MRfa7s2F; 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 S235487AbhHDHRW (ORCPT + 99 others); Wed, 4 Aug 2021 03:17:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235219AbhHDHRV (ORCPT ); Wed, 4 Aug 2021 03:17:21 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F51DC0613D5 for ; Wed, 4 Aug 2021 00:17:09 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id h13so1070100wrp.1 for ; Wed, 04 Aug 2021 00:17:09 -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=XNEs/6yr9b8hBQJj2GN/2tEZCeGoJUsw90alOL/69is=; b=MRfa7s2FlqWOZN1LdWG9uuA2LDK4JWa35Hl4QjcgjFTI6pryHaQWkcpUdTW9ls6cUh wU/tM9FUyC5q4Hs7TpxT5/kRxdkcJUp0QgLu0QMLU/TgjjYbGEPjBeVJCu2aybz6/x96 P9wN8SKOi+yNj2hmcKkKnxLElr+ajPmy36P9Ldz2zFvolMi/qlmLZ2MF8bCYsvWHjVyW ASZLShSWvUGBBklIwdSJ+VhMMOhjx90ZrUk96mRak3VNf9bIg5yTfwgrahOH9QD/GWAr bICzY7dttw78c8vG73H8QPTvHElx6JB5fryzSD0RL5eoWWk/sogoyswO5lF/haQ8gwu1 A8Ew== 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=XNEs/6yr9b8hBQJj2GN/2tEZCeGoJUsw90alOL/69is=; b=KIiIyqF8qQ1tumcYxv8qCx2kmMu0y+hFX0k+rxX5JbHaz7yRHlvYerfnKCmSaiIYcZ J85AHmhZLLS7tkdozVAPvFyp0E/iznmBWmBn7g7xowOrDwuyYwPrfnQ5OmDTavCe3yyV 3H1NjRUdSQeeIkSsmJoYruZRrKxKkI8SG3QPcTi8mX+NnCBne6lss8eMvuT/1X4cfqBs XzYuaI6q8SmK5r21y8/5MQcJWUGbtjVwS/FLnL3S5QJ2/k/n+u/7Y0O0etPD3XFplnJe O+vOzkOhOYWPwPym3mWRi5ZxpAXaHXdf2LopVCLjXMv1n/mJE3OaciSJFTYQ6xUaUCPL Z57g== X-Gm-Message-State: AOAM533yYY5YnviiSW2VkxujiQuPnWvURifKSJ0dfQteUKMqsP4L1PWm 92OlI75CmUvZ8gDm34LXSQNCAfpZlnuU3agUnQjnGQ== X-Received: by 2002:a5d:640f:: with SMTP id z15mr27704351wru.325.1628061427914; Wed, 04 Aug 2021 00:17:07 -0700 (PDT) MIME-Version: 1.0 References: <20210727055450.2742868-1-anup.patel@wdc.com> <20210727055450.2742868-12-anup.patel@wdc.com> <38734ad1008a46169dcd89e1ded9ac62@huawei.com> In-Reply-To: <38734ad1008a46169dcd89e1ded9ac62@huawei.com> From: Anup Patel Date: Wed, 4 Aug 2021 12:46:20 +0530 Message-ID: Subject: Re: [PATCH v19 11/17] RISC-V: KVM: Implement MMU notifiers To: "limingwang (A)" Cc: Anup Patel , Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Albert Ou , Paolo Bonzini , Alexander Graf , Atish Patra , Alistair Francis , Damien Le Moal , "kvm@vger.kernel.org" , "kvm-riscv@lists.infradead.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 3, 2021 at 6:49 PM limingwang (A) wrote: > > > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index > > fa9a4f9b9542..4b294113c63b 100644 > > --- a/arch/riscv/kvm/mmu.c > > +++ b/arch/riscv/kvm/mmu.c > > @@ -300,7 +300,8 @@ static void stage2_op_pte(struct kvm *kvm, gpa_t > > addr, > > } > > } > > > > -static void stage2_unmap_range(struct kvm *kvm, gpa_t start, gpa_t size) > > +static void stage2_unmap_range(struct kvm *kvm, gpa_t start, > > + gpa_t size, bool may_block) > > { > > int ret; > > pte_t *ptep; > > @@ -325,6 +326,13 @@ static void stage2_unmap_range(struct kvm *kvm, > > gpa_t start, gpa_t size) > > > > next: > > addr += page_size; > > + > > + /* > > + * If the range is too large, release the kvm->mmu_lock > > + * to prevent starvation and lockup detector warnings. > > + */ > > + if (may_block && addr < end) > > + cond_resched_lock(&kvm->mmu_lock); > > } > > } > > > > @@ -405,7 +413,6 @@ static int stage2_ioremap(struct kvm *kvm, gpa_t gpa, > > phys_addr_t hpa, > > out: > > stage2_cache_flush(&pcache); > > return ret; > > - > > } > > > > void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, @@ > > -547,7 +554,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > > spin_lock(&kvm->mmu_lock); > > if (ret) > > stage2_unmap_range(kvm, mem->guest_phys_addr, > > - mem->memory_size); > > + mem->memory_size, false); > > spin_unlock(&kvm->mmu_lock); > > > > out: > > @@ -555,6 +562,73 @@ int kvm_arch_prepare_memory_region(struct kvm > > *kvm, > > return ret; > > } > > > > +bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range) > > +{ > > + if (!kvm->arch.pgd) > > + return 0; > > + > > + stage2_unmap_range(kvm, range->start << PAGE_SHIFT, > > + (range->end - range->start) << PAGE_SHIFT, > > + range->may_block); > > + return 0; > > +} > > + > > +bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_range *range) { > > + int ret; > > + kvm_pfn_t pfn = pte_pfn(range->pte); > > + > > + if (!kvm->arch.pgd) > > + return 0; > > + > > + WARN_ON(range->end - range->start != 1); > > + > > + ret = stage2_map_page(kvm, NULL, range->start << PAGE_SHIFT, > > + __pfn_to_phys(pfn), PAGE_SIZE, true, true); > > + if (ret) { > > + kvm_err("Failed to map stage2 page (error %d)\n", ret); > > + return 1; > > + } > > Hi, Anup > > I think that it is not appropriate to add kvm_err here, because stage2_set_pte function > may apply for memory based on the pcache parameter. If the value of pcache is NULL, > stage2_set_pte function considers that there is not enough memory and here an invalid > error log is generated. > > As an example, this error log is printed when a VM is migrating. But finally the VM migration > is successful. And if the kvm_err is added to the same position in the ARM architecture, the > same error log is also printed. Okay, I have converted kvm_err() to kvm_debug(). In the future, we can totally remove it as well. Please try riscv_kvm_v20 branch at: https://github.com/avpatel/linux.git Regards, Anup > > Mingwang > > > + return 0; > > +} > > + >