2022-11-28 16:39:26

by Anup Patel

[permalink] [raw]
Subject: [PATCH 0/9] RISC-V KVM ONE_REG interface for SBI

This series does first does few cleanups/fixes (PATCH1 to PATCH5) and
adds ONE-REG interface for customizing the SBI interface visible to the
Guest/VM.

The testing of this series has been done with KVMTOOL changes in
riscv_sbi_imp_v1 branch at:
https://github.com/avpatel/kvmtool.git

These patches can also be found in the riscv_kvm_sbi_imp_v1 branch at:
https://github.com/avpatel/linux.git

Anup Patel (9):
RISC-V: KVM: Fix reg_val check in kvm_riscv_vcpu_set_reg_config()
RISC-V: KVM: Remove redundant includes of asm/kvm_vcpu_timer.h
RISC-V: KVM: Remove redundant includes of asm/csr.h
RISC-V: KVM: Use switch-case in kvm_riscv_vcpu_set/get_reg()
RISC-V: KVM: Move sbi related struct and functions to kvm_vcpu_sbi.h
RISC-V: Export sbi_get_mvendorid() and friends
RISC-V: KVM: Save mvendorid, marchid, and mimpid when creating VCPU
RISC-V: KVM: Add ONE_REG interface for mvendorid, marchid, and mimpid
RISC-V: KVM: Add ONE_REG interface to enable/disable SBI extensions

arch/riscv/include/asm/kvm_host.h | 16 ++-
arch/riscv/include/asm/kvm_vcpu_sbi.h | 14 ++-
arch/riscv/include/uapi/asm/kvm.h | 22 ++++
arch/riscv/kernel/sbi.c | 3 +
arch/riscv/kvm/vcpu.c | 82 +++++++++++----
arch/riscv/kvm/vcpu_sbi.c | 145 +++++++++++++++++++++++---
arch/riscv/kvm/vcpu_sbi_base.c | 15 ++-
arch/riscv/kvm/vcpu_sbi_hsm.c | 1 -
arch/riscv/kvm/vcpu_sbi_replace.c | 1 -
arch/riscv/kvm/vcpu_sbi_v01.c | 1 -
10 files changed, 244 insertions(+), 56 deletions(-)

--
2.34.1


2022-11-28 16:41:53

by Anup Patel

[permalink] [raw]
Subject: [PATCH 5/9] RISC-V: KVM: Move sbi related struct and functions to kvm_vcpu_sbi.h

Just like asm/kvm_vcpu_timer.h, we should have all sbi related struct
and functions in asm/kvm_vcpu_sbi.h.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/include/asm/kvm_host.h | 10 ++--------
arch/riscv/include/asm/kvm_vcpu_sbi.h | 6 ++++++
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
index 6502f9099965..91c74b09a970 100644
--- a/arch/riscv/include/asm/kvm_host.h
+++ b/arch/riscv/include/asm/kvm_host.h
@@ -16,6 +16,7 @@
#include <asm/hwcap.h>
#include <asm/kvm_vcpu_fp.h>
#include <asm/kvm_vcpu_insn.h>
+#include <asm/kvm_vcpu_sbi.h>
#include <asm/kvm_vcpu_timer.h>

#define KVM_MAX_VCPUS 1024
@@ -94,10 +95,6 @@ struct kvm_arch {
struct kvm_guest_timer timer;
};

-struct kvm_sbi_context {
- int return_handled;
-};
-
struct kvm_cpu_trap {
unsigned long sepc;
unsigned long scause;
@@ -216,7 +213,7 @@ struct kvm_vcpu_arch {
struct kvm_csr_decode csr_decode;

/* SBI context */
- struct kvm_sbi_context sbi_context;
+ struct kvm_vcpu_sbi_context sbi_context;

/* Cache pages needed to program page tables with spinlock held */
struct kvm_mmu_memory_cache mmu_page_cache;
@@ -326,7 +323,4 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, unsigned long mask);
void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu);
void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu);

-int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
-int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
-
#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 d4e3e600beef..f79478a85d2d 100644
--- a/arch/riscv/include/asm/kvm_vcpu_sbi.h
+++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h
@@ -14,6 +14,10 @@
#define KVM_SBI_VERSION_MAJOR 1
#define KVM_SBI_VERSION_MINOR 0

+struct kvm_vcpu_sbi_context {
+ int return_handled;
+};
+
struct kvm_vcpu_sbi_extension {
unsigned long extid_start;
unsigned long extid_end;
@@ -31,7 +35,9 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
struct kvm_run *run,
u32 type, u64 flags);
+int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long extid);
+int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);

#ifdef CONFIG_RISCV_SBI_V01
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01;
--
2.34.1

2022-11-28 16:44:45

by Anup Patel

[permalink] [raw]
Subject: [PATCH 2/9] RISC-V: KVM: Remove redundant includes of asm/kvm_vcpu_timer.h

The asm/kvm_vcpu_timer.h is redundantly included in vcpu_sbi_base.c
so let us remove it.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/kvm/vcpu_sbi_base.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
index 48f431091cdb..22b9126e2872 100644
--- a/arch/riscv/kvm/vcpu_sbi_base.c
+++ b/arch/riscv/kvm/vcpu_sbi_base.c
@@ -12,7 +12,6 @@
#include <linux/version.h>
#include <asm/csr.h>
#include <asm/sbi.h>
-#include <asm/kvm_vcpu_timer.h>
#include <asm/kvm_vcpu_sbi.h>

static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
--
2.34.1

2022-11-28 17:09:29

by Anup Patel

[permalink] [raw]
Subject: [PATCH 3/9] RISC-V: KVM: Remove redundant includes of asm/csr.h

We should include asm/csr.h only where required so let us remove
redundant includes of this header.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/include/asm/kvm_host.h | 1 -
arch/riscv/kvm/vcpu_sbi_base.c | 1 -
arch/riscv/kvm/vcpu_sbi_hsm.c | 1 -
arch/riscv/kvm/vcpu_sbi_replace.c | 1 -
arch/riscv/kvm/vcpu_sbi_v01.c | 1 -
5 files changed, 5 deletions(-)

diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
index dbbf43d52623..6502f9099965 100644
--- a/arch/riscv/include/asm/kvm_host.h
+++ b/arch/riscv/include/asm/kvm_host.h
@@ -13,7 +13,6 @@
#include <linux/kvm.h>
#include <linux/kvm_types.h>
#include <linux/spinlock.h>
-#include <asm/csr.h>
#include <asm/hwcap.h>
#include <asm/kvm_vcpu_fp.h>
#include <asm/kvm_vcpu_insn.h>
diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
index 22b9126e2872..0c806f61c629 100644
--- a/arch/riscv/kvm/vcpu_sbi_base.c
+++ b/arch/riscv/kvm/vcpu_sbi_base.c
@@ -10,7 +10,6 @@
#include <linux/err.h>
#include <linux/kvm_host.h>
#include <linux/version.h>
-#include <asm/csr.h>
#include <asm/sbi.h>
#include <asm/kvm_vcpu_sbi.h>

diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
index 239dec0a628a..2e915cafd551 100644
--- a/arch/riscv/kvm/vcpu_sbi_hsm.c
+++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
@@ -9,7 +9,6 @@
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/kvm_host.h>
-#include <asm/csr.h>
#include <asm/sbi.h>
#include <asm/kvm_vcpu_sbi.h>

diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
index 4c034d8a606a..03a0198389f0 100644
--- a/arch/riscv/kvm/vcpu_sbi_replace.c
+++ b/arch/riscv/kvm/vcpu_sbi_replace.c
@@ -9,7 +9,6 @@
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/kvm_host.h>
-#include <asm/csr.h>
#include <asm/sbi.h>
#include <asm/kvm_vcpu_timer.h>
#include <asm/kvm_vcpu_sbi.h>
diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c
index 8a91a14e7139..489f225ee66d 100644
--- a/arch/riscv/kvm/vcpu_sbi_v01.c
+++ b/arch/riscv/kvm/vcpu_sbi_v01.c
@@ -9,7 +9,6 @@
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/kvm_host.h>
-#include <asm/csr.h>
#include <asm/sbi.h>
#include <asm/kvm_vcpu_timer.h>
#include <asm/kvm_vcpu_sbi.h>
--
2.34.1

