Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp273793imw; Tue, 12 Jul 2022 19:49:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sJkAQM9NAeCW75we+5cyDQ1SSTmHB5CIpe41W2C//sPOf9IQ40DqMB/gKfc84+H5kmqBFC X-Received: by 2002:a17:902:f78c:b0:169:b76f:2685 with SMTP id q12-20020a170902f78c00b00169b76f2685mr1028092pln.41.1657680584865; Tue, 12 Jul 2022 19:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657680584; cv=none; d=google.com; s=arc-20160816; b=ojHDqayWO15ICgiaPR9esgRKJd1A8xFrmmLKSYAYGzkZF9UIZXMxtGaATYEyPmJmOH aq1MBw/+hT8zmtGmT3i0e8gEDAP8VGb3w12B57UvJ5LYVE8LortzzKw+Q+cT2/JHapt4 wh0DC3YwwBVnB6PYAWD7GzuEDrDnBUQq4XAMV9M8XUNLK1PMVcNAiRhDB5ESxzijHTw+ Km6KaITffRgDDVRGbdikBfV8IG9k6mAZ2/Fmpvvuk7x1UJU6Y2fQsaM+Rp2mRcjbgcKJ q3soErx1oPEKvsGF3iGYCu2X5uzgCj+GAfIxWelFoDXUu7+/JqgcsDu6i5ADz3uNCntN 4Seg== 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=0Dy+Rmcjm8hkXGU4nfEHBrtA1yQ8VRvv++C+zBI3stA=; b=PFopvYtYjgTS9k8s7xe2PDL753yocOYgitW2/QriP2F4dItHQF0RuA6ln/iPirisCq 74PBDNHjYWVPCDwxeKzeRCiWmqaMFoGcFdHWs5g1B4uGb7xpvsepaoRePPBtTlwZp/3E IUxxCAWDdWVDWRW2XA9zdx9aDa1nl6SC8KlXaG8CGvUK9JzUCUdsqwb9Lj0D7RZxDd8f hwvCCFpPA5USCNuWojR3ygNStjMza8nSpvxkbH06nMCXWNV3gGby0PNkJ2ENLZT/KZIT E4pAdYO2Cuu+4B5k0gb8m/n0ZZ+lFhQtBOKwV4t756PsOKuIlI1B3PNrcRX0g6nXDryD aCbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b="AGQh/f2q"; 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 v18-20020a056a00149200b0052ade51b8a7si6788877pfu.361.2022.07.12.19.49.31; Tue, 12 Jul 2022 19:49:44 -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=@atishpatra.org header.s=google header.b="AGQh/f2q"; 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 S233379AbiGMB05 (ORCPT + 99 others); Tue, 12 Jul 2022 21:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232959AbiGMB0z (ORCPT ); Tue, 12 Jul 2022 21:26:55 -0400 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C66DB657B for ; Tue, 12 Jul 2022 18:26:53 -0700 (PDT) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-31cac89d8d6so98858137b3.2 for ; Tue, 12 Jul 2022 18:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0Dy+Rmcjm8hkXGU4nfEHBrtA1yQ8VRvv++C+zBI3stA=; b=AGQh/f2q3qa6iXyE58orKUemPvszcwkcBLBJaMXz97hOSpcp+xbP7A3WISXnxCsi8J qmti94NwVRMdkhLPb7Z519Z0uOxjAs5mZNcLNPJvbRUUe/1d1SNmD9qM8pguS+3NHhry JpctM7lg5p9sbx/qoRaUQlI3PyLT5G7Eckt1U= 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=0Dy+Rmcjm8hkXGU4nfEHBrtA1yQ8VRvv++C+zBI3stA=; b=jzk2lxEsSZIhu+JXUbyJX8bu0ARr6egzx29B0JJ9gmXG5gVkIauKous12Yx0+LvpY+ dEG//xOixwlBwDusl2y9GSaMhMlHeNCylbLQW14xWnrxLWC5f+sB3enWC/xfdaTvc0qt UrtIFjP8GHi61fJ96cJqxtor9nUTd8osBIqMB8lb2Z0gkJ9iPHA1s1Jw+LsRQZ0M0Qw5 LbUygcQs/9SpMgE3AdOwrh/z/R+NjDtd582MMWs/q92f35qiX9YD5WE5A0JhOrTmzbAA 8XFBH0tEGL2L2ruQ96SgDGGJNor0uX4RKV9aODW7D3i753YToAnhCjVdCkschJt3F3fV PGDQ== X-Gm-Message-State: AJIora9kAFHJniq4FQQtqAovS/dgmk2TvJzwiMl8ihv81komuTuLp0RN E5xILkm4jrm5ZqIM/gxJo9IrH5NFUFYTMYl1R4p1 X-Received: by 2002:a81:653:0:b0:31d:2a21:734 with SMTP id 80-20020a810653000000b0031d2a210734mr1435894ywg.14.1657675612674; Tue, 12 Jul 2022 18:26:52 -0700 (PDT) MIME-Version: 1.0 References: <20220707145248.458771-1-apatel@ventanamicro.com> <20220707145248.458771-4-apatel@ventanamicro.com> In-Reply-To: <20220707145248.458771-4-apatel@ventanamicro.com> From: Atish Patra Date: Tue, 12 Jul 2022 18:26:41 -0700 Message-ID: Subject: Re: [PATCH 3/5] RISC-V: KVM: Add G-stage ioremap() and iounmap() functions To: Anup Patel Cc: Paolo Bonzini , Palmer Dabbelt , Paul Walmsley , Alistair Francis , Anup Patel , 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 -- Regards, Atish