From patchwork Thu Jul 7 14:52:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1653648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=qfRYhu5v; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=ohr/MWgS; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Ldzv057Vvz9s2R for ; Fri, 8 Jul 2022 00:53:48 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iOm/3YiWXFXXJNVewwTRnjpEDhxq6JM2p4rnXkOsmf0=; b=qfRYhu5vutl9Bx mE7m/4C6wWxyPT/yy/53lHTOCJh818EH745KBWSKRXssqWsJuWkDS5ZeDKtxY1kc5APYj+SJinm+c rLXc29rWo01kx89bZNPRYUYyav9jyrMEdUV6ciDsr8rjOfttA0RP64VXHBWrSpEKrWnVPJicenmaC 4AXT6XsZ1dAx5PE1lc+hlXgl0jXdRrLr7wjTYzfJDfVqvXmGd9bP2nRxKiySq0EtSJ9Sj2UrIOIVl SR0iSUmvUDCOGhxcjJlGKTyrJhAXLIR2A49+o3AdJjKOe8Y/xCKCZgXBCqxznOSoOPJshYI2smd/K YxZgTo/YEYx1FY9mhbHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9Ssz-00GdPb-6Y; Thu, 07 Jul 2022 14:53:45 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o9Ssk-00GdDs-UB for kvm-riscv@lists.infradead.org; Thu, 07 Jul 2022 14:53:32 +0000 Received: by mail-pf1-x431.google.com with SMTP id 70so4777614pfx.1 for ; Thu, 07 Jul 2022 07:53:30 -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=SILj0U5OttoKLyxHHbEFX/6Loldz8Mg8dA0PvWHzEaVaSRwgtkLKYV6KcXMoTJNj/3 6LSxo3zz4MN+mN/xMQy0VxzAiKl1IaXpLe9b4KESRXnQ8lE2mpZPKM9WALBcio3qmlco WNp4nsC7uZNhOkS9ToG7M0rH6vWyYcsAz5+V+vXRUWkPm5MZuwdist/rDLaWprPBWsp+ fjinJXb/A9tzVTJ/ncEVk7URnvFRpjK94agIfpSguoPfEr6br0z0DqrgEayWfBCgtBEp nLnTjxNPd+BeoJ+d38pbrwEf8UYVHIjAUZwTJYhB0ltD1HV/pDmXYwdIDXTRpQfjQ0mo cnow== X-Gm-Message-State: AJIora9jz2N7KNsE3lCJhYMXg7o7w+Dlj+RcIchoEO85v98seD2pMAFI 5vbiVmmz5KzrU/m02NtNcKTsIg== X-Google-Smtp-Source: AGRyM1snRoAR3IesxARH9go1XUXWfZLlCv+MUuUz10z6M/0+3rvZbNtTwjV0qKUuBZJUWXwPPcq4Ag== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220707_075331_076384_543457AD X-CRM114-Status: GOOD ( 11.56 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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_io [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:431 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.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 Reviewed-by: Atish Patra --- 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; }