2022-11-28 17:28:40

by Anup Patel

[permalink] [raw]
Subject: [PATCH 6/9] RISC-V: Export sbi_get_mvendorid() and friends

The sbi_get_mvendorid(), sbi_get_marchid(), and sbi_get_mimpid()
can be used by KVM module so let us export these functions.

Signed-off-by: Anup Patel <[email protected]>
---
arch/riscv/kernel/sbi.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 775d3322b422..5c87db8fdff2 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
{
return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
}
+EXPORT_SYMBOL_GPL(sbi_get_mvendorid);

long sbi_get_marchid(void)
{
return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
}
+EXPORT_SYMBOL_GPL(sbi_get_marchid);

long sbi_get_mimpid(void)
{
return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
}
+EXPORT_SYMBOL_GPL(sbi_get_mimpid);

static void sbi_send_cpumask_ipi(const struct cpumask *target)
{
--
2.34.1

2022-11-28 21:26:06

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH 5/9] RISC-V: KVM: Move sbi related struct and functions to kvm_vcpu_sbi.h

On Mon, Nov 28, 2022 at 8:14 AM Anup Patel <[email protected]> wrote:
>
> Just like asm/kvm_vcpu_timer.h, we should have all sbi related struct
> and functions in asm/kvm_vcpu_sbi.h.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/include/asm/kvm_host.h | 10 ++--------
> arch/riscv/include/asm/kvm_vcpu_sbi.h | 6 ++++++
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
> index 6502f9099965..91c74b09a970 100644
> --- a/arch/riscv/include/asm/kvm_host.h
> +++ b/arch/riscv/include/asm/kvm_host.h
> @@ -16,6 +16,7 @@
> #include <asm/hwcap.h>
> #include <asm/kvm_vcpu_fp.h>
> #include <asm/kvm_vcpu_insn.h>
> +#include <asm/kvm_vcpu_sbi.h>
> #include <asm/kvm_vcpu_timer.h>
>
> #define KVM_MAX_VCPUS 1024
> @@ -94,10 +95,6 @@ struct kvm_arch {
> struct kvm_guest_timer timer;
> };
>
> -struct kvm_sbi_context {
> - int return_handled;
> -};
> -
> struct kvm_cpu_trap {
> unsigned long sepc;
> unsigned long scause;
> @@ -216,7 +213,7 @@ struct kvm_vcpu_arch {
> struct kvm_csr_decode csr_decode;
>
> /* SBI context */
> - struct kvm_sbi_context sbi_context;
> + struct kvm_vcpu_sbi_context sbi_context;
>
> /* Cache pages needed to program page tables with spinlock held */
> struct kvm_mmu_memory_cache mmu_page_cache;
> @@ -326,7 +323,4 @@ bool kvm_riscv_vcpu_has_interrupts(struct kvm_vcpu *vcpu, unsigned long mask);
> void kvm_riscv_vcpu_power_off(struct kvm_vcpu *vcpu);
> void kvm_riscv_vcpu_power_on(struct kvm_vcpu *vcpu);
>
> -int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
> -int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
> -
> #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 d4e3e600beef..f79478a85d2d 100644
> --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h
> +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h
> @@ -14,6 +14,10 @@
> #define KVM_SBI_VERSION_MAJOR 1
> #define KVM_SBI_VERSION_MINOR 0
>
> +struct kvm_vcpu_sbi_context {
> + int return_handled;
> +};
> +
> struct kvm_vcpu_sbi_extension {
> unsigned long extid_start;
> unsigned long extid_end;
> @@ -31,7 +35,9 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run);
> void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu,
> struct kvm_run *run,
> u32 type, u64 flags);
> +int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run);
> const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long extid);
> +int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run);
>
> #ifdef CONFIG_RISCV_SBI_V01
> extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01;
> --
> 2.34.1
>


Reviewed-by: Atish Patra <[email protected]>
--
Regards,
Atish

2022-11-28 21:26:32

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH 2/9] RISC-V: KVM: Remove redundant includes of asm/kvm_vcpu_timer.h

