Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3849057imw; Thu, 7 Jul 2022 08:30:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v4XCoU7ZxSFCkBmMA8Tqjtpk0TBCL06kDKd+VMSlS85EcUALNMr+6jhwiYbmAn7UqMieCF X-Received: by 2002:a17:906:519b:b0:722:e857:1a90 with SMTP id y27-20020a170906519b00b00722e8571a90mr44219058ejk.212.1657207817955; Thu, 07 Jul 2022 08:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657207817; cv=none; d=google.com; s=arc-20160816; b=fxyJQABze7p79LkkujNHS99hPa5A39P6jTNShEKLIjAt1q3NfPDT8uXv4OFxeQ5ONT 0AKl5hgYt4GB8bEo8ujGvir2wUgXg0vXVJWOX1BzDvWUCwi/SqeGIapJGj9OEJ7GxHxk 5gH1rnFncc7OEZKottwdNQxDFdGi9JS43c1XqvQsmiQmm+mWlrt+d4Igg35qUiErvjbI t0+zJz7QoMctqxRrwe6Chn3lkbgVbHdQqbTq+kBcbLV6aQg6/NbhizGLU4Jt6EWmURa+ mwd92tXO+sn/o3aip4GShTTbvHZpoZUX/3tVGyahugbhJP19xWTbxBvZtQX6ZEeLokxF 3E1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fCJ8QaefSod2FLdMLTYJXcVAzkRtmLMvuXzW7AhKtNg=; b=OhlAJOXthsl6AkLzzu6047Gqoh4Gr0VvaaJ3i3XVvnk/tvtDsX/5qlaqoGD2DNwu5V Lb4QzEogRJye2qyxXXZ94UHDjhbyzTfxC4mT/2zXomflnR+mkZsxwKJwCTbra2SWphmw kvx0ZJThGrRy0UlQhbRxADVxfhWAU6qyq0Vu5qfeBUwjAPjSaBVnhJ453+UTZFTJy0s1 MG0UpHzaruqc/4Z0cviKG/xe+auBE02daj31Lx3sv6vSdzk9JFeL9MYvB1wVB3xU6DUM tNb5Be8Ah5rtqDy7JreCmrcnQfASzeL/URMxASmraM/1Yb3bzthcXOFN50jdYMzTlkCf kqcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b="ohr/MWgS"; 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 s13-20020a508dcd000000b004356ae0bc86si28118197edh.396.2022.07.07.08.29.51; Thu, 07 Jul 2022 08:30:17 -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=@ventanamicro.com header.s=google header.b="ohr/MWgS"; 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 S236299AbiGGOyu (ORCPT + 99 others); Thu, 7 Jul 2022 10:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236113AbiGGOyX (ORCPT ); Thu, 7 Jul 2022 10:54:23 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC3ED167C0 for ; Thu, 7 Jul 2022 07:53:31 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id y9so5653183pff.12 for ; Thu, 07 Jul 2022 07:53:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fCJ8QaefSod2FLdMLTYJXcVAzkRtmLMvuXzW7AhKtNg=; b=ohr/MWgS1UQ+/RqKaVwpKraOsQZDAN9is50wEwY0SGO1YKNeTXChx9AZGHKtXsBBmy Mbp1n9fspU0TeIVN1VIrNZ7vPZzdDx1q/Eo3o+Na38S4wjuQ9jCi/QPL3PhU9kb/Nz/N sL7Rz0wsEVRNOzl7JGtvop7SVc9OQepRnfWrIGfdYy3U3WujeOLTny3Fd6p4OIHTVuHw 4ONX7nnB1kHQspD5L7+rNnmUdBwLlETywejxdMnqyA0LRUWtz6nWWNUkg71C2DAp9YiA Lh8Sf6yiCI4CbfCT+V+YntxYuQbEXcjqhGU/Hp7/b8bbJY6ZjnWH/G9c31yRwu+6L7qe nZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fCJ8QaefSod2FLdMLTYJXcVAzkRtmLMvuXzW7AhKtNg=; b=JRLSrHCeO0JNG8qkPcqx1oAaXtVaULiJQTv0YcGxTLa8Psm+VAqQOsdZPfvUkhSgPb PTmoB2KFjfJ8VwfxUncQwO5YNcK8NhIv9IQJMuMJ9wSGVeVDz1AOzRplHjChHIqtg64k 61VP0lfi7CMZTXpANcGrRiOTdC7fr46fjwCWqSEAAkp+DfkS6skMzBjji8OnyBSyH4uK LjUGU6RoRi0jK/YcuimV1PdjEsx8OfWqeFtBAd3n63t6LWIiwT57wQa8JC+0KfprM5+G 0uNsvv5jDD2E9tDXHL1PT8pqWOZuoluAtjiBz5Mbj7REqy8VKt66ghn0CvxSctGxdELK YXVQ== X-Gm-Message-State: AJIora99esYKNscDP1yii5Ys2KbIZAJgFoInxQ9OxuPjb4Sauc1qTb7F 63UXzjbBc+O9ZZexfleq8UpN/NSxkrp4yQ== X-Received: by 2002:a17:903:124c:b0:16b:a568:996d with SMTP id u12-20020a170903124c00b0016ba568996dmr45373917plh.169.1657205610537; Thu, 07 Jul 2022 07:53:30 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([223.226.40.162]) by smtp.gmail.com with ESMTPSA id b26-20020aa7951a000000b0052535e7c489sm27144231pfp.114.2022.07.07.07.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 07:53:29 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH 3/5] RISC-V: KVM: Add G-stage ioremap() and iounmap() functions Date: Thu, 7 Jul 2022 20:22:46 +0530 Message-Id: <20220707145248.458771-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707145248.458771-1-apatel@ventanamicro.com> References: <20220707145248.458771-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=unavailable 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 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