From patchwork Sun Oct 20 19:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1999651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=kQLWOMji; 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=SEI7UG9u; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XWprR0HFpz1xwK for ; Mon, 21 Oct 2024 06:47:51 +1100 (AEDT) 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: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:In-Reply-To:References: List-Owner; bh=BLCmib+raR4HowYJS/OLH4NlGXGP7BMyh6CApuujZaw=; b=kQLWOMji5VmEUu Wh98JJEhaAYTCvSkxqHpKteeJiyOiduvO+KLs6Dv2EP0vsaQNq+PNuLvZKjyTljuBalTVEEyDd3eJ IWee0Eia7sCqA5oxN3OxnumoUGLudiAQd6BOH/T4QQZVcys7WwAddAPaQga9IGQUfO5bYNRhcBAxN vsGHJr/TvgpDYJavlSvtzLvR4LBNe+Y+XDpVTTaxq4NRSHMWhHQ6bUx+/dIYEyerdoAqxs7pq3lKQ EA+fx6+ab7vBQko7Hqr0n2BnChLyb8g5Sj/GFki6cr1bDJ4Y+WjQtZJo47L2CrdOCYl0SAGGuAM9O RU3tYz319zPzTlyaIm+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2bu1-00000005Men-3BGt; Sun, 20 Oct 2024 19:47:49 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t2btx-00000005Md5-2lOX for kvm-riscv@lists.infradead.org; Sun, 20 Oct 2024 19:47:47 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2e2d1858cdfso2482763a91.1 for ; Sun, 20 Oct 2024 12:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1729453664; x=1730058464; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+ivURfBSvioRGHQ9UQ83vIOIrYF8b7wh/zY/rzLMXhM=; b=SEI7UG9u6iL0L7K2kRhx4jzjo23kCYAb7XRFCTQUP7YEZt7y2ztvDN6LbL5GfsSkTn mbNGlNnDcWwQqXPvr4uzsI5zXy+hvbERerrmy6c3LVfqv7148Nb/m4/o13kStti3JczU 80TbpxkTQkdnolLr9G1nEs5Y7NXaIwHc/1EIEMMLDJ73UGd1eeIJup9mmFo39BstgBUi GQq82WY9RJbuz2A0lFnd2pMRo27CUdUW04jsQhgm89uvQ24681/S8eB3avTM8szfeN/q HRJPI8V5erSH9ey72UcHN9S3H3aArE5jchk/vojO+yJL1wJWsiqAIG/dyQ0rkdPcDCpf QemQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729453664; x=1730058464; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+ivURfBSvioRGHQ9UQ83vIOIrYF8b7wh/zY/rzLMXhM=; b=bsoArzKIBH+0weMgrxhYDuwyEYnTG1ibjNzCA26fPHItv49vtXxfevj4Y6l2/WsvAx E1jC7iUZhgJgBa7GycKFFr8bqBZHC4aAnS1Ka0zHwhGOtoFL3Gi0X7UmxgOpN/DfmHGk 2vABISzuPl+Ss3blhThO69oCTs2CAh851c5USf46ceIDOLKQ7ByI5sCP1U5yWbQ8bQcS h1AVqnQbZSzpzKdoIWUjhKOCcPFyopAvXKKbg+V6/hUfnddZNZaEXk+GSr6tigeqlq9W Uo4zfB/Nq5njvluVmo3oC+DFuaz+R/vqQJqxwpLHT3huQ+yR38xY9MFjdT7c1/zfXcWM Awdw== X-Forwarded-Encrypted: i=1; AJvYcCW/y+tWVAoOknhEWr/j5VvG3/ICmv2F/Dvhgn/xwPveyTB2G32HiIeFqOtiy+bgcg77liFXh6imjsE=@lists.infradead.org X-Gm-Message-State: AOJu0YxIxR690RMdh/sSfeMdXDkr7DVpMTSdeT42xqy+Dk421V6qlNnr rsAYYJIcw6eCmo3hMMvUrf+VG4OvGIW52HNGWyd26dW8ihjASBO+Qi9O+ZL4xAQ= X-Google-Smtp-Source: AGHT+IHG9XXvm9AJ2oRMr/j3vJjm8TDJeXCKSU0fNmuN70GfoPp1Bf8M19KyxCwvXuMkl6hkr0LMHg== X-Received: by 2002:a17:90b:4c8b:b0:2c9:9658:d704 with SMTP id 98e67ed59e1d1-2e5617331b4mr9148581a91.40.1729453664025; Sun, 20 Oct 2024 12:47:44 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([50.238.223.131]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e5ad365d4dsm1933188a91.14.2024.10.20.12.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2024 12:47:43 -0700 (PDT) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley Cc: Atish Patra , Andrew Jones , 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 v2 00/13] Accelerate KVM RISC-V when running as a guest Date: Mon, 21 Oct 2024 01:17:21 +0530 Message-ID: <20241020194734.58686-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241020_124745_725901_AC408034 X-CRM114-Status: GOOD ( 11.47 ) X-Spam-Score: -2.1 (--) 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 KVM RISC-V hypervisor might be running as a guest under some other host hypervisor in which case the complete H-extension functionality will be trap-n-emulated by the host hypervisor. In this case [...] Content analysis details: (-2.1 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:102d 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_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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 KVM RISC-V hypervisor might be running as a guest under some other host hypervisor in which case the complete H-extension functionality will be trap-n-emulated by the host hypervisor. In this case, the KVM RISC-V performance can be accelerated using the SBI nested acceleration (NACL) extension if the host hypervisor provides it. These series extends KVM RISC-V to use SBI NACL extension whenever underlying SBI implementation (aka host hypervisor) provides it. These patches can also be found in the riscv_sbi_nested_v2 branch at: https://github.com/avpatel/linux.git To test these patches, run KVM RISC-V as Guest under latest Xvisor found at: https://github.com/xvisor/xvisor.git For the steps to test on Xvisor, refer the Xvisor documentation /docs/riscv/riscv64-qemu.txt with two small changes: 1) In step#11, make sure compressed kvm.ko, guest kernel image, and kvmtool are present in the rootfs.img 2) In step#14, make sure AIA is available to Xvisor by using "virt,aia=aplic-imsic" as the QEMU machine name. Changes since v1: - Dropped nacl_shmem_fast() macro from PATCH8 - Added comments in PATCH8 about which back-to-back ncsr_xyz() macros are sub-optimal - Moved nacl_scratch_xyz() macros to PATCH8 Anup Patel (13): RISC-V: KVM: Order the object files alphabetically RISC-V: KVM: Save/restore HSTATUS in C source RISC-V: KVM: Save/restore SCOUNTEREN in C source RISC-V: KVM: Break down the __kvm_riscv_switch_to() into macros RISC-V: KVM: Replace aia_set_hvictl() with aia_hvictl_value() RISC-V: KVM: Don't setup SGEI for zero guest external interrupts RISC-V: Add defines for the SBI nested acceleration extension RISC-V: KVM: Add common nested acceleration support RISC-V: KVM: Use nacl_csr_xyz() for accessing H-extension CSRs RISC-V: KVM: Use nacl_csr_xyz() for accessing AIA CSRs RISC-V: KVM: Use SBI sync SRET call when available RISC-V: KVM: Save trap CSRs in kvm_riscv_vcpu_enter_exit() RISC-V: KVM: Use NACL HFENCEs for KVM request based HFENCEs arch/riscv/include/asm/kvm_nacl.h | 245 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/sbi.h | 120 +++++++++++++++ arch/riscv/kvm/Makefile | 27 ++-- arch/riscv/kvm/aia.c | 114 +++++++++----- arch/riscv/kvm/main.c | 51 ++++++- arch/riscv/kvm/mmu.c | 4 +- arch/riscv/kvm/nacl.c | 152 ++++++++++++++++++ arch/riscv/kvm/tlb.c | 57 ++++--- arch/riscv/kvm/vcpu.c | 184 ++++++++++++++++------ arch/riscv/kvm/vcpu_switch.S | 137 +++++++++++------ arch/riscv/kvm/vcpu_timer.c | 28 ++-- 11 files changed, 941 insertions(+), 178 deletions(-) create mode 100644 arch/riscv/include/asm/kvm_nacl.h create mode 100644 arch/riscv/kvm/nacl.c