On Mon, Nov 28, 2022 at 8:14 AM Anup Patel <[email protected]> wrote:
>
> The asm/kvm_vcpu_timer.h is redundantly included in vcpu_sbi_base.c
> so let us remove it.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/kvm/vcpu_sbi_base.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
> index 48f431091cdb..22b9126e2872 100644
> --- a/arch/riscv/kvm/vcpu_sbi_base.c
> +++ b/arch/riscv/kvm/vcpu_sbi_base.c
> @@ -12,7 +12,6 @@
> #include <linux/version.h>
> #include <asm/csr.h>
> #include <asm/sbi.h>
> -#include <asm/kvm_vcpu_timer.h>
> #include <asm/kvm_vcpu_sbi.h>
>
> static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> --
> 2.34.1
>

Reviewed-by: Atish Patra <[email protected]>

--
Regards,
Atish

2022-11-28 21:27:21

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH 6/9] RISC-V: Export sbi_get_mvendorid() and friends

On Mon, Nov 28, 2022 at 8:14 AM Anup Patel <[email protected]> wrote:
>
> The sbi_get_mvendorid(), sbi_get_marchid(), and sbi_get_mimpid()
> can be used by KVM module so let us export these functions.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/kernel/sbi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index 775d3322b422..5c87db8fdff2 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_mvendorid);
>
> long sbi_get_marchid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_marchid);
>
> long sbi_get_mimpid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_mimpid);
>
> static void sbi_send_cpumask_ipi(const struct cpumask *target)
> {
> --
> 2.34.1
>

Reviewed-by: Atish Patra <[email protected]>

--
Regards,
Atish

2022-11-28 21:42:57

by Atish Patra

[permalink] [raw]
Subject: Re: [PATCH 3/9] RISC-V: KVM: Remove redundant includes of asm/csr.h

On Mon, Nov 28, 2022 at 8:14 AM Anup Patel <[email protected]> wrote:
>
> We should include asm/csr.h only where required so let us remove
> redundant includes of this header.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/include/asm/kvm_host.h | 1 -
> arch/riscv/kvm/vcpu_sbi_base.c | 1 -
> arch/riscv/kvm/vcpu_sbi_hsm.c | 1 -
> arch/riscv/kvm/vcpu_sbi_replace.c | 1 -
> arch/riscv/kvm/vcpu_sbi_v01.c | 1 -
> 5 files changed, 5 deletions(-)
>
> diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h
> index dbbf43d52623..6502f9099965 100644
> --- a/arch/riscv/include/asm/kvm_host.h
> +++ b/arch/riscv/include/asm/kvm_host.h
> @@ -13,7 +13,6 @@
> #include <linux/kvm.h>
> #include <linux/kvm_types.h>
> #include <linux/spinlock.h>
> -#include <asm/csr.h>
> #include <asm/hwcap.h>
> #include <asm/kvm_vcpu_fp.h>
> #include <asm/kvm_vcpu_insn.h>
> diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
> index 22b9126e2872..0c806f61c629 100644
> --- a/arch/riscv/kvm/vcpu_sbi_base.c
> +++ b/arch/riscv/kvm/vcpu_sbi_base.c
> @@ -10,7 +10,6 @@
> #include <linux/err.h>
> #include <linux/kvm_host.h>
> #include <linux/version.h>
> -#include <asm/csr.h>
> #include <asm/sbi.h>
> #include <asm/kvm_vcpu_sbi.h>
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c
> index 239dec0a628a..2e915cafd551 100644
> --- a/arch/riscv/kvm/vcpu_sbi_hsm.c
> +++ b/arch/riscv/kvm/vcpu_sbi_hsm.c
> @@ -9,7 +9,6 @@
> #include <linux/errno.h>
> #include <linux/err.h>
> #include <linux/kvm_host.h>
> -#include <asm/csr.h>
> #include <asm/sbi.h>
> #include <asm/kvm_vcpu_sbi.h>
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c
> index 4c034d8a606a..03a0198389f0 100644
> --- a/arch/riscv/kvm/vcpu_sbi_replace.c
> +++ b/arch/riscv/kvm/vcpu_sbi_replace.c
> @@ -9,7 +9,6 @@
> #include <linux/errno.h>
> #include <linux/err.h>
> #include <linux/kvm_host.h>
> -#include <asm/csr.h>
> #include <asm/sbi.h>
> #include <asm/kvm_vcpu_timer.h>
> #include <asm/kvm_vcpu_sbi.h>
> diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c
> index 8a91a14e7139..489f225ee66d 100644
> --- a/arch/riscv/kvm/vcpu_sbi_v01.c
> +++ b/arch/riscv/kvm/vcpu_sbi_v01.c
> @@ -9,7 +9,6 @@
> #include <linux/errno.h>
> #include <linux/err.h>
> #include <linux/kvm_host.h>
> -#include <asm/csr.h>
> #include <asm/sbi.h>
> #include <asm/kvm_vcpu_timer.h>
> #include <asm/kvm_vcpu_sbi.h>
> --
> 2.34.1
>

Reviewed-by: Atish Patra <[email protected]>

--
Regards,
Atish

2022-11-29 05:30:01

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH 6/9] RISC-V: Export sbi_get_mvendorid() and friends

On Mon, Nov 28, 2022 at 09:44:21PM +0530, Anup Patel wrote:
> The sbi_get_mvendorid(), sbi_get_marchid(), and sbi_get_mimpid()
> can be used by KVM module so let us export these functions.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/kernel/sbi.c | 3 +++
> 1 file changed, 3 insertions(+)
>

Reviewed-by: Andrew Jones <[email protected]>

2022-11-29 05:47:35

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH 5/9] RISC-V: KVM: Move sbi related struct and functions to kvm_vcpu_sbi.h

On Mon, Nov 28, 2022 at 09:44:20PM +0530, Anup Patel wrote:
> Just like asm/kvm_vcpu_timer.h, we should have all sbi related struct
> and functions in asm/kvm_vcpu_sbi.h.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/include/asm/kvm_host.h | 10 ++--------
> arch/riscv/include/asm/kvm_vcpu_sbi.h | 6 ++++++
> 2 files changed, 8 insertions(+), 8 deletions(-)
>

Reviewed-by: Andrew Jones <[email protected]>

2022-11-29 06:10:30

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH 2/9] RISC-V: KVM: Remove redundant includes of asm/kvm_vcpu_timer.h

On Mon, Nov 28, 2022 at 09:44:17PM +0530, Anup Patel wrote:
> The asm/kvm_vcpu_timer.h is redundantly included in vcpu_sbi_base.c
> so let us remove it.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/kvm/vcpu_sbi_base.c | 1 -
> 1 file changed, 1 deletion(-)
>
> diff --git a/arch/riscv/kvm/vcpu_sbi_base.c b/arch/riscv/kvm/vcpu_sbi_base.c
> index 48f431091cdb..22b9126e2872 100644
> --- a/arch/riscv/kvm/vcpu_sbi_base.c
> +++ b/arch/riscv/kvm/vcpu_sbi_base.c
> @@ -12,7 +12,6 @@
> #include <linux/version.h>
> #include <asm/csr.h>
> #include <asm/sbi.h>
> -#include <asm/kvm_vcpu_timer.h>
> #include <asm/kvm_vcpu_sbi.h>
>
> static int kvm_sbi_ext_base_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
> --
> 2.34.1
>

Reviewed-by: Andrew Jones <[email protected]>

2022-12-02 18:16:07

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH 6/9] RISC-V: Export sbi_get_mvendorid() and friends

On Mon, 28 Nov 2022 08:14:21 PST (-0800), [email protected] wrote:
> The sbi_get_mvendorid(), sbi_get_marchid(), and sbi_get_mimpid()
> can be used by KVM module so let us export these functions.
>
> Signed-off-by: Anup Patel <[email protected]>
> ---
> arch/riscv/kernel/sbi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index 775d3322b422..5c87db8fdff2 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_mvendorid);
>
> long sbi_get_marchid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_marchid);
>
> long sbi_get_mimpid(void)
> {
> return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
> }
> +EXPORT_SYMBOL_GPL(sbi_get_mimpid);
>
> static void sbi_send_cpumask_ipi(const struct cpumask *target)
> {

Acked-by: Palmer Dabbelt <[email protected]>

2022-12-03 13:17:35

by Anup Patel

[permalink] [raw]
Subject: Re: [PATCH 0/9] RISC-V KVM ONE_REG interface for SBI

On Mon, Nov 28, 2022 at 9:44 PM Anup Patel <[email protected]> wrote:
>
> This series does first does few cleanups/fixes (PATCH1 to PATCH5) and
> adds ONE-REG interface for customizing the SBI interface visible to the
> Guest/VM.
>
> The testing of this series has been done with KVMTOOL changes in
> riscv_sbi_imp_v1 branch at:
> https://github.com/avpatel/kvmtool.git
>
> These patches can also be found in the riscv_kvm_sbi_imp_v1 branch at:
> https://github.com/avpatel/linux.git
>
> Anup Patel (9):
> RISC-V: KVM: Fix reg_val check in kvm_riscv_vcpu_set_reg_config()
> RISC-V: KVM: Remove redundant includes of asm/kvm_vcpu_timer.h
> RISC-V: KVM: Remove redundant includes of asm/csr.h
> RISC-V: KVM: Use switch-case in kvm_riscv_vcpu_set/get_reg()
> RISC-V: KVM: Move sbi related struct and functions to kvm_vcpu_sbi.h
> RISC-V: Export sbi_get_mvendorid() and friends
> RISC-V: KVM: Save mvendorid, marchid, and mimpid when creating VCPU
> RISC-V: KVM: Add ONE_REG interface for mvendorid, marchid, and mimpid
> RISC-V: KVM: Add ONE_REG interface to enable/disable SBI extensions

I have queued PATCH1 to PATCH8 for Linux-6.2.

I have deferred PATCH9 until we have an agreement about how to deal
with VM-level attributes. This is also required for the KVM SBI PMU series.

>
> arch/riscv/include/asm/kvm_host.h | 16 ++-
> arch/riscv/include/asm/kvm_vcpu_sbi.h | 14 ++-
> arch/riscv/include/uapi/asm/kvm.h | 22 ++++
> arch/riscv/kernel/sbi.c | 3 +
> arch/riscv/kvm/vcpu.c | 82 +++++++++++----
> arch/riscv/kvm/vcpu_sbi.c | 145 +++++++++++++++++++++++---
> arch/riscv/kvm/vcpu_sbi_base.c | 15 ++-
> arch/riscv/kvm/vcpu_sbi_hsm.c | 1 -
> arch/riscv/kvm/vcpu_sbi_replace.c | 1 -
> arch/riscv/kvm/vcpu_sbi_v01.c | 1 -
> 10 files changed, 244 insertions(+), 56 deletions(-)
>
> --
> 2.34.1
>

Thanks,
Anup

2022-12-09 04:48:27

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH 6/9] RISC-V: Export sbi_get_mvendorid() and friends

On Mon, 28 Nov 2022 13:07:27 PST (-0800), [email protected] wrote:
> On Mon, Nov 28, 2022 at 8:14 AM Anup Patel <[email protected]> wrote:
>>
>> The sbi_get_mvendorid(), sbi_get_marchid(), and sbi_get_mimpid()
>> can be used by KVM module so let us export these functions.
>>
>> Signed-off-by: Anup Patel <[email protected]>
>> ---
>> arch/riscv/kernel/sbi.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
>> index 775d3322b422..5c87db8fdff2 100644
>> --- a/arch/riscv/kernel/sbi.c
>> +++ b/arch/riscv/kernel/sbi.c
>> @@ -627,16 +627,19 @@ long sbi_get_mvendorid(void)
>> {
>> return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID);
>> }
>> +EXPORT_SYMBOL_GPL(sbi_get_mvendorid);
>>
>> long sbi_get_marchid(void)
>> {
>> return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID);
>> }
>> +EXPORT_SYMBOL_GPL(sbi_get_marchid);
>>
>> long sbi_get_mimpid(void)
>> {
>> return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID);
>> }
>> +EXPORT_SYMBOL_GPL(sbi_get_mimpid);
>>
>> static void sbi_send_cpumask_ipi(const struct cpumask *target)
>> {
>> --
>> 2.34.1
>>
>
> Reviewed-by: Atish Patra <[email protected]>

Acked-by: Palmer Dabbelt <[email protected]>