RISC-V: Add steal-time support
Subsystems (6)
cover RISC-V: Add steal-time support
One frequently touted benefit of virtualization is the ability to consolidate machines, increasing resource utilization. It may even be desirable to overcommit, at the risk of one or more VCPUs having to wait. Hypervisors which have interfaces for guests to retrieve the amount of time each VCPU had to wait give observers within the guests ways to account for less progress than would otherwise be expected. The SBI STA extension proposal[1] provides a standard interface for guest VCPUs to retrieve the amount of time "stolen".
This series has three parts:
1) Patches 01-04 - Add paravirt support to RISC-V and implement steal-time accounting support using the SBI STA extension.
2) Patches 05-10 - Implement SBI STA in KVM so KVM guests, such as Linux guests which enable the paravirt steal-time support, can be enlightened about stolen time.
3) Patches 11-12 - Add support to the KVM selftests steal_time test for RISC-V.
Note, while we can review and revise this series now, we'll keep the RFC tag and refrain from merging it until the proposed SBI extension has been ratified.
[1] https://lists.riscv.org/g/tech-prs/message/401
This patches are also available here
https://github.com/jones-drew/linux/commits/kvm/steal-time-rfc-v1
Thanks,
drew
Andrew Jones (14):
RISC-V: paravirt: Add skeleton for pv-time support
RISC-V: Add SBI STA extension definitions
RISC-V: paravirt: Implement steal-time support
RISC-V: paravirt: Add kconfigs
RISC-V: KVM: Add SBI STA extension skeleton
RISC-V: KVM: Add steal-update vcpu request
RISC-V: KVM: Add SBI STA info to vcpu_arch
RISC-V: KVM: Implement SBI STA extension
RISC-V: KVM: Add support for SBI extension registers
RISC-V: KVM: Add support for SBI STA registers
KVM: selftests: riscv: Move sbi_ecall to processor.c
KVM: selftests: riscv: Add guest_sbi_probe_extension
KVM: selftests: riscv: Add RISCV_SBI_EXT_REG
KVM: selftests: riscv: Add steal_time test support
.../admin-guide/kernel-parameters.txt | 6 +- arch/riscv/Kconfig | 19 ++ arch/riscv/include/asm/kvm_host.h | 9 + arch/riscv/include/asm/kvm_vcpu_sbi.h | 5 + arch/riscv/include/asm/paravirt.h | 29 +++ arch/riscv/include/asm/paravirt_api_clock.h | 1 + arch/riscv/include/asm/sbi.h | 15 ++ arch/riscv/include/uapi/asm/kvm.h | 14 ++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/paravirt.c | 127 +++++++++++ arch/riscv/kernel/time.c | 3 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu.c | 74 +++++++ arch/riscv/kvm/vcpu_sbi.c | 4 + arch/riscv/kvm/vcpu_sbi_sta.c | 199 ++++++++++++++++++ tools/testing/selftests/kvm/Makefile | 3 +- .../selftests/kvm/include/riscv/processor.h | 40 +++- .../selftests/kvm/lib/riscv/processor.c | 45 ++++ tools/testing/selftests/kvm/lib/riscv/ucall.c | 26 --- tools/testing/selftests/kvm/steal_time.c | 100 +++++++++ 21 files changed, 685 insertions(+), 37 deletions(-) create mode 100644 arch/riscv/include/asm/paravirt.h create mode 100644 arch/riscv/include/asm/paravirt_api_clock.h create mode 100644 arch/riscv/kernel/paravirt.c create mode 100644 arch/riscv/kvm/vcpu_sbi_sta.c
Signature · 1 line
2.39.2
RFC PATCH 1/14 RISC-V: paravirt: Add skeleton for pv-time support
Add the files and functions needed to support paravirt time on RISC-V. Also include the common code needed for the first application of pv-time, which is steal-time. In the next patches we'll complete the functions to fully enable steal-time support.
--- .../admin-guide/kernel-parameters.txt | 6 +- arch/riscv/include/asm/paravirt.h | 29 +++++++ arch/riscv/include/asm/paravirt_api_clock.h | 1 + arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/paravirt.c | 77 +++++++++++++++++++ arch/riscv/kernel/time.c | 3 + 6 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/include/asm/paravirt.h create mode 100644 arch/riscv/include/asm/paravirt_api_clock.h create mode 100644 arch/riscv/kernel/paravirt.c
Documentation/admin-guide/kernel-parameters.txt +3 -3
@@ -3791,9 +3791,9 @@ [X86,PV_OPS] Disable paravirtualized VMware scheduler clock and use the default one. - no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES] Disable paravirtualized - steal time accounting. steal time is computed, but - won't influence scheduler behaviour + no-steal-acc [X86,PV_OPS,ARM64,PPC/PSERIES,RISCV] Disable + paravirtualized steal time accounting. steal time is + computed, but won't influence scheduler behaviour nolapic [X86-32,APIC] Do not enable or use the local APIC.
arch/riscv/include/asm/paravirt.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_PARAVIRT_H +#define _ASM_RISCV_PARAVIRT_H + +#ifdef CONFIG_PARAVIRT +#include <linux/static_call_types.h> + +struct static_key ; +extern struct static_key paravirt_steal_enabled; +extern struct static_key paravirt_steal_rq_enabled; + +u64 dummy_steal_clock (int cpu); + +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock); + +static inline u64 paravirt_steal_clock (int cpu) +{ +return static_call (pv_steal_clock)(cpu); +} + +int __init pv_time_init (void ); + +#else + +#define pv_time_init () do {} while (0) + +#endif // CONFIG_PARAVIRT + +#endif
arch/riscv/include/asm/paravirt_api_clock.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm/paravirt.h>
arch/riscv/kernel/Makefile +1 -0
@@ -77,6 +77,7 @@ ifeq ($(CONFIG_RISCV_SBI), y) obj-$(CONFIG_SMP) += cpu_ops_sbi.o endif obj-$(CONFIG_HOTPLUG_CPU) += cpu-hotplug.o +obj-$(CONFIG_PARAVIRT) += paravirt.o obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KEXEC_CORE) += kexec_relocate.o crash_save_regs.o machine_kexec.o obj-$(CONFIG_KEXEC_FILE) += elf_kexec.o machine_kexec_file.o
arch/riscv/kernel/paravirt.c new file +77 -0
77 lines not on this page · raw message
arch/riscv/kernel/time.c +3 -0
@@ -11,6 +11,7 @@#include <asm/sbi.h> #include <asm/processor.h> #include <asm/timex.h> +#include <asm/paravirt.h> unsigned long riscv_timebase__ro_after_init ;EXPORT_SYMBOL_GPL (riscv_timebase);
@@ -32,4 +33,6 @@ void __init time_init(void)timer_probe ();tick_setup_hrtimer_broadcast (); + +pv_time_init (); }
Signature · 1 line
2.39.2
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
In reply to Andrew JonesThe SBI STA extension enables steal-time accounting. Add the definitions it specifies.
--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/riscv/include/asm/sbi.h +15 -0
@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , +SBI_EXT_STA =0x535441 ,/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal; +u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
Signature · 1 line
2.39.2
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 13 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/riscv/include/asm/sbi.h +0
-0
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 4 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,
What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
Anyways, this does match the docs - but I'm quite hesitant to leave an R-b when it's not merged yet.
Cheers,
Conor.
Quoted 32 lines
arch/riscv/include/asm/sbi.h +14
-0/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal; +u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7fSignature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list linux-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kvm-riscv/attachments/20230418/725fa408/attachment-0001.sig>
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Quoted 12 lines
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 9 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
I don't believe there's an established order. I've been going for spec order, I think.
Quoted 3 lines
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
I think I need to wait until it's been ratified.
Quoted 3 lines
Anyways, this does match the docs - but I'm quite hesitant to leave an R-b when it's not merged yet.
I could take your R-b now, and then if the spec changes, I'd drop it when reposting the PoC after reworking it.
Thanks,
drew
Quoted 36 lines
Cheers,
Conor.Quoted 32 lines
arch/riscv/include/asm/sbi.h +14
-0/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal; +u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7fSignature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list linux-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 30 lines · Andrew Jones
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Quoted 12 lines
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 9 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
I don't believe there's an established order. I've been going for spec order, I think.
Quoted 3 lines
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
Quoted 8 lines
I think I need to wait until it's been ratified.
Quoted 3 lines
Anyways, this does match the docs - but I'm quite hesitant to leave an R-b when it's not merged yet.
I could take your R-b now, and then if the spec changes, I'd drop it when reposting the PoC after reworking it.
Yah, sure.
Thanks,
Conor.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kvm-riscv/attachments/20230419/38456429/attachment-0001.sig>
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
In reply to Andrew JonesQuoted 23 lines · Andrew Jones
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Quoted 12 lines
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 9 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
Quoted 8 lines
I don't believe there's an established order. I've been going for spec order, I think.
Quoted 3 lines
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
I think I need to wait until it's been ratified.
Did you discuss the SBI_EXT_STA number of the SBI spec? Could you share the link to me? Thx.
Quoted 55 lines
Quoted 4 lines
Anyways, this does match the docs - but I'm quite hesitant to leave an R-b when it's not merged yet.
I could take your R-b now, and then if the spec changes, I'd drop it when reposting the PoC after reworking it.
Thanks,
drewQuoted 32 lines
Cheers,
Conor.Quoted 28 lines
arch/riscv/include/asm/sbi.h +14
-0/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) +/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal; +u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7fSignature · 1 line
2.39.2Quoted 4 lines
Quoted 4 lines
_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 28 lines · Guo Ren
Quoted 27 lines · Andrew Jones
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Quoted 12 lines
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 9 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
I don't believe there's an established order. I've been going for spec order, I think.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
I think I need to wait until it's been ratified.
Did you discuss the
SBI_EXT_STAnumber of the SBI spec? Could you share the link to me? Thx.
The number is just "STA" in hex, as all SBI extensions are numbered. All discussion of the spec was on the tech-prs mailing list[1]. Searching for "steal" in the archives appears to pull up relevant threads.
[1] https://lists.riscv.org/g/tech-prs/messages
Thanks,
drew
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 38 lines · On Thu, Aug 3, 2023 at 2:48?PM Andrew Jones <[email protected]> wrote:
Quoted 28 lines · Guo Ren
Quoted 27 lines · Andrew Jones
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)Quoted 12 lines
arch/riscv/include/asm/sbi.h enum sbi_ext_id { · line 33
Quoted 9 lines
arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , + SBI_EXT_STA = 0x535441,What is the sort order of this? Matching the spec ordering, or just append-at-the-end?
I don't believe there's an established order. I've been going for spec order, I think.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Unrelated, but in checking that I saw that your SUSP stuff is in master - you planning on resending that series?
I think I need to wait until it's been ratified.
Did you discuss the
SBI_EXT_STAnumber of the SBI spec? Could you share the link to me? Thx.
Quoted 5 lines
The number is just "STA" in hex, as all SBI extensions are numbered. All discussion of the spec was on the tech-prs mailing list[1]. Searching for "steal" in the archives appears to pull up relevant threads.
Thx for the information; It could guide me to send the SBI_EXT_PVLOCK request.
Quoted 5 lines
Thanks,
drew
Signature · 2 lines
Best Regards Guo Ren
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
In reply to Andrew JonesQuoted 23 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , +SBI_EXT_STA =0x535441 ,/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0)
arch/riscv/include/asm/sbi.h enum sbi_pmu_ctr_type { · line 248
Quoted 10 lines
arch/riscv/include/asm/sbi.h +9
-0+/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal;
Could we wrap the "sequence & steal" into one 64-bit variable? Then only rv32 needs double READs, and only one ld instruction for rv64 ISA.
Quoted 17 lines
arch/riscv/include/asm/sbi.h +5
-0+u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7fSignature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list linux-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 2/14 RISC-V: Add SBI STA extension definitions
Quoted 25 lines · Guo Ren
Quoted 24 lines · Andrew Jones
The SBI STA extension enables steal-time accounting. Add the definitions it specifies.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/include/asm/sbi.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/riscv/include/asm/sbi.h +1
-0@@ -30,6 +30,7 @@ enum sbi_ext_id {SBI_EXT_HSM =0x48534D ,SBI_EXT_SRST =0x53525354 ,SBI_EXT_PMU =0x504D55 , +SBI_EXT_STA =0x535441 ,/* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START = 0x08000000,@@ -236,6 +237,20 @@ enum sbi_pmu_ctr_type {/* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0)
Quoted 11 lines
arch/riscv/include/asm/sbi.h enum sbi_pmu_ctr_type { · line 248
Quoted 9 lines
arch/riscv/include/asm/sbi.h +9
-0+/* SBI STA (steal-time accounting) extension */ +enum sbi_ext_sta_fid { +SBI_EXT_STA_SET_STEAL_TIME_SHMEM =0 , +}; + +struct sbi_sta_struct { +__le32 sequence; +__le32 flags; +__le64 steal;Could we wrap the "sequence & steal" into one 64-bit variable? Then only rv32 needs double READs, and only one ld instruction for rv64 ISA.
That's possible, but we'd have to reduce the size of steal by whatever size we decide is sufficient for sequence. In order to do that we'll need to discuss the size reduction proposals and their justifications at the spec level. If you'd like to make that proposal, then please create an issue at [1]. But, I don't think it should be necessary. There's non-normative text in the spec that says "This sequence field enables the value of the steal field to be read by supervisor-mode software executing in a 32-bit environment.", which implies to me that we could optimize the read in a 64-bit environment by neglecting to read sequence at all.
[1] https://github.com/riscv-non-isa/riscv-sbi-doc
Thanks,
drew
Quoted 18 lines
Quoted 18 lines
arch/riscv/include/asm/sbi.h +5
-0+u8 preempted; +u8 pad[47 ]; +} __packed; + +/* SBI spec version fields */ #define SBI_SPEC_VERSION_DEFAULT 0x1#define SBI_SPEC_VERSION_MAJOR_SHIFT 24#define SBI_SPEC_VERSION_MAJOR_MASK 0x7fSignature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list linux-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
In reply to Andrew JonesWhen the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation.
--- arch/riscv/kernel/paravirt.c | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)
arch/riscv/kernel/paravirt.c +53 -3
@@ -6,12 +6,21 @@#define pr_fmt (fmt) "riscv-pv: " fmt#include <linux/cpuhotplug.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/jump_label.h> +#include <linux/kconfig.h> +#include <linux/kernel.h> +#include <linux/percpu-defs.h> #include <linux/printk.h> #include <linux/static_call.h> #include <linux/types.h> +#include <asm/barrier.h> +#include <asm/page.h> +#include <asm/sbi.h> +struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;
@@ -31,24 +40,65 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); +static bool __init has_pv_steal_clock (void ) { +if (sbi_probe_extension (SBI_EXT_STA ) >0 ) { +pr_info ("SBI STA extension detected\n" ); +return true; + } +return false; } -static int pv_time_cpu_online (unsigned int cpu) +static int sbi_sta_set_steal_time_shmem (unsigned long lo,unsigned long hi, +unsigned long flags) { +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_STA ,SBI_EXT_STA_SET_STEAL_TIME_SHMEM , + lo, hi, flags,0 ,0 ,0 ); +if (ret.error) { +if (lo ==-1 && hi ==-1 ) +pr_warn ("Failed to disable steal-time shmem" ); +else +pr_warn ("Failed to set steal-time shmem" ); +return -ENOMEM ; + } +return 0 ; } +static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st); +unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 ); }static u64 pv_time_steal_clock (int cpu) { -return 0 ; +struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence)); + +return steal; }int __init pv_time_init (void )
Signature · 1 line
2.39.2
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
Quoted 4 lines · Andrew Jones
arch/riscv/kernel/paravirt.c +4
-0+static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st);
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 85
Quoted 10 lines
arch/riscv/kernel/paravirt.c +7
-1+unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 );
I'm not really a fan of this -1s without an explanation of what passing -1 to the ecall does.
Quoted 5 lines
}
static u64
pv_time_steal_clock(int cpu)
{arch/riscv/kernel/paravirt.c +0
-1-return 0 ;
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 99
Quoted 10 lines
arch/riscv/kernel/paravirt.c +10
-0+struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence));
Call me a bit anal, but should we yoink your:
| The supervisor-mode software MUST check this field | before and after reading the `steal` field, and | repeat the read if they are different or odd
and add it here so that is it immediately obvious without reading the SBI spec what is going on here? Or it is a case of "go read the SBI spec if you have questions about what the kernel is doing w/ SBI stuff?
(sidenote, s/they are/it is/?)
Guess both of my comments are in the same vein, but would make at-a-glance understanding easier IMO.
Cheers,
Conor.
Quoted 13 lines
arch/riscv/kernel/paravirt.c +2
-0+ +return steal; }int __init pv_time_init (void )Signature · 7 lines
2.39.2 _______________________________________________ linux-riscv mailing list linux-riscv at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kvm-riscv/attachments/20230418/acadb863/attachment-0001.sig>
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
Quoted 37 lines · Conor Dooley
Quoted 4 lines · Andrew Jones
arch/riscv/kernel/paravirt.c +4
-0+static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st);arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 85
Quoted 10 lines
arch/riscv/kernel/paravirt.c +7
-1+unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 );I'm not really a fan of this -1s without an explanation of what passing -1 to the ecall does.
Quoted 5 lines
}
static u64
pv_time_steal_clock(int cpu)
{arch/riscv/kernel/paravirt.c +0
-1-return 0 ;arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 99
Quoted 10 lines
arch/riscv/kernel/paravirt.c +10
-0+struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence));Call me a bit anal, but should we yoink your:
Quoted 8 lines
| The supervisor-mode software MUST check this field | before and after reading the `steal` field, and | repeat the read if they are different or oddand add it here so that is it immediately obvious without reading the SBI spec what is going on here? Or it is a case of "go read the SBI spec if you have questions about what the kernel is doing w/ SBI stuff?
(sidenote, s/they are/it is/?)
Thanks, I updated the spec for its v3 posting. Before posting v3, I'd be happy to take more comments on it over on its v2 posting.
Quoted 3 lines
Guess both of my comments are in the same vein, but would make at-a-glance understanding easier IMO.
I'm inclined to say "go read the spec" for everything, since the KVM implementation would otherwise also require several comments which duplicate the spec, but I'm also OK with adding the comments you've suggested here. I'll do that for rfc-v2.
Thanks,
drew
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
Quoted 45 lines · Andrew Jones
Quoted 44 lines · Conor Dooley
Quoted 4 lines · Andrew Jones
arch/riscv/kernel/paravirt.c +4
-0+static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st);arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 85
Quoted 10 lines
arch/riscv/kernel/paravirt.c +7
-1+unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 );I'm not really a fan of this -1s without an explanation of what passing -1 to the ecall does.
Quoted 5 lines
}
static u64
pv_time_steal_clock(int cpu)
{arch/riscv/kernel/paravirt.c +0
-1-return 0 ;arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 99
Quoted 10 lines
arch/riscv/kernel/paravirt.c +10
-0+struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence));Call me a bit anal, but should we yoink your:
| The supervisor-mode software MUST check this field | before and after reading the `steal` field, and | repeat the read if they are different or oddand add it here so that is it immediately obvious without reading the SBI spec what is going on here? Or it is a case of "go read the SBI spec if you have questions about what the kernel is doing w/ SBI stuff?
Quoted 4 lines
Quoted 1 line
(sidenote, s/they are/it is/?)
Thanks, I updated the spec for its v3 posting. Before posting v3, I'd be happy to take more comments on it over on its v2 posting.
I did read it last week or whenever you sent it, but didn't feel qualified to give an opinion on the content nor did I notice that grammaro.
I'd have replied there, but I was too lazy to dump your mail from there into a format readable by a decent mail client. I should just sign up there with this email address instead.
Quoted 7 lines
Quoted 2 lines
Guess both of my comments are in the same vein, but would make at-a-glance understanding easier IMO.
I'm inclined to say "go read the spec" for everything, since the KVM implementation would otherwise also require several comments which duplicate the spec, but I'm also OK with adding the comments you've suggested here. I'll do that for rfc-v2.
I don't really have strong feelings, the magic -1s can be explained away
with a define so they're sortable without cogging stuff from the spec.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kvm-riscv/attachments/20230419/2c748fe9/attachment-0001.sig>
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
In reply to Andrew JonesQuoted 92 lines · Andrew Jones
When the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)arch/riscv/kernel/paravirt.c +44
-3@@ -6,12 +6,21 @@#define pr_fmt (fmt) "riscv-pv: " fmt#include <linux/cpuhotplug.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/jump_label.h> +#include <linux/kconfig.h> +#include <linux/kernel.h> +#include <linux/percpu-defs.h> #include <linux/printk.h> #include <linux/static_call.h> #include <linux/types.h> +#include <asm/barrier.h> +#include <asm/page.h> +#include <asm/sbi.h> +struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;@@ -31,24 +40,65 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); +static bool __init has_pv_steal_clock (void ) { +if (sbi_probe_extension (SBI_EXT_STA ) >0 ) { +pr_info ("SBI STA extension detected\n" ); +return true; + } +return false; } -static int pv_time_cpu_online (unsigned int cpu) +static int sbi_sta_set_steal_time_shmem (unsigned long lo,unsigned long hi, +unsigned long flags) { +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_STA ,SBI_EXT_STA_SET_STEAL_TIME_SHMEM , + lo, hi, flags,0 ,0 ,0 ); +if (ret.error) { +if (lo ==-1 && hi ==-1 ) +pr_warn ("Failed to disable steal-time shmem" ); +else +pr_warn ("Failed to set steal-time shmem" ); +return -ENOMEM ; + } +return 0 ; } +static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st); +unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 ); }static u64 pv_time_steal_clock (int cpu) { -return 0 ; +struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal;
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 102
Quoted 10 lines
arch/riscv/kernel/paravirt.c +9
-0+ +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence)); + +return steal; }
So anybody poking around the implementations for other architectures will see that I shamelessly ripped this off from x86's implementation. However, looking at it again, I think all the references to the steal-time info should be wrapped in READ_ONCE(). I'll write a patch for x86/kvm to add READ_ONCE's and also update this patch for rfc-v2.
Thanks,
drew
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
Quoted 101 lines · Andrew Jones
Quoted 100 lines · Andrew Jones
When the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)arch/riscv/kernel/paravirt.c +52
-3@@ -6,12 +6,21 @@#define pr_fmt (fmt) "riscv-pv: " fmt#include <linux/cpuhotplug.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/jump_label.h> +#include <linux/kconfig.h> +#include <linux/kernel.h> +#include <linux/percpu-defs.h> #include <linux/printk.h> #include <linux/static_call.h> #include <linux/types.h> +#include <asm/barrier.h> +#include <asm/page.h> +#include <asm/sbi.h> +struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;@@ -31,24 +40,65 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); +static bool __init has_pv_steal_clock (void ) { +if (sbi_probe_extension (SBI_EXT_STA ) >0 ) { +pr_info ("SBI STA extension detected\n" ); +return true; + } +return false; } -static int pv_time_cpu_online (unsigned int cpu) +static int sbi_sta_set_steal_time_shmem (unsigned long lo,unsigned long hi, +unsigned long flags) { +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_STA ,SBI_EXT_STA_SET_STEAL_TIME_SHMEM , + lo, hi, flags,0 ,0 ,0 ); +if (ret.error) { +if (lo ==-1 && hi ==-1 ) +pr_warn ("Failed to disable steal-time shmem" ); +else +pr_warn ("Failed to set steal-time shmem" ); +return -ENOMEM ; + } +return 0 ; } +static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st); +unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 ); }static u64 pv_time_steal_clock (int cpu) { -return 0 ; +struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence)); +
Quoted 9 lines
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 102
Quoted 2 lines
arch/riscv/kernel/paravirt.c +1
-0+return steal; }So anybody poking around the implementations for other architectures will see that I shamelessly ripped this off from x86's implementation. However, looking at it again, I think all the references to the steal-time info should be wrapped in
READ_ONCE(). I'll write a patch for x86/kvm to add READ_ONCE's and also update this patch for rfc-v2.
After rereading "COMPILER BARRIER" of Documentation/memory-barriers.txt, I no longer believe we need the READ_ONCE wrappers for x86 nor riscv, unless we add them "for documentation purposes", as suggested by that section. The reason is that the virt_rmb() barriers also act as compiler barriers, which not only ensures program access order, but also "Within a loop, forces the compiler to load the variables used in that loop's conditional on each pass through that loop."
That said, my preference would be to add them, though, so I'll at least add them for riscv for rfc-v2. Maybe I'll still send the x86 patch too.
Thanks,
drew
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
In reply to Andrew JonesQuoted 101 lines · Andrew Jones
Quoted 100 lines · Andrew Jones
When the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)arch/riscv/kernel/paravirt.c +52
-3@@ -6,12 +6,21 @@#define pr_fmt (fmt) "riscv-pv: " fmt#include <linux/cpuhotplug.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/jump_label.h> +#include <linux/kconfig.h> +#include <linux/kernel.h> +#include <linux/percpu-defs.h> #include <linux/printk.h> #include <linux/static_call.h> #include <linux/types.h> +#include <asm/barrier.h> +#include <asm/page.h> +#include <asm/sbi.h> +struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;@@ -31,24 +40,65 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); +static bool __init has_pv_steal_clock (void ) { +if (sbi_probe_extension (SBI_EXT_STA ) >0 ) { +pr_info ("SBI STA extension detected\n" ); +return true; + } +return false; } -static int pv_time_cpu_online (unsigned int cpu) +static int sbi_sta_set_steal_time_shmem (unsigned long lo,unsigned long hi, +unsigned long flags) { +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_STA ,SBI_EXT_STA_SET_STEAL_TIME_SHMEM , + lo, hi, flags,0 ,0 ,0 ); +if (ret.error) { +if (lo ==-1 && hi ==-1 ) +pr_warn ("Failed to disable steal-time shmem" ); +else +pr_warn ("Failed to set steal-time shmem" ); +return -ENOMEM ; + } +return 0 ; } +static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st); +unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 ); }static u64 pv_time_steal_clock (int cpu) { -return 0 ; +struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence)); +
Quoted 8 lines
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 102
Quoted 2 lines
arch/riscv/kernel/paravirt.c +1
-0+return steal; }So anybody poking around the implementations for other architectures will see that I shamelessly ripped this off from x86's implementation. However, looking at it again, I think all the references to the steal-time info should be wrapped in
READ_ONCE(). I'll write a patch for x86/kvm to add READ_ONCE's and also update this patch for rfc-v2.
Hello, what's the status of rfc-v2? The riscv paravirt_qspinlock is based on your series to reuse the paravirt.c and CONFIG_PARAVIRT.
https://lore.kernel.org/linux-riscv/20230802164701.192791-10-guoren at kernel.org/
https://lore.kernel.org/linux-riscv/20230802164701.192791-17-guoren at kernel.org/
Quoted 9 lines
Thanks,
drew_______________________________________________
linux-riscv mailing list
linux-riscv at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
RFC PATCH 3/14 RISC-V: paravirt: Implement steal-time support
Quoted 110 lines · Guo Ren
Quoted 101 lines · Andrew Jones
Quoted 100 lines · Andrew Jones
When the SBI STA extension exists we can use it to implement paravirt steal-time support. Fill in the empty pv-time functions with an SBI STA implementation.
Signed-off-by Andrew Jones <[email protected]>--- arch/riscv/kernel/paravirt.c | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)arch/riscv/kernel/paravirt.c +52
-3@@ -6,12 +6,21 @@#define pr_fmt (fmt) "riscv-pv: " fmt#include <linux/cpuhotplug.h> +#include <linux/compiler.h> +#include <linux/errno.h> #include <linux/init.h> #include <linux/jump_label.h> +#include <linux/kconfig.h> +#include <linux/kernel.h> +#include <linux/percpu-defs.h> #include <linux/printk.h> #include <linux/static_call.h> #include <linux/types.h> +#include <asm/barrier.h> +#include <asm/page.h> +#include <asm/sbi.h> +struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;@@ -31,24 +40,65 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc); +DEFINE_PER_CPU(struct sbi_sta_struct, steal_time) __aligned(64); +static bool __init has_pv_steal_clock (void ) { +if (sbi_probe_extension (SBI_EXT_STA ) >0 ) { +pr_info ("SBI STA extension detected\n" ); +return true; + } +return false; } -static int pv_time_cpu_online (unsigned int cpu) +static int sbi_sta_set_steal_time_shmem (unsigned long lo,unsigned long hi, +unsigned long flags) { +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_STA ,SBI_EXT_STA_SET_STEAL_TIME_SHMEM , + lo, hi, flags,0 ,0 ,0 ); +if (ret.error) { +if (lo ==-1 && hi ==-1 ) +pr_warn ("Failed to disable steal-time shmem" ); +else +pr_warn ("Failed to set steal-time shmem" ); +return -ENOMEM ; + } +return 0 ; } +static int pv_time_cpu_online (unsigned int cpu) +{ +struct sbi_sta_struct *st =this_cpu_ptr (&steal_time); +phys_addr_t pa =__pa (st); +unsigned long lo = (unsigned long )pa; +unsigned long hi =IS_ENABLED (CONFIG_32BIT ) ?upper_32_bits ((u64 )pa) :0 ; + +return sbi_sta_set_steal_time_shmem (lo, hi,0 ); +} +static int pv_time_cpu_down_prepare (unsigned int cpu) { -return 0 ; +return sbi_sta_set_steal_time_shmem (-1 ,-1 ,0 ); }static u64 pv_time_steal_clock (int cpu) { -return 0 ; +struct sbi_sta_struct *st =per_cpu_ptr (&steal_time, cpu); +u32 sequence; +u64 steal; + +do { + sequence = st->sequence; +virt_rmb (); + steal = st->steal; +virt_rmb (); + }while ((sequence &1 ) || (sequence != st->sequence)); +Quoted 8 lines
arch/riscv/kernel/paravirt.c static int __init parse_no_stealacc(char *arg) · line 102
Quoted 2 lines
arch/riscv/kernel/paravirt.c +1
-0+return steal; }So anybody poking around the implementations for other architectures will see that I shamelessly ripped this off from x86's implementation. However, looking at it again, I think all the references to the steal-time info should be wrapped in
READ_ONCE(). I'll write a patch for x86/kvm to add READ_ONCE's and also update this patch for rfc-v2.
Quoted 2 lines
Hello, what's the status of rfc-v2? The riscv
paravirt_qspinlockis based on your series to reuse theparavirt.candCONFIG_PARAVIRT.
I prepared it, but then didn't bother posting, since the series has to stay an RFC and not be merged until the spec is frozen and the changes were pretty minor (mostly just name changes). The pv_time_steal_clock() changes described above look like this
static u64 pv_time_steal_clock(int cpu)
{
struct sbi_sta_struct *st = per_cpu_ptr(&steal_time, cpu);
u32 sequence;
u64 steal;
/*
* Check the sequence field before and after reading the steal
* field. Repeat the read if it is different or odd.
*/
do {
sequence = READ_ONCE(st->sequence);
virt_rmb();
steal = READ_ONCE(st->steal);
virt_rmb();
} while ((le32_to_cpu(sequence) & 1) || sequence != READ_ONCE(st->sequence));
return le64_to_cpu(steal);
}Quoted 3 lines
https://lore.kernel.org/linux-riscv/20230802164701.192791-10-guoren at kernel.org/
https://lore.kernel.org/linux-riscv/20230802164701.192791-17-guoren at kernel.org/
Thanks, I'll take a look at this.
drew
RFC PATCH 4/14 RISC-V: paravirt: Add kconfigs
In reply to Andrew JonesNow that we can support steal-time accounting, add the kconfig knobs allowing it to be enabled.
--- arch/riscv/Kconfig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/riscv/Kconfig +19 -0
@@ -583,6 +583,25 @@ config COMPAT If you want to execute 32-bit userspace applications, say Y. +config PARAVIRT + bool "Enable paravirtualization code" + depends on RISCV_SBI + help + This changes the kernel so it can modify itself when it is run + under a hypervisor, potentially improving performance significantly + over full virtualization. + +config PARAVIRT_TIME_ACCOUNTING + bool "Paravirtual steal time accounting" + depends on PARAVIRT + help + Select this option to enable fine granularity task steal time + accounting. Time spent executing other tasks in parallel with + the current vCPU is discounted from the vCPU power. To account for + that, there can be a small performance impact. + + If in doubt, say N here. + endmenu # "Kernel features" menu "Boot options"
Signature · 1 line
2.39.2
RFC PATCH 4/14 RISC-V: paravirt: Add kconfigs
Quoted 4 lines · Andrew Jones
Now that we can support steal-time accounting, add the kconfig knobs allowing it to be enabled.
Signed-off-by Andrew Jones <[email protected]>
Surely this won't change even if the SBI spec proposal does, right...
Thanks,
Conor.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/kvm-riscv/attachments/20230418/6fbdfae1/attachment-0001.sig>
RFC PATCH 5/14 RISC-V: KVM: Add SBI STA extension skeleton
In reply to Andrew JonesAdd the files and functions needed to support the SBI STA (steal-time accounting) extension. In the next patches we'll complete the functions to fully enable SBI STA support.
--- arch/riscv/include/asm/kvm_vcpu_sbi.h | 1 + arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu_sbi.c | 4 +++ arch/riscv/kvm/vcpu_sbi_sta.c | 47 +++++++++++++++++++++++++++ 5 files changed, 54 insertions(+) create mode 100644 arch/riscv/kvm/vcpu_sbi_sta.c
arch/riscv/include/asm/kvm_vcpu_sbi.h +1 -0
@@ -63,6 +63,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi;extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence;extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst;extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta;extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental;extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor;
arch/riscv/include/uapi/asm/kvm.h +1 -0
@@ -124,6 +124,7 @@ enum KVM_RISCV_SBI_EXT_ID {KVM_RISCV_SBI_EXT_PMU ,KVM_RISCV_SBI_EXT_EXPERIMENTAL ,KVM_RISCV_SBI_EXT_VENDOR , +KVM_RISCV_SBI_EXT_STA , KVM_RISCV_SBI_EXT_MAX, };
arch/riscv/kvm/Makefile +1 -0
@@ -24,5 +24,6 @@ kvm-$(CONFIG_RISCV_SBI_V01) += vcpu_sbi_v01.o kvm-y += vcpu_sbi_base.o kvm-y += vcpu_sbi_replace.o kvm-y += vcpu_sbi_hsm.o +kvm-y += vcpu_sbi_sta.o kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o
arch/riscv/kvm/vcpu_sbi.c +4 -0
@@ -68,6 +68,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { .dis_idx = KVM_RISCV_SBI_EXT_PMU, .ext_ptr = &vcpu_sbi_ext_pmu, }, + { + .dis_idx = KVM_RISCV_SBI_EXT_STA, + .ext_ptr = &vcpu_sbi_ext_sta, + }, { .dis_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, .ext_ptr = &vcpu_sbi_ext_experimental,
arch/riscv/kvm/vcpu_sbi_sta.c new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH 6/14 RISC-V: KVM: Add steal-update vcpu request
In reply to Andrew JonesAdd a new vcpu request to inform a vcpu that it should record its steal-time information. The request is made each time it has been detected that the vcpu task was not assigned a cpu for some time, which is easy to do by making the request from vcpu-load. The record function is just a stub for now and will be filled in with the rest of the steal-time support functions in following patches.
--- arch/riscv/include/asm/kvm_host.h | 3 +++ arch/riscv/kvm/vcpu.c | 5 +++++ arch/riscv/kvm/vcpu_sbi_sta.c | 4 ++++ 3 files changed, 12 insertions(+)
arch/riscv/include/asm/kvm_host.h +3 -0
@@ -37,6 +37,7 @@ KVM_ARCH_REQ_FLAGS(4, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_HFENCE \ KVM_ARCH_REQ_FLAGS(5, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) +#define KVM_REQ_STEAL_UPDATE KVM_ARCH_REQ(6)enum kvm_riscv_hfence_type {KVM_RISCV_HFENCE_UNKNOWN =0 ,
@@ -331,4 +332,6 @@ 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); +void kvm_riscv_vcpu_record_steal_time (struct kvm_vcpu *vcpu); +#endif /* __RISCV_KVM_HOST_H__ */
arch/riscv/kvm/vcpu.c +5 -0
@@ -901,6 +901,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)kvm_riscv_vcpu_guest_fp_restore (&vcpu->arch.guest_context, vcpu->arch.isa); +kvm_make_request (KVM_REQ_STEAL_UPDATE , vcpu); + vcpu->cpu = cpu; }
@@ -969,6 +971,9 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu)if (kvm_check_request (KVM_REQ_HFENCE , vcpu))kvm_riscv_hfence_process (vcpu); + +if (kvm_check_request (KVM_REQ_STEAL_UPDATE , vcpu)) +kvm_riscv_vcpu_record_steal_time (vcpu); } }
arch/riscv/kvm/vcpu_sbi_sta.c +4 -0
@@ -8,6 +8,10 @@#include <asm/kvm_vcpu_sbi.h> #include <asm/sbi.h> +void kvm_riscv_vcpu_record_steal_time (struct kvm_vcpu *vcpu) +{ +} +static int kvm_sbi_sta_set_steal_time_shmem (struct kvm_vcpu *vcpu) {return SBI_ERR_FAILURE ;
Signature · 1 line
2.39.2
RFC PATCH 7/14 RISC-V: KVM: Add SBI STA info to vcpu_arch
In reply to Andrew JonesKVM's implementation of SBI STA needs to track the address of each VCPU's steal-time shared memory region as well as the amount of stolen time. Add a structure to vcpu_arch to contain this state and make sure that the address is always set to INVALID_GPA on vcpu reset. And, of course, ensure KVM won't try to update steal- time when the shared memory address is invalid.
--- arch/riscv/include/asm/kvm_host.h | 6 ++++++ arch/riscv/kvm/vcpu.c | 2 ++ arch/riscv/kvm/vcpu_sbi_sta.c | 4 ++++ 3 files changed, 12 insertions(+)
arch/riscv/include/asm/kvm_host.h +6 -0
@@ -233,6 +233,12 @@ struct kvm_vcpu_arch {/* Performance monitoring context */ struct kvm_pmu pmu_context; + +/* SBI steal-time accounting */ +struct { +gpa_t shmem; +u64 last_steal; + } sta; };static inline void kvm_arch_sync_events (struct kvm *kvm) {}
arch/riscv/kvm/vcpu.c +2 -0
@@ -146,6 +146,8 @@ 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)); + vcpu->arch.sta.shmem =INVALID_GPA ; +/* Reset the guest CSRs for hotplug usecase */ if (loaded)kvm_arch_vcpu_load (vcpu,smp_processor_id ());
arch/riscv/kvm/vcpu_sbi_sta.c +4 -0
@@ -10,6 +10,10 @@void kvm_riscv_vcpu_record_steal_time (struct kvm_vcpu *vcpu) { +gpa_t shmem = vcpu->arch.sta.shmem; + +if (shmem ==INVALID_GPA ) +return ; }static int kvm_sbi_sta_set_steal_time_shmem (struct kvm_vcpu *vcpu)
Signature · 1 line
2.39.2
RFC PATCH 8/14 RISC-V: KVM: Implement SBI STA extension
In reply to Andrew JonesAdd a select SCHED_INFO to the KVM config in order to get run_delay info. Then implement SBI STA's set-steal-time-shmem function and kvm_riscv_vcpu_record_steal_time() to provide the steal-time info to guests.
--- arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/vcpu_sbi_sta.c | 96 ++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-)
arch/riscv/kvm/Kconfig +1 -0
@@ -28,6 +28,7 @@ config KVM select KVM_XFER_TO_GUEST_WORK select MMU_NOTIFIER select PREEMPT_NOTIFIERS + select SCHED_INFO select SRCU help Support hosting virtualized guest machines.
arch/riscv/kvm/vcpu_sbi_sta.c +94 -2
123 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH 9/14 RISC-V: KVM: Add support for SBI extension registers
In reply to Andrew JonesSome SBI extensions have state that needs to be saved / restored when migrating the VM. Provide a get/set-one-reg register type for SBI extension registers. Each SBI extension that uses this type will have its own subtype. There are currently no subtypes defined. The next patch introduces the first one.
--- arch/riscv/include/uapi/asm/kvm.h | 3 ++ arch/riscv/kvm/vcpu.c | 62 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
arch/riscv/include/uapi/asm/kvm.h +3 -0
@@ -186,6 +186,9 @@ enum KVM_RISCV_SBI_EXT_ID {#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) +/* Registers for specific SBI extensions are mapped as type 9 */ +#define KVM_REG_RISCV_SBI (0x09 << KVM_REG_RISCV_TYPE_SHIFT) +#endif #endif /* __LINUX_KVM_RISCV_H */
arch/riscv/kvm/vcpu.c +62 -0
80 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH 10/14 RISC-V: KVM: Add support for SBI STA registers
In reply to Andrew JonesKVM userspace needs to be able to save and restore the steal-time shared memory address. Provide the address through the get/set-one-reg interface with two ulong-sized SBI STA extension registers (lo and hi). 64-bit KVM will always save/restore zero for the hi register.
--- arch/riscv/include/asm/kvm_vcpu_sbi.h | 4 +++ arch/riscv/include/uapi/asm/kvm.h | 10 ++++++ arch/riscv/kvm/vcpu.c | 5 +++ arch/riscv/kvm/vcpu_sbi_sta.c | 52 +++++++++++++++++++++++++++ 4 files changed, 71 insertions(+)
arch/riscv/include/asm/kvm_vcpu_sbi.h +4 -0
@@ -52,6 +52,10 @@ int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext (struct kvm_vcpu *vcpu,unsigned long extid); +int kvm_riscv_vcpu_get_reg_sbi_sta (struct kvm_vcpu *vcpu,unsigned long reg_num, +unsigned long *reg_val); +int kvm_riscv_vcpu_set_reg_sbi_sta (struct kvm_vcpu *vcpu,unsigned long reg_num, +unsigned long reg_val);int kvm_riscv_vcpu_sbi_ecall (struct kvm_vcpu *vcpu,struct kvm_run *run);#ifdef CONFIG_RISCV_SBI_V01
arch/riscv/include/uapi/asm/kvm.h +10 -0
@@ -128,6 +128,12 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_MAX, }; +/* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ +struct kvm_riscv_sbi_sta { +unsigned long shmem_lo; +unsigned long shmem_hi; +}; +/* Possible states for kvm_riscv_timer */ #define KVM_RISCV_TIMER_STATE_OFF 0#define KVM_RISCV_TIMER_STATE_ON 1
@@ -189,6 +195,10 @@ enum KVM_RISCV_SBI_EXT_ID {/* Registers for specific SBI extensions are mapped as type 9 */ #define KVM_REG_RISCV_SBI (0x09 << KVM_REG_RISCV_TYPE_SHIFT) +#define KVM_REG_RISCV_SBI_STA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) +#define KVM_REG_RISCV_SBI_STA_REG (name) \ + (offsetof(struct kvm_riscv_sbi_sta, name) / sizeof(unsigned long)) +#endif #endif /* __LINUX_KVM_RISCV_H */
arch/riscv/kvm/vcpu.c +5 -0
@@ -603,6 +603,9 @@ static int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK ;switch (reg_subtype) { +case KVM_REG_RISCV_SBI_STA : + ret =kvm_riscv_vcpu_get_reg_sbi_sta (vcpu, reg_num, ®_val); +break ;default :return -EINVAL ; }
@@ -636,6 +639,8 @@ static int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, reg_num &= ~KVM_REG_RISCV_SUBTYPE_MASK ;switch (reg_subtype) { +case KVM_REG_RISCV_SBI_STA : +return kvm_riscv_vcpu_set_reg_sbi_sta (vcpu, reg_num, reg_val);default :return -EINVAL ; }
arch/riscv/kvm/vcpu_sbi_sta.c +52 -0
61 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH 11/14 KVM: selftests: riscv: Move sbi_ecall to processor.c
In reply to Andrew Jonessbi_ecall() isn't ucall specific. Move it to processor.c.
--- .../selftests/kvm/lib/riscv/processor.c | 26 +++++++++++++++++++ tools/testing/selftests/kvm/lib/riscv/ucall.c | 26 ------------------- 2 files changed, 26 insertions(+), 26 deletions(-)
tools/testing/selftests/kvm/lib/riscv/processor.c +26 -0
@@ -367,3 +367,29 @@ void vcpu_args_set(struct kvm_vcpu *vcpu, unsigned int num, ...)void assert_on_unhandled_exception (struct kvm_vcpu *vcpu) { } + +struct sbiret sbi_ecall (int ext,int fid,unsigned long arg0, +unsigned long arg1,unsigned long arg2, +unsigned long arg3,unsigned long arg4, +unsigned long arg5) +{ + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); + register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); +struct sbiret ret; + + asmvolatile ( +"ecall" + :"+r" (a0),"+r" (a1) + :"r" (a2),"r" (a3),"r" (a4),"r" (a5),"r" (a6),"r" (a7) + :"memory" ); + ret.error = a0; + ret.value = a1; + +return ret; +}
tools/testing/selftests/kvm/lib/riscv/ucall.c +0 -26
@@ -14,32 +14,6 @@ void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa) { } -struct sbiret sbi_ecall (int ext,int fid,unsigned long arg0, -unsigned long arg1,unsigned long arg2, -unsigned long arg3,unsigned long arg4, -unsigned long arg5) -{ - register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); - register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); - register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); - register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); - register uintptr_t a4 asm ("a4") = (uintptr_t)(arg4); - register uintptr_t a5 asm ("a5") = (uintptr_t)(arg5); - register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); - register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); -struct sbiret ret; - - asmvolatile ( -"ecall" - :"+r" (a0),"+r" (a1) - :"r" (a2),"r" (a3),"r" (a4),"r" (a5),"r" (a6),"r" (a7) - :"memory" ); - ret.error = a0; - ret.value = a1; - -return ret; -} -void ucall_arch_do_ucall (vm_vaddr_t uc) { sbi_ecall(KVM_RISCV_SELFTESTS_SBI_EXT,
Signature · 1 line
2.39.2
RFC PATCH 12/14 KVM: selftests: riscv: Add guest_sbi_probe_extension
In reply to Andrew JonesAdd guest_sbi_probe_extension(), allowing guest code to probe for SBI extensions. As guest_sbi_probe_extension() needs SBI_ERR_NOT_SUPPORTED, take the opportunity to bring in all SBI error codes. We don't bring in all current extension IDs or base extension function IDs though, even though we need one of each, because we'd prefer to bring those in as necessary.
--- .../selftests/kvm/include/riscv/processor.h | 21 +++++++++++++++++++ .../selftests/kvm/lib/riscv/processor.c | 19 +++++++++++++++++ 2 files changed, 40 insertions(+)
tools/testing/selftests/kvm/include/riscv/processor.h +21 -0
@@ -99,6 +99,17 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t idx,#define SATP_ASID_SHIFT 44#define SATP_ASID_MASK _AC(0xFFFF, UL) +/* SBI return error codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILURE -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 +#define SBI_ERR_ALREADY_AVAILABLE -6 +#define SBI_ERR_ALREADY_STARTED -7 +#define SBI_ERR_ALREADY_STOPPED -8 +#define SBI_EXT_EXPERIMENTAL_START 0x08000000#define SBI_EXT_EXPERIMENTAL_END 0x08FFFFFF
@@ -106,6 +117,14 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t idx,#define KVM_RISCV_SELFTESTS_SBI_UCALL 0#define KVM_RISCV_SELFTESTS_SBI_UNEXP 1 +enum sbi_ext_id { +SBI_EXT_BASE =0x10 , +}; + +enum sbi_ext_base_fid { +SBI_EXT_BASE_PROBE_EXT =3 , +}; +struct sbiret {long error;long value;
@@ -116,4 +135,6 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg3, unsigned long arg4, unsigned long arg5); +bool guest_sbi_probe_extension (int extid,long *out_val); +#endif /* SELFTEST_KVM_PROCESSOR_H */
tools/testing/selftests/kvm/lib/riscv/processor.c +19 -0
@@ -393,3 +393,22 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,return ret; } + +bool guest_sbi_probe_extension (int extid,long *out_val) +{ +struct sbiret ret; + + ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_PROBE_EXT , extid, +0 ,0 ,0 ,0 ,0 ); + +GUEST_ASSERT_2 (!ret.error || ret.error ==SBI_ERR_NOT_SUPPORTED , + ret.error, ret.value); + +if (ret.error ==SBI_ERR_NOT_SUPPORTED ) +return false; + +if (out_val) + *out_val = ret.value; + +return true; +}
Signature · 1 line
2.39.2
RFC PATCH 13/14 KVM: selftests: riscv: Add RISCV_SBI_EXT_REG
In reply to Andrew JonesExtend __kvm_reg_id() with subtype field support and add RISCV_SBI_EXT_REG() which uses that field.
--- .../selftests/kvm/include/riscv/processor.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
tools/testing/selftests/kvm/include/riscv/processor.h +11 -7
@@ -10,10 +10,10 @@#include "kvm_util.h" #include <linux/stringify.h> -static inline uint64_t __kvm_reg_id (uint64_t type,uint64_t idx, -uint64_t size) +static inline uint64_t __kvm_reg_id (uint64_t type,uint64_t subtype, +uint64_t idx,uint64_t size) { -return KVM_REG_RISCV | type | idx | size; +return KVM_REG_RISCV | type | subtype | idx | size; }#if __riscv_xlen ==64
@@ -22,22 +22,26 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t idx,#define KVM_REG_SIZE_ULONG KVM_REG_SIZE_U32#endif -#define RISCV_CONFIG_REG (name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, \ +#define RISCV_CONFIG_REG (name) __kvm_reg_id(KVM_REG_RISCV_CONFIG, 0, \ KVM_REG_RISCV_CONFIG_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_CORE_REG (name) __kvm_reg_id(KVM_REG_RISCV_CORE, \ +#define RISCV_CORE_REG (name) __kvm_reg_id(KVM_REG_RISCV_CORE, 0, \ KVM_REG_RISCV_CORE_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_CSR_REG (name) __kvm_reg_id(KVM_REG_RISCV_CSR, \ +#define RISCV_CSR_REG (name) __kvm_reg_id(KVM_REG_RISCV_CSR, 0, \ KVM_REG_RISCV_CSR_REG(name), \ KVM_REG_SIZE_ULONG) -#define RISCV_TIMER_REG (name) __kvm_reg_id(KVM_REG_RISCV_TIMER, \ +#define RISCV_TIMER_REG (name) __kvm_reg_id(KVM_REG_RISCV_TIMER, 0, \ KVM_REG_RISCV_TIMER_REG(name), \ KVM_REG_SIZE_U64) +#define RISCV_SBI_EXT_REG (subtype, id) __kvm_reg_id(KVM_REG_RISCV_SBI_EXT, \ + subtype, id, \ + KVM_REG_SIZE_ULONG) +/* L3 index Bit[47:39] */ #define PGTBL_L3_INDEX_MASK 0x0000FF8000000000ULL#define PGTBL_L3_INDEX_SHIFT 39
Signature · 1 line
2.39.2
RFC PATCH 14/14 KVM: selftests: riscv: Add steal_time test support
In reply to Andrew JonesWith the introduction of steal-time accounting support for RISC-V KVM we can add RISC-V support to the steal_time test.
--- tools/testing/selftests/kvm/Makefile | 3 +- .../selftests/kvm/include/riscv/processor.h | 1 + tools/testing/selftests/kvm/steal_time.c | 100 ++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-)
tools/testing/selftests/kvm/Makefile +2 -1
@@ -171,10 +171,11 @@ TEST_GEN_PROGS_s390x += kvm_binary_stats_test TEST_GEN_PROGS_riscv += demand_paging_test TEST_GEN_PROGS_riscv += dirty_log_test +TEST_GEN_PROGS_riscv += kvm_binary_stats_test TEST_GEN_PROGS_riscv += kvm_create_max_vcpus TEST_GEN_PROGS_riscv += kvm_page_table_test TEST_GEN_PROGS_riscv += set_memory_region_test -TEST_GEN_PROGS_riscv += kvm_binary_stats_test +TEST_GEN_PROGS_riscv += steal_time TEST_PROGS += $(TEST_PROGS_$(ARCH_DIR)) TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(ARCH_DIR))
tools/testing/selftests/kvm/include/riscv/processor.h +1 -0
@@ -123,6 +123,7 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,enum sbi_ext_id {SBI_EXT_BASE =0x10 , +SBI_EXT_STA =0x535441 , };enum sbi_ext_base_fid {
tools/testing/selftests/kvm/steal_time.c +100 -0
113 lines not on this page · raw message
Signature · 1 line
2.39.2