From patchwork Wed Apr 19 22:16:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1770908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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=49NsHj9C; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=aBDfZuGK; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1wMG6jjfz23tD for ; Thu, 20 Apr 2023 08:24:42 +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=cB8m3uiQxVzEYQj9F2lacxTz2rGavkcQfaCPwc9e1uU=; b=49NsHj9CCMSWMS XlVahVUllJ7enhoLRlOigvaXvTL4UhQ+1TvYBsveG4ehbk7ul3JJ102MAjUTODxQPzAyoaUf9CXlS 1MmHmAEX1x4pcM3q2620MPvybOsqkpLho95rQax/Vge/sEKBE4v8/GG9INBj+6evKyRf6bjl66iZm ZAZQ+sUNdon/Cj/3FyenKOSsvZ9wILyyRvYoGzkQZvR76nOr2edJNRevcjztorEjGWtTOBmyzW3Jg aL+W3pkzlkM1S7Taos4ErBuoLAYaMjJt5zzb2K6lX/3IqdVBo9gEICtlFn0az+afQEAlDwq6RT3RS NNtjRD58K2XzcepXiuSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppGEB-006Uwi-0q; Wed, 19 Apr 2023 22:24:39 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ppGE8-006Uv6-0A for kvm-riscv@lists.infradead.org; Wed, 19 Apr 2023 22:24:37 +0000 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6a5f7341850so287655a34.2 for ; Wed, 19 Apr 2023 15:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681943072; x=1684535072; 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=EbUa6ryrerMYndbR89JSXBoBIycYIOI5MWjMv8QTenY=; b=aBDfZuGKm1nMrsXJN4/qnhfbo/eEbEhGSmFOiVno+0RiEEybCTU09TGsaZZBK3bHde Jy+EzGftbyHaHRClERPYt4hzYERbKcK1ER4JevQN734u9xKrIjhdn7UroQQVPa1yRmme 5Se6E9NAuavSzsypqLI3kbm3zK+rTvSdXy86eDczY2lCfGxXp3FvNyfOWcB7okABCUrn wVO+Vzyrkagv68DL1/P/hiCdcgY+S0PtOLCbWHiZGpVpQ1rNc0TdifNDKCarJPsV/W60 oIDkM/ceeFEnHHm0Iys/SBdv5SgXo0nNz9bl5NxSyZjba4aCOdA1yA11jg76X3X9gijk N19A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681943072; x=1684535072; 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=EbUa6ryrerMYndbR89JSXBoBIycYIOI5MWjMv8QTenY=; b=e2N0y0iLwYXzBsaiRD8/+yTwtu/8zMYtoMPv2fAkpudG2eqbR7OA55S3lbdDbAqhVC l010ufq78kdvqntJRumXMEy0ziG3fg6IILTj5VUnEQtlF/cRKSWf401jz7nDmBzuANtq bC4FsbBMm8EBH8SZAHp6VUoQ7AyqAFapM+0SHeEiXze/GVuChdSKtt4mfSgi+rxm31pv iJhcfjGT09mLuCafc0LeKC4eXCYGfH6jFQuIfnWBY5dukpEz5fXgOUrnPGESx0VX5gPr EJZx1O3OaT+I61RAykjbar7sDWdyKcX+YYIeROws3H7WxAMsF6OH3W9+9pF7/UfkmSdo ZzLg== X-Gm-Message-State: AAQBX9eboiAKk5BAdSMa6WkDeSx+RQBWUvrtH1/buO3CeTwWP5ueaDh2 GEaR4f71zqvwJAESpl93vLlFAQC18O9OIX3M5Gw= X-Google-Smtp-Source: AKy350bOrY/ltn4aOC/irJe3I2c3DHWQXEGnacE0hKIRD44viSqKcVds6P+5HuawRV2gn0DMpSc7nw== X-Received: by 2002:a17:902:e80c:b0:1a8:32e:3256 with SMTP id u12-20020a170902e80c00b001a8032e3256mr6684314plg.35.1681942689090; Wed, 19 Apr 2023 15:18:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:18:08 -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?b?QmrDtnJuIFTDtnBlbA==?= , 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 18/48] RISC-V: KVM: Skip TLB management for TVMs Date: Wed, 19 Apr 2023 15:16:46 -0700 Message-Id: <20230419221716.3603068-19-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_152436_097444_EA60AC3F X-CRM114-Status: GOOD ( 13.67 ) X-Spam-Score: 0.0 (/) 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: TSM manages the tlb entries for the TVMs. Thus, host can ignore all the hfence requests or tlb updates for confidential guests. Most of the hfence requests happen through vcpu requests which are skipp [...] Content analysis details: (0.0 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:335 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 Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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 TSM manages the tlb entries for the TVMs. Thus, host can ignore all the hfence requests or tlb updates for confidential guests. Most of the hfence requests happen through vcpu requests which are skipped for TVMs. Thus, we just need to take care of the invocation from tlb management here. Signed-off-by: Atish Patra --- arch/riscv/kvm/tlb.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kvm/tlb.c b/arch/riscv/kvm/tlb.c index dff37b57..b007c02 100644 --- a/arch/riscv/kvm/tlb.c +++ b/arch/riscv/kvm/tlb.c @@ -15,6 +15,7 @@ #include #include #include +#include #define has_svinval() riscv_has_extension_unlikely(RISCV_ISA_EXT_SVINVAL) @@ -72,6 +73,14 @@ void kvm_riscv_local_hfence_gvma_gpa(gpa_t gpa, gpa_t gpsz, void kvm_riscv_local_hfence_gvma_all(void) { + /* For TVMs, TSM will take care of hfence. + * TODO: We can't skip unconditionally if cove is enabled + * as the host may be running in HS-mode and need to issue hfence + * for legacy VMs. + */ + if (kvm_riscv_cove_enabled()) + return; + asm volatile(HFENCE_GVMA(zero, zero) : : : "memory"); } @@ -160,7 +169,7 @@ void kvm_riscv_local_tlb_sanitize(struct kvm_vcpu *vcpu) { unsigned long vmid; - if (!kvm_riscv_gstage_vmid_bits() || + if (is_cove_vcpu(vcpu) || !kvm_riscv_gstage_vmid_bits() || vcpu->arch.last_exit_cpu == vcpu->cpu) return;