From: Andrew Jones <ajones@ventanamicro.com>
To: Anup Patel <apatel@ventanamicro.com>
Cc: Atish Patra <atish.patra@linux.dev>,
Palmer Dabbelt <palmer@dabbelt.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Alexandre Ghiti <alex@ghiti.fr>,
Paolo Bonzini <pbonzini@redhat.com>,
Shuah Khan <shuah@kernel.org>, Anup Patel <anup@brainfault.org>,
kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 1/4] RISC-V: KVM: Convert kvm_riscv_vcpu_sbi_forward() into extension handler
Date: Fri, 17 Oct 2025 11:14:22 -0500 [thread overview]
Message-ID: <20251017-161e4ec373e5f7c41364a4d3@orel> (raw)
In-Reply-To: <20251017155925.361560-2-apatel@ventanamicro.com>
On Fri, Oct 17, 2025 at 09:29:22PM +0530, Anup Patel wrote:
> All uses of kvm_riscv_vcpu_sbi_forward() also updates retdata->uexit so
> to further reduce code duplication move retdata->uexit assignment to
> kvm_riscv_vcpu_sbi_forward() and convert it into SBI extension handler.
>
> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
> ---
> arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 +++-
> arch/riscv/kvm/vcpu_sbi.c | 6 +++++-
> arch/riscv/kvm/vcpu_sbi_base.c | 20 +++-----------------
> arch/riscv/kvm/vcpu_sbi_replace.c | 27 +--------------------------
> arch/riscv/kvm/vcpu_sbi_system.c | 4 +---
> arch/riscv/kvm/vcpu_sbi_v01.c | 3 +--
> 6 files changed, 14 insertions(+), 50 deletions(-)
>
> diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h
> index 3497489e04db..446f4a8eb3cd 100644
> --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h
> +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h
> @@ -69,7 +69,9 @@ struct kvm_vcpu_sbi_extension {
> unsigned long reg_size, const void *reg_val);
> };
>
> -void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
> +int kvm_riscv_vcpu_sbi_forward_handler(struct kvm_vcpu *vcpu,
> + struct kvm_run *run,
> + struct kvm_vcpu_sbi_return *retdata);
> void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
> struct kvm_run *run,
> u32 type, u64 flags);
> diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c
> index 1b13623380e1..fd4106c276d8 100644
> --- a/arch/riscv/kvm/vcpu_sbi.c
> +++ b/arch/riscv/kvm/vcpu_sbi.c
> @@ -120,7 +120,9 @@ static bool riscv_vcpu_supports_sbi_ext(struct kvm_vcpu *vcpu, int idx)
> return sext && scontext->ext_status[sext->ext_idx] != KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE;
> }
>
> -void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run)
> +int kvm_riscv_vcpu_sbi_forward_handler(struct kvm_vcpu *vcpu,
> + struct kvm_run *run,
> + struct kvm_vcpu_sbi_return *retdata)
> {
> struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
>
> @@ -137,6 +139,8 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run)
> run->riscv_sbi.args[5] = cp->a5;
> run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED;
> run->riscv_sbi.ret[1] = 0;
> + retdata->uexit = true;
> + return 0;
> }
>
> void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
> diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
> index 5bc570b984f4..ca489f2dfbdf 100644
> --- a/arch/riscv/kvm/vcpu_sbi_base.c
> +++ b/arch/riscv/kvm/vcpu_sbi_base.c
> @@ -41,8 +41,7 @@ static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> * For experimental/vendor extensions
> * forward it to the userspace
> */
> - kvm_riscv_vcpu_sbi_forward(vcpu, run);
> - retdata->uexit = true;
> + return kvm_riscv_vcpu_sbi_forward_handler(vcpu, run, retdata);
> } else {
> sbi_ext = kvm_vcpu_sbi_find_ext(vcpu, cp->a0);
> *out_val = sbi_ext && sbi_ext->probe ?
> @@ -72,27 +71,14 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base = {
> .handler = kvm_sbi_ext_base_handler,
> };
>
> -static int kvm_sbi_ext_forward_handler(struct kvm_vcpu *vcpu,
> - struct kvm_run *run,
> - struct kvm_vcpu_sbi_return *retdata)
> -{
> - /*
> - * Both SBI experimental and vendor extensions are
> - * unconditionally forwarded to userspace.
> - */
> - kvm_riscv_vcpu_sbi_forward(vcpu, run);
> - retdata->uexit = true;
> - return 0;
> -}
> -
> const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental = {
> .extid_start = SBI_EXT_EXPERIMENTAL_START,
> .extid_end = SBI_EXT_EXPERIMENTAL_END,
> - .handler = kvm_sbi_ext_forward_handler,
> + .handler = kvm_riscv_vcpu_sbi_forward_handler,
> };
>
> const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor = {
> .extid_start = SBI_EXT_VENDOR_START,
> .extid_end = SBI_EXT_VENDOR_END,
> - .handler = kvm_sbi_ext_forward_handler,
> + .handler = kvm_riscv_vcpu_sbi_forward_handler,
> };
> diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
> index b490ed1428a6..2c456e26f6ca 100644
> --- a/arch/riscv/kvm/vcpu_sbi_replace.c
> +++ b/arch/riscv/kvm/vcpu_sbi_replace.c
> @@ -186,34 +186,9 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst = {
> .handler = kvm_sbi_ext_srst_handler,
> };
>
> -static int kvm_sbi_ext_dbcn_handler(struct kvm_vcpu *vcpu,
> - struct kvm_run *run,
> - struct kvm_vcpu_sbi_return *retdata)
> -{
> - struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
> - unsigned long funcid = cp->a6;
> -
> - switch (funcid) {
> - case SBI_EXT_DBCN_CONSOLE_WRITE:
> - case SBI_EXT_DBCN_CONSOLE_READ:
> - case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
> - /*
> - * The SBI debug console functions are unconditionally
> - * forwarded to the userspace.
> - */
> - kvm_riscv_vcpu_sbi_forward(vcpu, run);
> - retdata->uexit = true;
> - break;
> - default:
> - retdata->err_val = SBI_ERR_NOT_SUPPORTED;
> - }
> -
> - return 0;
> -}
> -
> const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn = {
> .extid_start = SBI_EXT_DBCN,
> .extid_end = SBI_EXT_DBCN,
> .default_disabled = true,
> - .handler = kvm_sbi_ext_dbcn_handler,
> + .handler = kvm_riscv_vcpu_sbi_forward_handler,
> };
> diff --git a/arch/riscv/kvm/vcpu_sbi_system.c b/arch/riscv/kvm/vcpu_sbi_system.c
> index 359be90b0fc5..c6f7e609ac79 100644
> --- a/arch/riscv/kvm/vcpu_sbi_system.c
> +++ b/arch/riscv/kvm/vcpu_sbi_system.c
> @@ -47,9 +47,7 @@ static int kvm_sbi_ext_susp_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> kvm_riscv_vcpu_sbi_request_reset(vcpu, cp->a1, cp->a2);
>
> /* userspace provides the suspend implementation */
> - kvm_riscv_vcpu_sbi_forward(vcpu, run);
> - retdata->uexit = true;
> - break;
> + return kvm_riscv_vcpu_sbi_forward_handler(vcpu, run, retdata);
> default:
> retdata->err_val = SBI_ERR_NOT_SUPPORTED;
> break;
> diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c
> index 368dfddd23d9..188d5ea5b3b8 100644
> --- a/arch/riscv/kvm/vcpu_sbi_v01.c
> +++ b/arch/riscv/kvm/vcpu_sbi_v01.c
> @@ -32,8 +32,7 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> * The CONSOLE_GETCHAR/CONSOLE_PUTCHAR SBI calls cannot be
> * handled in kernel so we forward these to user-space
> */
> - kvm_riscv_vcpu_sbi_forward(vcpu, run);
> - retdata->uexit = true;
> + ret = kvm_riscv_vcpu_sbi_forward_handler(vcpu, run, retdata);
> break;
> case SBI_EXT_0_1_SET_TIMER:
> #if __riscv_xlen == 32
> --
> 2.43.0
>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
next prev parent reply other threads:[~2025-10-17 16:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 15:59 [PATCH 0/4] SBI MPXY support for KVM Guest Anup Patel
2025-10-17 15:59 ` [PATCH 1/4] RISC-V: KVM: Convert kvm_riscv_vcpu_sbi_forward() into extension handler Anup Patel
2025-10-17 16:14 ` Andrew Jones [this message]
2025-10-17 15:59 ` [PATCH 2/4] RISC-V: KVM: Add separate source for forwarded SBI extensions Anup Patel
2025-10-17 16:17 ` Andrew Jones
2025-10-17 15:59 ` [PATCH 3/4] RISC-V: KVM: Add SBI MPXY extension support for Guest Anup Patel
2025-10-17 16:20 ` Andrew Jones
2025-10-17 15:59 ` [PATCH 4/4] KVM: riscv: selftests: Add SBI MPXY extension to get-reg-list Anup Patel
2025-10-17 16:20 ` Andrew Jones
2025-10-27 3:38 ` [PATCH 0/4] SBI MPXY support for KVM Guest Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251017-161e4ec373e5f7c41364a4d3@orel \
--to=ajones@ventanamicro.com \
--cc=alex@ghiti.fr \
--cc=anup@brainfault.org \
--cc=apatel@ventanamicro.com \
--cc=atish.patra@linux.dev \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=pbonzini@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox