From patchwork Mon Feb 10 21:35:46 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: 13969387 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 04AC3C02198 for ; Tue, 11 Feb 2025 00:10:55 +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=vD+h3EdbeIXXOjYpiuBHaRPqs3v/8T+UEW0NALEef5Y=; b=HaFstkj8703TcF GCjR5th/TOjN8TiZx3yb3ftPevJ0W6HtBK1+6ZnAcjBc1eyGORHtJ164Wyu91YyVHj6yRzZQDeUZn T09IQjKrRtagE7anLoiTH6PMf+RF5BQg6STyAY0rvbLwEBtVWUwj5XKVf1i3TDaGhj9FFq6t5xodO edl13xblKwrMnuqlbQwOn97nD0sG6/HEtWr+D7HIVhYdoAKWo1VIIX9oeJRxhI6+Ot1By70HdmB+F 5OKi4O4ptf5FJmalga1L6cSbIO0c1X13tQrw7DZkzzAa7rtxHA+E+0H3oSzpZBHVJxI1tV339A/g+ 3zW1vU5+uKG6MFY9nujg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thdrW-00000001vzd-0jc1; Tue, 11 Feb 2025 00:10:50 +0000 Received: from mail-wm1-f54.google.com ([209.85.128.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thbS2-00000001VU4-3Vdj for linux-riscv@lists.infradead.org; Mon, 10 Feb 2025 21:36:23 +0000 Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-43944181e68so16085415e9.0 for ; Mon, 10 Feb 2025 13:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1739223381; x=1739828181; 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=laF+WRFcEPhbPigMR+biZf/NV/ZYQNs3dPPw81Y/wsw=; b=fxR36ZxboIrccYdUHCzM/3Ghs/BhSBfhxRDYbAMeitc9TtQI+B0T+NCMeq0RUFswML /7NSlF+JuZx8vqJwDdMyAr7q78GDnuhA6xGy8KWgKak0CRL3AZ6mrID9RnlVtMdMP9x5 0dyXNZ6ZLgpC9zRni5cAwcgopdk4aEkZCoVsTCHqzU/LKITojOQ4s4a35MuV53Vwlp/V vOm5o1r8AoEY70jWNB8baHvn+B59kYNnC2iVONogmGr17OrVtXjpXkVwXjy1f+84F1bD aonmxHwqMhrF+tPwqgvx3PVhQ5K9bDPulrZe2B7Us1CmlZQhLN+DaZmnSzYDeFy+wMqU +L2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739223381; x=1739828181; 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=laF+WRFcEPhbPigMR+biZf/NV/ZYQNs3dPPw81Y/wsw=; b=Gvzk9BfMVBZWcO0vM91TEAlP9Szszjb2/sdPpOvSErBlUpxuPHggLJj5xeaM6a15kf uEWnT4bSV2qzvI4M+CChEPzCv9xcPneOn5R7t0pDxPMRasF1/v+8dFYQ1aUiBsVIO45m c7dYKkRkKi0E3ffn8Y7POUfHdDRQitgQZtAVRnIpXvIdf4e4Sj5zTZo2bIsNOeXKLbmF uUTTJ6ls0txkRw9HXjs8+Us0NmKttOANoK4Z6mKb8Mvnfij4yXnuePLP4/EubuIptpLf hLyMB3B9hwvRLFhTYdeKC5cctUB6fh/u/llHmK7QAP7HgCgMUBS2pU88+mhFGTNUL2TG wcrA== X-Forwarded-Encrypted: i=1; AJvYcCW4tIA0NXUbAUiMTyaTETg/rICWTBlarnlPaSt9XGI5yvAavNl4w6lySqRND9Wpn0jnJ+WZxsCp36aYUw==@lists.infradead.org X-Gm-Message-State: AOJu0YwDMijGS7X8XhMn8hCyBbyDa4Okxyvkf/ec2/ZI+l66BOu4jmf5 2aWCNWg3NR5z4WKWZC1IjRq9CFFbAR7oJwbkAieCayzFp7y+8NETE/efRBkSt2c= X-Gm-Gg: ASbGnctbfsgnZSWkNuaWJs/jGklykLiDHwmu4//5vVKTB1uY+zX7q8dk2K1PUQVPDg9 zopPFUc63Z/MX2uPCbZzSdlz5SGQSQ0+mjH/Q99+dDhQ9Tb4+pcyqycvG6vJqHN8exyIv8j8oil fMPNU8NoLMec1VL1TfbL5L7kPNsZ2G1w+qSHykSj/Ged4/QEwq3QQwtSimfGVUgak9+YwsodXSg qzZ3AQp3fFmx4kAo3DnCGSweRJfx7edC1aqTNbZWwvfa/e9dyo6NFv27jS1DKuMAzLMf2Aphl2W jqsz3oI+bRY/f8mk X-Google-Smtp-Source: AGHT+IFgS/HX5A+kH5PAPBrkqn8fBWMnZmlOER5QhwFIE+HweZ3IE1yWLyw44chbTe5o+iil3uYEhQ== X-Received: by 2002:a05:600c:1c07:b0:436:18d0:aa6e with SMTP id 5b1f17b1804b1-4392497d041mr163575835e9.5.1739223380954; Mon, 10 Feb 2025 13:36:20 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4394376118esm47541515e9.40.2025.02.10.13.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 13:36:20 -0800 (PST) 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 v2 13/15] RISC-V: KVM: add SBI extension reset callback Date: Mon, 10 Feb 2025 22:35:46 +0100 Message-ID: <20250210213549.1867704-14-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250210213549.1867704-1-cleger@rivosinc.com> References: <20250210213549.1867704-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250210_133622_887597_4EABFFD6 X-CRM114-Status: GOOD ( 17.72 ) 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 --- 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 44f551143498..f81f06f82650 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -540,3 +540,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,