Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp914511rwr; Wed, 19 Apr 2023 15:22:18 -0700 (PDT) X-Google-Smtp-Source: AKy350Yw+wiEs4TUE5a8Z3YkpvC3DfdZcVjv6o6xLPfa4YtkimEb/jvpEyMnD5QTi9/gcBfJXfgC X-Received: by 2002:a17:90a:2dc2:b0:244:952c:9701 with SMTP id q2-20020a17090a2dc200b00244952c9701mr4352417pjm.7.1681942938023; Wed, 19 Apr 2023 15:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681942938; cv=none; d=google.com; s=arc-20160816; b=c1mes8k53rn1jpiNXnagdVjXZ3AG9YrpiS/pqKQvMA14e4S5xdK7hJ2I8EFJtu6DJ6 2znn4yLYHLUqhX7S3QPecLZbUxbs5t42kLXtOJg95CvVgIobwkyGjZKVu3+oCC/ec0YW SY/uXOnSOIYJQq4ImQP26FsMPdk5zImBU2tj5Vm213ZkK+GMheYrgnzkr2PnFr9u45O+ WhZZaHDqTRYSxz86A6oD++q2BTnJYPDqoW0PxapGfgEpBt9cEJXDv4CvATQqgMLulZgW O71NCNCoh48LnHI1FAOgiXMZG2T+49l8vIK8HhQBcbjo99tzwCPJwfpth6bN2DIGZtEV mPDA== 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=g1210zPiD8zHFMhzBINzpx5nEW8Eoe5MAD0zhuCIRKc=; b=T6c+J0k/3A8oB5K0hVIEK6qjAvuMC30ARfOwaRdlfZivxS10/70Og9O/XDXjXfb4PC w2gzG9CWWljDB5AsVaidi8N8hqXt+iaP9yn7opnJWnF7qFQ4lggBUtiCIowm9fk8s7/K aWi0Yeih3Au3zuUTG33VQ9ZihtOPilik2JgJeq9CEpLiFzkoJXTrTWQASuOEv1chk0KU wbPmi4kW1j1cLAMkvXiYxbA4KeXujGUxfP27PXbFp+heNEX8Hjgv6COW8tIHnn0m6J/n yWWJI03Yaf22xkebOHbdZEbLZdzLhcV9gsIYOx4m7HPUKyFyzMStaL7QH86J9ewn37ER hKtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ANhU+J8n; 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 ji5-20020a170903324500b001a5089fe47fsi16419277plb.326.2023.04.19.15.22.06; Wed, 19 Apr 2023 15:22:18 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=ANhU+J8n; 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 S232876AbjDSWVP (ORCPT + 99 others); Wed, 19 Apr 2023 18:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbjDSWUo (ORCPT ); Wed, 19 Apr 2023 18:20:44 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357959031 for ; Wed, 19 Apr 2023 15:19:31 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b5465fb99so383339b3a.1 for ; Wed, 19 Apr 2023 15:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681942716; x=1684534716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g1210zPiD8zHFMhzBINzpx5nEW8Eoe5MAD0zhuCIRKc=; b=ANhU+J8nQWq2obESgBEJE0X9NLT82kBUBDzc1BRbSeZ1EgPeiOl0GddoyWaEPDRU8N vnwjEIo0UjaS9xezvAc/UGttMWlJo7ew/iqSZCawFdCpXkbeL6whYMnxnv1UE0Mkzjl9 zxU19X9QWwNQwOpt5WP+CxQUT1ZA3xUcznURR03bnG+WcdbBRPDMOVkCCCi+rkT0f8qL 85oGYhbbNz2xb1HJWq0YwM9QGXFDFKbWMgSuumHQ7xfEhCPnY/6ETL+ra68ruaG7yl2u qOhetkOJdoWKqEsNNxd/aiUVnUUF2SqhhyrAmB8w+eSk+hd8cQeWPbuaUf1XaZLgT9mw WXww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681942716; x=1684534716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g1210zPiD8zHFMhzBINzpx5nEW8Eoe5MAD0zhuCIRKc=; b=h7pLfOB117/X7oGF2apEWXIzTKjvVGQR2kZRFI3j6IVPEsgQ+tNRAYmkBIDrktHsob FGPH9MZDygBqr8PkPWtHmbfnqc+LZFJ062eMfmXnFfNJBOUJcfWqDqskisRPlrbTi3P0 FXtTQ2aWqx3ru73bJKGTCUlJeH3VEslDvHQYyn1x9V4AcTKGDfTFn1XbEfR+lYLFALMZ qV76vwLQ/rEmKQaM5M6XcVaCalVitonZLR+G2YPaoyFOvmACRoUUx5hHfWViGyC1HTv2 lS1rB9RxzXvsZkH4KiRbOgtQ1gkLZ1xw79hoURWrtSqf1eKeLzCp8hZcNxI3uP/SqjZD u59g== X-Gm-Message-State: AAQBX9c+najO4s4EGCbNVlR5g8P3YaMWP3tuQ5Zqk+5YPN69BrcRtznx UbHACBd87Vsq6fulwhqIv4GwcNvXPfabCJTxDfg= X-Received: by 2002:a17:903:1c4:b0:1a1:ee8c:eeba with SMTP id e4-20020a17090301c400b001a1ee8ceebamr7881066plh.59.1681942715856; Wed, 19 Apr 2023 15:18:35 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jn11-20020a170903050b00b00196807b5189sm11619190plb.292.2023.04.19.15.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:18:35 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Christoph Hellwig , Conor Dooley , Greg Kroah-Hartman , Guo Ren , Heiko Stuebner , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Mayuresh Chitale , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Rajnesh Kanwal , Uladzislau Rezki Subject: [RFC 30/48] RISC-V: KVM: Perform limited operations in hardware enable/disable Date: Wed, 19 Apr 2023 15:16:58 -0700 Message-Id: <20230419221716.3603068-31-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419221716.3603068-1-atishp@rivosinc.com> References: <20230419221716.3603068-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_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 Hardware enable/disable path only need to perform AIA/NACL enable/disable for TVMs. All other operations i.e. interrupt/exception delegation, counter access must be provided by the TSM as host doesn't have control of these operations for a TVM. Signed-off-by: Atish Patra --- arch/riscv/kvm/main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/riscv/kvm/main.c b/arch/riscv/kvm/main.c index 45ee62d..842b78d 100644 --- a/arch/riscv/kvm/main.c +++ b/arch/riscv/kvm/main.c @@ -13,6 +13,7 @@ #include #include #include +#include long kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) @@ -29,6 +30,15 @@ int kvm_arch_hardware_enable(void) if (rc) return rc; + /* + * We just need to invoke aia enable for CoVE if host is in VS mode + * However, if the host is running in HS mode, we need to initialize + * other CSRs as well for legacy VMs. + * TODO: Handle host in HS mode use case. + */ + if (unlikely(kvm_riscv_cove_enabled())) + goto enable_aia; + hedeleg = 0; hedeleg |= (1UL << EXC_INST_MISALIGNED); hedeleg |= (1UL << EXC_BREAKPOINT); @@ -49,6 +59,7 @@ int kvm_arch_hardware_enable(void) csr_write(CSR_HVIP, 0); +enable_aia: kvm_riscv_aia_enable(); return 0; @@ -58,6 +69,8 @@ void kvm_arch_hardware_disable(void) { kvm_riscv_aia_disable(); + if (unlikely(kvm_riscv_cove_enabled())) + goto disable_nacl; /* * After clearing the hideleg CSR, the host kernel will receive * spurious interrupts if hvip CSR has pending interrupts and the @@ -69,6 +82,7 @@ void kvm_arch_hardware_disable(void) csr_write(CSR_HEDELEG, 0); csr_write(CSR_HIDELEG, 0); +disable_nacl: kvm_riscv_nacl_disable(); } -- 2.25.1