From patchwork Mon Mar 10 15:12:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 14010364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4A322C282DE for ; Mon, 10 Mar 2025 15:47:58 +0000 (UTC) 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=mdlfd5B1HXIY55an97TyErXPrHEXsZycbcWSfh0GX0k=; b=C/DMLgI2Y0Mi54 5sNNuowfhlB1NBBqz5U3tqwfr3y2jD4Y8H29IzFkNXd5mUMdirHJApnv+e3aNz9+gq/+GUTFniKpu /SErlADKn93+oOpxx8mEKKqLW/I6guEvPY7FKQp98x6KIgJrYSnzhCXb6JzDxzMnEPyt4C2f6165p T+Mz0q5ACIiLgPot0vfPRMFuy7iMhKCBJeGHoIQDLg1pZ54WMOmBJ330CckRF+SBxbG+ZL3BDrlXS XseK1dn4y3Z4iHsGulHdvkpRkHwtQVFYMZKm2MwOatuNBG+UIoxS+e1y7AOI3IRxlkQQQKjIYdGkB qVSkzTkAgH42WWPW5mNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1trfM9-00000003GKo-1UlG; Mon, 10 Mar 2025 15:47:53 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1treqD-000000038BS-3rEs for linux-riscv@lists.infradead.org; Mon, 10 Mar 2025 15:14:55 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-225477548e1so33388095ad.0 for ; Mon, 10 Mar 2025 08:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1741619693; x=1742224493; darn=lists.infradead.org; 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=6l++jogwQbkZh7dICu4CyxiXIZKEwQKPb1/RHWWp03A=; b=gcC4aScSF1JWDAyz5OEIQPHq5k9LxwhokxZ5+GtzSkBF//n7EjmgSjU8XFmz7NsmKw EENWnkSxErFvYex1LvBvUyoICBapqaV99e/tm8iOmtrSnzH6bDsK3Vrkb4jwlFgjT9Yw 8iHXrwyO8F5RHQstUo8OHcz6MbAixPl8W0u3859zAJaL8tblfhH8EN0nqGDgU0h6Zl8P 3huhXYJVv3+7mdZ/FCCe/OWUpW8oSv+1l9sbEmB80YfuV2yJqsH1cfhnlWf5LeI9wqoU 7rOH0OP9hQKB4IMScsydhI36JNVr/SFqWvfiLI9dbe4m+D3Qt/gSsEHTfE8FI0V27SBx 5nTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741619693; x=1742224493; 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=6l++jogwQbkZh7dICu4CyxiXIZKEwQKPb1/RHWWp03A=; b=H1+dXicAHJbc0VU6RLXhInIZ21HBwJaYY3cJ54AgUEajdrQHOaVVKQaC4MUrJvpmSD 3N0pGYLDlDumz4D/Jt3nn0r5Mo57ra5kqb+52WAS+o25KxpMcwyPmWnIa1a6chIBi0Wj BNfQ+cHVmY8wzZSdZCM8z9W0NYaZezdJQAjMpa/U8yJwG+uanrVGsfCFo+iSIejSMu1W hIAsFbRMOC5sRuZxLQoql6Jf67CdeG/hdaB3o3dywU+ICVHePGq/uegMJzLgoX6dnTTU KlwfhT1goLiCUa4bch5N7h4/DPUVJYjnUp1JWQX7jUhw0Uqj2oW3eKDIb45hM+SbmppR DLzw== X-Forwarded-Encrypted: i=1; AJvYcCUNJUHUSY7WHuGjBU/ryy+qgW8OiSz+snXxz0+7yHb73kCqnExaj9PbCilONH72R4kkKU1xPR7LoEo0pA==@lists.infradead.org X-Gm-Message-State: AOJu0YxWT7ZzsQA54o1YX1RHNWR20OcLZJh4YoqtJjGFA4277cXyyntY 1902EPpTNUZYd1BsnRXQKQnbkSn0+wC20LDKBmn20O4hYuHUjjf1iIB9Va6l+Ns= X-Gm-Gg: ASbGncupHSu4+2uor96NV6XSM6fzWi6KT3FzXzunTplqyrirR6XLcUnmsl59F/dgxUq tb9CBB9RbS70aVx2QBwRX9958NzVfowH1cawJ89B2hWNYF2mtj/jpRuh024PZQzeiT/RDfOAm0N PrD6uIgZJ6mdPUX1QS/YJTbJqs2gzcN780/4A3aRlVoB0bRiPX81No8DCGJMe39vLERhiy4JyBs hxQsIiSoSIx1xDqRhRfFP99EHXOnDRKtT6PKG8etzz474v33E8CpGXZBAmtkgVTqmGxI1FSM0qj mdvfolVxF/2//jkpJPK+BssTel5k/kmKfJsv0Ugq8mT5Wf9kt+h90+q2 X-Google-Smtp-Source: AGHT+IGtMqipPUgghWjpfZ6ZkTy1ft1+oxAHrUN4YZ5GS8RdVCB2lFCZnqkm3CMl7QqHMx+cAywiQQ== X-Received: by 2002:a17:902:f648:b0:220:d601:a704 with SMTP id d9443c01a7336-22428a967a4mr207702705ad.18.1741619693398; Mon, 10 Mar 2025 08:14:53 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-224109e99dfsm79230515ad.91.2025.03.10.08.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Mar 2025 08:14:52 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , Shuah Khan , Jonathan Corbet , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Samuel Holland Subject: [PATCH v3 15/17] RISC-V: KVM: add SBI extension reset callback Date: Mon, 10 Mar 2025 16:12:22 +0100 Message-ID: <20250310151229.2365992-16-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250310151229.2365992-1-cleger@rivosinc.com> References: <20250310151229.2365992-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250310_081453_960764_E58C9F50 X-CRM114-Status: GOOD ( 17.93 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, oonly the STA extension needed a reset function but that's going to be the case for FWFT as well. Add a reset callback that can be implemented by SBI extensions. Signed-off-by: Clément Léger Reviewed-by: Andrew Jones --- arch/riscv/include/asm/kvm_host.h | 1 - arch/riscv/include/asm/kvm_vcpu_sbi.h | 2 ++ arch/riscv/kvm/vcpu.c | 2 +- arch/riscv/kvm/vcpu_sbi.c | 24 ++++++++++++++++++++++++ arch/riscv/kvm/vcpu_sbi_sta.c | 3 ++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index cc33e35cd628..bb93d2995ea2 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -409,7 +409,6 @@ void __kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu); bool kvm_riscv_vcpu_stopped(struct kvm_vcpu *vcpu); -void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu); #endif /* __RISCV_KVM_HOST_H__ */ diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index bcb90757b149..cb68b3a57c8f 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -57,6 +57,7 @@ struct kvm_vcpu_sbi_extension { */ int (*init)(struct kvm_vcpu *vcpu); void (*deinit)(struct kvm_vcpu *vcpu); + void (*reset)(struct kvm_vcpu *vcpu); }; void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run); @@ -78,6 +79,7 @@ bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx); int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu); void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu); +void kvm_riscv_vcpu_sbi_reset(struct kvm_vcpu *vcpu); int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, unsigned long reg_num, unsigned long *reg_val); diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 877bcc85c067..542747e2c7f5 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -94,7 +94,7 @@ static void kvm_riscv_reset_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.hfence_tail = 0; memset(vcpu->arch.hfence_queue, 0, sizeof(vcpu->arch.hfence_queue)); - kvm_riscv_vcpu_sbi_sta_reset(vcpu); + kvm_riscv_vcpu_sbi_reset(vcpu); /* Reset the guest CSRs for hotplug usecase */ if (loaded) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 858ddefd7e7f..18726096ef44 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -539,3 +539,27 @@ void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu) ext->deinit(vcpu); } } + +void kvm_riscv_vcpu_sbi_reset(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_sbi_context *scontext = &vcpu->arch.sbi_context; + const struct kvm_riscv_sbi_extension_entry *entry; + const struct kvm_vcpu_sbi_extension *ext; + int idx, i; + + for (i = 0; i < ARRAY_SIZE(sbi_ext); i++) { + entry = &sbi_ext[i]; + ext = entry->ext_ptr; + idx = entry->ext_idx; + + if (idx < 0 || idx >= ARRAY_SIZE(scontext->ext_status)) + continue; + + if (scontext->ext_status[idx] != KVM_RISCV_SBI_EXT_STATUS_ENABLED || + !ext->reset) + continue; + + ext->reset(vcpu); + } +} + diff --git a/arch/riscv/kvm/vcpu_sbi_sta.c b/arch/riscv/kvm/vcpu_sbi_sta.c index 5f35427114c1..cc6cb7c8f0e4 100644 --- a/arch/riscv/kvm/vcpu_sbi_sta.c +++ b/arch/riscv/kvm/vcpu_sbi_sta.c @@ -16,7 +16,7 @@ #include #include -void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu) +static void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu) { vcpu->arch.sta.shmem = INVALID_GPA; vcpu->arch.sta.last_steal = 0; @@ -156,6 +156,7 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = { .extid_end = SBI_EXT_STA, .handler = kvm_sbi_ext_sta_handler, .probe = kvm_sbi_ext_sta_probe, + .reset = kvm_riscv_vcpu_sbi_sta_reset, }; int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu,