Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2940610imw; Sun, 17 Jul 2022 21:30:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+D3TCMRzkLoBu9APUmtOdNuQl2ACVw5qSZrLRyPD+jeAygEg26vXRGTDqXTuSOuWBYygk X-Received: by 2002:a17:90a:fa01:b0:1ef:6e6a:4ff0 with SMTP id cm1-20020a17090afa0100b001ef6e6a4ff0mr29687199pjb.35.1658118613946; Sun, 17 Jul 2022 21:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658118613; cv=none; d=google.com; s=arc-20160816; b=nZpujx87DZmHssHAWm+jpLAsUFK1FCg3nYhE6a6k2j/L/Cl+lvrxuxXyUNwB8rhy3U DKvOYrTHucKEv7mIzIDdx2qiYpHgi1r2YNu37hz0wIPTyOeWHyFBqeXyc4HI6gJdmSVQ d0ZpX6k96V4s9mZAqyl8IqaRyDqRa4q26G03MyQujiIeAjYva+RSt96++MbR7uD9YJi2 hmKGSpNvnoKPkwWEazt7AurpiJDjr89Vlmgj5KowK4jUIt0xqeZub8TFQ0LTMblgYRMo 7W3N/DRjrdI++HiWeG40GqfqplbiM4GKWInKYj12QRP3jCe/VjbayfYiOKGo4HAV68Gv azKA== 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=QqKqAsiuT2ci7oRoFpphbORkfNF9Sqdp2GAmlBxKgV4=; b=XJvfpfFHYWucwVu2cumIvye+SqpFFVMtq2edjVlriaUnJrfOwq1fn+2w2m3s7ylAWt IsvJFGcIwoVMfiEMgAO50+hMYaaBD3pamrTqptnWT8Oppg1k4IhWBESxO0ZgxJmDu/hR FE6NnGgOxTAjDX3IE12D2jBK0ENZYz3CTl4Et72GAxXKSgur4twZnwqRcXWr6h2aBqVZ vhLmWxhXRdtRlI5fd1oBVIiby1L+TZRuBkET0C4hFejWGakXHCfs/TqjAG3xluDRCiZ1 P/tncZ6haA0bS6kHau9HtmLYG/T4HA3Y4dphnauT186wTmQQFyjJtFP3zbvLlv4MhNKk kImA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=k6u7OoZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i69-20020a638748000000b00419facb77dasi6882016pge.151.2022.07.17.21.29.59; Sun, 17 Jul 2022 21:30:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=k6u7OoZn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231346AbiGREHC (ORCPT + 99 others); Mon, 18 Jul 2022 00:07:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiGREHA (ORCPT ); Mon, 18 Jul 2022 00:07:00 -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 D6C8011C35 for ; Sun, 17 Jul 2022 21:06:59 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id r14so15292977wrg.1 for ; Sun, 17 Jul 2022 21:06:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QqKqAsiuT2ci7oRoFpphbORkfNF9Sqdp2GAmlBxKgV4=; b=k6u7OoZnhtF2M0wYb5Ye/+qhGhYm0AWbwVrohe57R7ni8v92EpBP6R6TjsbolXypA1 AahSW2NhR1X7hhjzZjDIVC1DS2dWM5MmBjEby9TCxPFmNmL4Vo+TyrPWxTa0+44/FwmY VjLl3xocn+U42excfVnEy/r1Kc3XhiuwTM3cGalvwKUnyPx9xyXsWSklura+LdvJsnRM WByOWuo2kWAzegVNbvKWRuw/KacEQwRwk0U2mgwy5YlYqR7u7qh1ltkCgYnus6yoYbgU hQTa7H9PdHBRC6Db+cZ9mxT//oY9oKI7poriDZ8xYHHrJ9lOUEVRnBoAaglE3EoiGBTO yI3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QqKqAsiuT2ci7oRoFpphbORkfNF9Sqdp2GAmlBxKgV4=; b=3OIgnHauRa5xvi44mnOt2YCgoVSnRsGL+K7I9sPCXdgU764TIOgUQbCXqQxfmIJ25P Ys6JsK19bdEWChoA+E5oZgo/eRZBx/rINKCoTHJ78NHnDBlKkU4ZcViDUJkEIwPoJ93g xrML2a/3nDHYqDAIJGdrZGW1PvPqKmgxngmZtM65AUys2M+YxpdhFfdDt31LhVnyYF2Y x9qUphLFXWbzKGzbaumWyrPDoVpsYAnUbOoBTdkyegUFOtmaD3btkvlKaJ0n6BMcaPLQ hTVR7sL7xVc/2FyttYstmwFfoNgtTFgF2OljnDXtw9EtfcrIGMRrTweSAiH+2AYjmQ81 qegw== X-Gm-Message-State: AJIora9wiFqZYtVqer9I5UW/MoWk+pnH7mbmtJFo++UcfXB8eUf7KA+U 8KhCBI6Uzyk4sY4tKPBijyg7QEklgpS3RXjTnyqufQ== X-Received: by 2002:a5d:67c4:0:b0:21d:6d91:7b1a with SMTP id n4-20020a5d67c4000000b0021d6d917b1amr20926351wrw.313.1658117218369; Sun, 17 Jul 2022 21:06:58 -0700 (PDT) MIME-Version: 1.0 References: <20220707145248.458771-1-apatel@ventanamicro.com> <20220707145248.458771-4-apatel@ventanamicro.com> In-Reply-To: From: Anup Patel Date: Mon, 18 Jul 2022 09:36:46 +0530 Message-ID: Subject: Re: [PATCH 3/5] RISC-V: KVM: Add G-stage ioremap() and iounmap() functions To: Atish Patra Cc: Anup Patel , Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , KVM General , "open list:KERNEL VIRTUAL MACHINE FOR RISC-V (KVM/riscv)" , linux-riscv , "linux-kernel@vger.kernel.org List" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 13, 2022 at 6:56 AM Atish Patra wrote: > > On Thu, Jul 7, 2022 at 7:53 AM Anup Patel wrote: > > > > The in-kernel AIA IMSIC support requires on-demand mapping / unmapping > > of Guest IMSIC address to Host IMSIC guest files. To help achieve this, > > we add kvm_riscv_stage2_ioremap() and kvm_riscv_stage2_iounmap() > > functions. These new functions for updating G-stage page table mappings > > will be called in atomic context so we have special "in_atomic" parameter > > for this purpose. > > > > Signed-off-by: Anup Patel > > --- > > arch/riscv/include/asm/kvm_host.h | 5 +++++ > > arch/riscv/kvm/mmu.c | 18 ++++++++++++++---- > > 2 files changed, 19 insertions(+), 4 deletions(-) > > > > diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h > > index 59a0cf2ca7b9..60c517e4d576 100644 > > --- a/arch/riscv/include/asm/kvm_host.h > > +++ b/arch/riscv/include/asm/kvm_host.h > > @@ -284,6 +284,11 @@ void kvm_riscv_hfence_vvma_gva(struct kvm *kvm, > > void kvm_riscv_hfence_vvma_all(struct kvm *kvm, > > unsigned long hbase, unsigned long hmask); > > > > +int kvm_riscv_gstage_ioremap(struct kvm *kvm, gpa_t gpa, > > + phys_addr_t hpa, unsigned long size, > > + bool writable, bool in_atomic); > > +void kvm_riscv_gstage_iounmap(struct kvm *kvm, gpa_t gpa, > > + unsigned long size); > > int kvm_riscv_gstage_map(struct kvm_vcpu *vcpu, > > struct kvm_memory_slot *memslot, > > gpa_t gpa, unsigned long hva, bool is_write); > > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c > > index b75d4e200064..f7862ca4c4c6 100644 > > --- a/arch/riscv/kvm/mmu.c > > +++ b/arch/riscv/kvm/mmu.c > > @@ -343,8 +343,9 @@ static void gstage_wp_memory_region(struct kvm *kvm, int slot) > > kvm_flush_remote_tlbs(kvm); > > } > > > > -static int gstage_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa, > > - unsigned long size, bool writable) > > +int kvm_riscv_gstage_ioremap(struct kvm *kvm, gpa_t gpa, > > + phys_addr_t hpa, unsigned long size, > > + bool writable, bool in_atomic) > > { > > pte_t pte; > > int ret = 0; > > @@ -353,6 +354,7 @@ static int gstage_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa, > > struct kvm_mmu_memory_cache pcache; > > > > memset(&pcache, 0, sizeof(pcache)); > > + pcache.gfp_custom = (in_atomic) ? GFP_ATOMIC | __GFP_ACCOUNT : 0; > > pcache.gfp_zero = __GFP_ZERO; > > > > end = (gpa + size + PAGE_SIZE - 1) & PAGE_MASK; > > @@ -382,6 +384,13 @@ static int gstage_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa, > > return ret; > > } > > > > +void kvm_riscv_gstage_iounmap(struct kvm *kvm, gpa_t gpa, unsigned long size) > > +{ > > + spin_lock(&kvm->mmu_lock); > > + gstage_unmap_range(kvm, gpa, size, false); > > + spin_unlock(&kvm->mmu_lock); > > +} > > + > > void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, > > struct kvm_memory_slot *slot, > > gfn_t gfn_offset, > > @@ -517,8 +526,9 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > > goto out; > > } > > > > - ret = gstage_ioremap(kvm, gpa, pa, > > - vm_end - vm_start, writable); > > + ret = kvm_riscv_gstage_ioremap(kvm, gpa, pa, > > + vm_end - vm_start, > > + writable, false); > > if (ret) > > break; > > } > > -- > > 2.34.1 > > > > Reviewed-by: Atish Patra Queued this patch for 5.20. Thanks, Anup