riscv: sbi: Test improvements and a couple new
Subsystems (3)
v2 cover riscv: sbi: Test improvements and a couple new
Improvements:
- Ensure system suspend test won't hang
- Ensure HSM suspend tests won't hang
- Ensure state is cleaned up at the end of one extension's test before starting another
- Probe SUSP and skip cleanly
- Minor SUSP test output improvement
- Dropped upper bits fwft test for misaligned_exc_deleg
New tests:
- Check bad FIDs for all extensions
- Check SUSP sleep_type upper bits are ignored on RV64
- FWFT pte-hw-ad-updating tests
v2:
- Dropped upper bits fwft test for misaligned_exc_deleg rather than change to kfail
- Added FWFT pte-hw-ad-updating tests
- Added a couple Clément tags
Andrew Jones (11):
riscv: sbi: Drop fwft upper bits test
riscv: sbi: Add fwft pte_hw_ad_updating test
riscv: sbi: Ensure we have IPIs enabled for HSM suspend tests
riscv: sbi: Ensure SUSP test gets an interrupt
riscv: sbi: Improve susp expected error output
riscv: sbi: Improve interrupt handling cleanup lib/cpumask: Add some operators
riscv: sbi: HSM suspend may not be supported
riscv: sbi: Probe/skip SUSP
riscv: sbi: susp: Check upper bits of sleep_type are ignored
riscv: sbi: Add bad fid tests
lib/cpumask.h | 56 +++++++++ riscv/sbi-fwft.c | 187 ++++++++++++++++++++++++++--- riscv/sbi-tests.h | 4 + riscv/sbi.c | 292 +++++++++++++++++++++++++++++++++------------- 4 files changed, 442 insertions(+), 97 deletions(-)
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 1/11 riscv: sbi: Drop fwft upper bits test
The test should be checking for SBI_SUCCESS and that the behavior of feature = BIT(32) is the same as feature = 0 (MISALIGNED_EXC_DELEG). However, enabling MISALIGNED_EXC_DELEG doesn't always lead to traps in S-mode (the platform may support misaligned accesses and not trap at all). Drop this upper bits of feature ID test for now. We'll add it back with another feature that has a deterministic behavior (such as with the ADUE feature).
--- riscv/sbi-fwft.c | 15 --------------- 1 file changed, 15 deletions(-)
riscv/sbi-fwft.c +0 -15
@@ -57,21 +57,6 @@ static void fwft_check_base(void)fwft_check_reserved (SBI_FWFT_GLOBAL_RESERVED_START );fwft_check_reserved (SBI_FWFT_GLOBAL_RESERVED_END ); -#if __riscv_xlen >32 -/* Check id > 32 bits */ - { -struct sbiret ret; - - ret =fwft_get_raw (BIT (32 )); -sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM , -"get feature with bit 32 set error" ); - - ret =fwft_set_raw (BIT (32 ),0 ,0 ); -sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM , -"set feature with bit 32 set error" ); - } -#endif -report_prefix_pop (); }
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Re: [kvm-unit-tests PATCH v2 01/11] riscv: sbi: Drop fwft upper bits test
Quoted 29 lines · Andrew Jones
The test should be checking for
SBI_SUCCESSand that the behavior of feature = BIT(32) is the same as feature = 0 (MISALIGNED_EXC_DELEG). However, enablingMISALIGNED_EXC_DELEGdoesn't always lead to traps in S-mode (the platform may support misaligned accesses and not trap at all). Drop this upper bits of feature ID test for now. We'll add it back with another feature that has a deterministic behavior (such as with the ADUE feature).Signed-off-by Andrew Jones <[email protected]>--- riscv/sbi-fwft.c | 15 --------------- 1 file changed, 15 deletions(-)riscv/sbi-fwft.c +0
-8@@ -57,21 +57,6 @@ static void fwft_check_base(void)fwft_check_reserved (SBI_FWFT_GLOBAL_RESERVED_START );fwft_check_reserved (SBI_FWFT_GLOBAL_RESERVED_END ); -#if __riscv_xlen >32 -/* Check id > 32 bits */ - { -struct sbiret ret; - - ret =fwft_get_raw (BIT (32 )); -sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM , -"get feature with bit 32 set error" );
riscv/sbi-fwft.c static void fwft_check_base(void) · line 62
Quoted 10 lines
riscv/sbi-fwft.c +0
-7- - ret =fwft_set_raw (BIT (32 ),0 ,0 ); -sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM , - "set feature with bit 32 set error"); - } -#endif -report_prefix_pop (); }
Hi Andrew,
Looks good to me.
Thanks,
Clément
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 2/11 riscv: sbi: Add fwft pte_hw_ad_updating test
In reply to Andrew JonesAdd SBI FWFT tests for the PTE_HW_AD_UPDATING feature.
--- riscv/sbi-fwft.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+)
riscv/sbi-fwft.c +170 -0
@@ -5,9 +5,12 @@* Copyright (C) 2024, Rivos Inc., Clément Léger <[email protected]> */ #include <libcflat.h> +#include <alloc.h> #include <stdlib.h> #include <asm/csr.h> +#include <asm/io.h> +#include <asm/mmu.h> #include <asm/processor.h> #include <asm/ptrace.h> #include <asm/sbi.h>
@@ -37,6 +40,21 @@ static struct sbiret fwft_get(uint32_t feature)return fwft_get_raw (feature); } +static struct sbiret fwft_set_and_check_raw (const char *str,unsigned long feature, +unsigned long value,unsigned long flags) +{ +struct sbiret ret; + + ret =fwft_set_raw (feature, value, flags); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"set to %ld%s" , value, str)) +return ret; + + ret =fwft_get_raw (feature); +sbiret_report (&ret,SBI_SUCCESS , value,"get %ld after set%s" , value, str); + +return ret; +} +static void fwft_check_reserved (unsigned long id) {struct sbiret ret;
@@ -160,6 +178,157 @@ static void fwft_check_misaligned_exc_deleg(void)report_prefix_pop (); } +static bool adue_triggered_read, adue_triggered_write; + +static void adue_set_ad (unsigned long addr,pteval_t prot) +{ +pte_t *ptep =get_pte (current_pgtable (), addr); + *ptep =__pte (pte_val (*ptep) | prot); +local_flush_tlb_page (addr); +} + +static void adue_read_handler (struct pt_regs *regs) +{ + adue_triggered_read = true; +adue_set_ad (regs->badaddr, _PAGE_ACCESSED); +} + +static void adue_write_handler (struct pt_regs *regs) +{ + adue_triggered_write = true; +adue_set_ad (regs->badaddr, _PAGE_ACCESSED | _PAGE_DIRTY); +} + +static bool adue_check_pte (pteval_t pte,bool write) +{ +return (pte & (_PAGE_ACCESSED | _PAGE_DIRTY)) == (_PAGE_ACCESSED | (write ? _PAGE_DIRTY :0 )); +} + +static void adue_check (bool hw_updating_enabled,bool write) +{ +unsigned long *ptr =malloc (sizeof (unsigned long )); +pte_t *ptep =get_pte (current_pgtable (), (uintptr_t )ptr); +bool *triggered; +const char *op; + +WRITE_ONCE (adue_triggered_read, false); +WRITE_ONCE (adue_triggered_write, false); + + *ptep =__pte (pte_val (*ptep) & ~(_PAGE_ACCESSED | _PAGE_DIRTY)); +local_flush_tlb_page ((uintptr_t )ptr); + +if (write) { + op ="write" ; + triggered = &adue_triggered_write; +writel (0xdeadbeef , ptr); + }else { + op ="read" ; + triggered = &adue_triggered_read; +readl (ptr); + } + +report (hw_updating_enabled != *triggered && +adue_check_pte (pte_val (*ptep), write),"hw updating %s %s" , + hw_updating_enabled ?"enabled" :"disabled" , op); + +free (ptr); +} + +static bool adue_toggle_and_check_raw (const char *str,unsigned long feature,unsigned long value, +unsigned long flags) +{ +struct sbiret ret =fwft_set_and_check_raw (str, feature, value, flags); + +if (!ret.error) { +adue_check (value, false); +adue_check (value, true); +return true; + } + +return false; +} + +static bool adue_toggle_and_check (const char *str,unsigned long value,unsigned long flags) +{ +return adue_toggle_and_check_raw (str,SBI_FWFT_PTE_AD_HW_UPDATING , value, flags); +} + +static void fwft_check_pte_ad_hw_updating (void ) +{ +struct sbiret ret; +bool enabled; + +report_prefix_push ("pte_ad_hw_updating" ); + + ret =fwft_get (SBI_FWFT_PTE_AD_HW_UPDATING ); +if (ret.error ==SBI_ERR_NOT_SUPPORTED ) { +report_skip ("not supported by platform" ); +return ; + }else if (!sbiret_report_error (&ret,SBI_SUCCESS ,"get" )) { +/* Not much we can do without a working get... */ +return ; + } + +report (ret.value ==0 || ret.value ==1 ,"first get value is 0/1" ); + + enabled = ret.value; +report_kfail (true, !enabled,"resets to 0" ); + +install_exception_handler (EXC_LOAD_PAGE_FAULT , adue_read_handler); +install_exception_handler (EXC_STORE_PAGE_FAULT , adue_write_handler); + +adue_check (enabled, false); +adue_check (enabled, true); + +if (!adue_toggle_and_check ("" , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; + +if (!adue_toggle_and_check (" again" , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; + +#if __riscv_xlen >32 +if (!adue_toggle_and_check_raw (" with high feature bits set" , +BIT (32 ) |SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; +#endif + +adue_inval_tests: + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING ,2 ,0 ); +sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"set to 2" ); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,2 ); +sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"set to %d with flags=2" , !enabled); + +if (!adue_toggle_and_check (" with lock" , !enabled,1 )) + goto adue_done; +else + enabled = !enabled; + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,0 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d without lock" , !enabled); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,1 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d with lock" , !enabled); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , enabled,0 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d without lock" , enabled); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , enabled,1 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d with lock" , enabled); + +adue_done: +install_exception_handler (EXC_LOAD_PAGE_FAULT ,NULL ); +install_exception_handler (EXC_STORE_PAGE_FAULT ,NULL ); + +report_prefix_pop (); +} +void check_fwft (void ) {report_prefix_push ("fwft" );
@@ -172,6 +341,7 @@ void check_fwft(void)fwft_check_base ();fwft_check_misaligned_exc_deleg (); +fwft_check_pte_ad_hw_updating ();report_prefix_pop (); }
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Re: [kvm-unit-tests PATCH v2 02/11] riscv: sbi: Add fwft pte_hw_ad_updating test
Quoted 182 lines · Andrew Jones
Add SBI FWFT tests for the
PTE_HW_AD_UPDATINGfeature.Signed-off-by Andrew Jones <[email protected]>--- riscv/sbi-fwft.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+)riscv/sbi-fwft.c +150
-0@@ -5,9 +5,12 @@* Copyright (C) 2024, Rivos Inc., Clément Léger <[email protected]> */ #include <libcflat.h> +#include <alloc.h> #include <stdlib.h> #include <asm/csr.h> +#include <asm/io.h> +#include <asm/mmu.h> #include <asm/processor.h> #include <asm/ptrace.h> #include <asm/sbi.h> @@ -37,6 +40,21 @@ static struct sbiret fwft_get(uint32_t feature)return fwft_get_raw (feature); } +static struct sbiret fwft_set_and_check_raw (const char *str,unsigned long feature, +unsigned long value,unsigned long flags) +{ +struct sbiret ret; + + ret =fwft_set_raw (feature, value, flags); +if (!sbiret_report_error (&ret,SBI_SUCCESS ,"set to %ld%s" , value, str)) +return ret; + + ret =fwft_get_raw (feature); +sbiret_report (&ret,SBI_SUCCESS , value,"get %ld after set%s" , value, str); + +return ret; +} +static void fwft_check_reserved (unsigned long id) {struct sbiret ret;@@ -160,6 +178,157 @@ static void fwft_check_misaligned_exc_deleg(void)report_prefix_pop (); } +static bool adue_triggered_read, adue_triggered_write; + +static void adue_set_ad (unsigned long addr,pteval_t prot) +{ +pte_t *ptep =get_pte (current_pgtable (), addr); + *ptep =__pte (pte_val (*ptep) | prot); +local_flush_tlb_page (addr); +} + +static void adue_read_handler (struct pt_regs *regs) +{ + adue_triggered_read = true; +adue_set_ad (regs->badaddr, _PAGE_ACCESSED); +} + +static void adue_write_handler (struct pt_regs *regs) +{ + adue_triggered_write = true; +adue_set_ad (regs->badaddr, _PAGE_ACCESSED | _PAGE_DIRTY); +} + +static bool adue_check_pte (pteval_t pte,bool write) +{ +return (pte & (_PAGE_ACCESSED | _PAGE_DIRTY)) == (_PAGE_ACCESSED | (write ? _PAGE_DIRTY :0 )); +} + +static void adue_check (bool hw_updating_enabled,bool write) +{ +unsigned long *ptr =malloc (sizeof (unsigned long )); +pte_t *ptep =get_pte (current_pgtable (), (uintptr_t )ptr); +bool *triggered; +const char *op; + +WRITE_ONCE (adue_triggered_read, false); +WRITE_ONCE (adue_triggered_write, false); + + *ptep =__pte (pte_val (*ptep) & ~(_PAGE_ACCESSED | _PAGE_DIRTY)); +local_flush_tlb_page ((uintptr_t )ptr); + +if (write) { + op ="write" ; + triggered = &adue_triggered_write; +writel (0xdeadbeef , ptr); + }else { + op ="read" ; + triggered = &adue_triggered_read; +readl (ptr); + } + +report (hw_updating_enabled != *triggered && +adue_check_pte (pte_val (*ptep), write),"hw updating %s %s" , + hw_updating_enabled ?"enabled" :"disabled" , op); + +free (ptr); +} + +static bool adue_toggle_and_check_raw (const char *str,unsigned long feature,unsigned long value, +unsigned long flags) +{ +struct sbiret ret =fwft_set_and_check_raw (str, feature, value, flags); + +if (!ret.error) { +adue_check (value, false); +adue_check (value, true); +return true; + } + +return false; +} + +static bool adue_toggle_and_check (const char *str,unsigned long value,unsigned long flags) +{ +return adue_toggle_and_check_raw (str,SBI_FWFT_PTE_AD_HW_UPDATING , value, flags); +} + +static void fwft_check_pte_ad_hw_updating (void ) +{ +struct sbiret ret; +bool enabled; + +report_prefix_push ("pte_ad_hw_updating" ); + + ret =fwft_get (SBI_FWFT_PTE_AD_HW_UPDATING ); +if (ret.error ==SBI_ERR_NOT_SUPPORTED ) { +report_skip ("not supported by platform" ); +return ; + }else if (!sbiret_report_error (&ret,SBI_SUCCESS ,"get" )) { +/* Not much we can do without a working get... */ +return ; + } + +report (ret.value ==0 || ret.value ==1 ,"first get value is 0/1" ); + + enabled = ret.value; +report_kfail (true, !enabled,"resets to 0" ); + +install_exception_handler (EXC_LOAD_PAGE_FAULT , adue_read_handler); +install_exception_handler (EXC_STORE_PAGE_FAULT , adue_write_handler); + +adue_check (enabled, false); +adue_check (enabled, true); + +if (!adue_toggle_and_check ("" , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; + +if (!adue_toggle_and_check (" again" , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; + +#if __riscv_xlen >32 +if (!adue_toggle_and_check_raw (" with high feature bits set" , +BIT (32 ) |SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,0 )) + goto adue_inval_tests; +else + enabled = !enabled; +#endif + +adue_inval_tests: + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING ,2 ,0 ); +sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"set to 2" ); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,2 ); +sbiret_report_error (&ret,SBI_ERR_INVALID_PARAM ,"set to %d with flags=2" , !enabled); + +if (!adue_toggle_and_check (" with lock" , !enabled,1 )) + goto adue_done; +else + enabled = !enabled; +
riscv/sbi-fwft.c static void fwft_check_misaligned_exc_deleg(void) · line 322
Quoted 10 lines
riscv/sbi-fwft.c +10
-0+ ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,0 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d without lock" , !enabled); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , !enabled,1 ); + sbiret_report_error(&ret, SBI_ERR_DENIED_LOCKED, "set locked to %d with lock", !enabled);> + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , enabled,0 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d without lock" , enabled); + + ret =fwft_set (SBI_FWFT_PTE_AD_HW_UPDATING , enabled,1 ); +sbiret_report_error (&ret,SBI_ERR_DENIED_LOCKED ,"set locked to %d with lock" , enabled);
Hi Andrew,
As I said, this could probably be factorized in some function common to all features since it will (probably) be done by other tests as well. But that can be done at a later time as well.
Quoted 12 lines
riscv/sbi-fwft.c +8
-0+ +adue_done: +install_exception_handler (EXC_LOAD_PAGE_FAULT ,NULL ); +install_exception_handler (EXC_STORE_PAGE_FAULT ,NULL ); + +report_prefix_pop (); +} +void check_fwft (void ) {report_prefix_push ("fwft" );
riscv/sbi-fwft.c void check_fwft(void) · line 347
Quoted 7 lines
riscv/sbi-fwft.c +1
-0@@ -172,6 +341,7 @@ void check_fwft(void)fwft_check_base ();fwft_check_misaligned_exc_deleg (); +fwft_check_pte_ad_hw_updating ();report_prefix_pop (); }
With or without my previous comment fixed:
Thanks,
Clément
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 3/11 riscv: sbi: Ensure we have IPIs enabled for HSM suspend tests
In reply to Andrew JonesWe'll start cleaning up after each test, so the HSM tests need to ensure they have IPIs setup themselves since they plan to use them.
--- riscv/sbi.c | 62 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 25 deletions(-)
riscv/sbi.c +37 -25
@@ -62,7 +62,7 @@ static struct sbiret sbi_dbcn_write_byte(uint8_t byte)return sbi_ecall (SBI_EXT_DBCN ,SBI_EXT_DBCN_CONSOLE_WRITE_BYTE , byte,0 ,0 ,0 ,0 ,0 ); } -static struct sbiret sbi_hart_suspend (uint32_t suspend_type,unsigned long resume_addr,unsigned long opaque) +static struct sbiret sbi_hart_suspend_raw (unsigned long suspend_type,unsigned long resume_addr,unsigned long opaque) {return sbi_ecall (SBI_EXT_HSM ,SBI_EXT_HSM_HART_SUSPEND , suspend_type, resume_addr, opaque,0 ,0 ,0 ); }
@@ -568,59 +568,71 @@ static void hart_start_invalid_hartid(void *data) sbi_hsm_invalid_hartid_check = true; } -static void hart_retentive_suspend (void *data) +static void ipi_nop (struct pt_regs *regs) +{ +ipi_ack (); +} + +static void hart_suspend_and_wait_ipi (unsigned long suspend_type,unsigned long resume_addr, +unsigned long opaque,bool returns,const char *typestr) {unsigned long hartid =current_thread_info ()->hartid; -struct sbiret ret =sbi_hart_suspend (SBI_EXT_HSM_HART_SUSPEND_RETENTIVE ,0 ,0 ); +struct sbiret ret; +install_irq_handler (IRQ_S_SOFT , ipi_nop); +local_ipi_enable (); +local_irq_enable (); + + ret =sbi_hart_suspend_raw (suspend_type, resume_addr, opaque);if (ret.error) -report_fail ("failed to retentive suspend cpu%d (hartid = %lx) (error=%ld)" , -smp_processor_id (), hartid, ret.error); +report_fail ("failed to %s cpu%d (hartid = %lx) (error=%ld)" , + typestr,smp_processor_id (), hartid, ret.error); +else if (!returns) +report_fail ("failed to %s cpu%d (hartid = %lx) (call should not return)" , + typestr,smp_processor_id (), hartid); + +local_irq_disable (); +local_ipi_disable (); +install_irq_handler (IRQ_S_SOFT ,NULL ); +} + +static void hart_retentive_suspend (void *data) +{ +hart_suspend_and_wait_ipi (SBI_EXT_HSM_HART_SUSPEND_RETENTIVE ,0 ,0 , true,"retentive suspend" ); }static void hart_non_retentive_suspend (void *data) { -unsigned long hartid =current_thread_info ()->hartid;unsigned long params[] = { [SBI_HSM_MAGIC_IDX ] =SBI_HSM_MAGIC , - [SBI_HSM_HARTID_IDX ] = hartid, + [SBI_HSM_HARTID_IDX ] =current_thread_info ()->hartid, }; -struct sbiret ret =sbi_hart_suspend (SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE , -virt_to_phys (&sbi_hsm_check_non_retentive_suspend), -virt_to_phys (params)); -report_fail ("failed to non-retentive suspend cpu%d (hartid = %lx) (error=%ld)" , -smp_processor_id (), hartid, ret.error); +hart_suspend_and_wait_ipi (SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE , +virt_to_phys (&sbi_hsm_check_non_retentive_suspend),virt_to_phys (params), + false,"non-retentive suspend" ); }/* This test function is only being run on RV64 to verify that upper bits of suspend_type are ignored */ static void hart_retentive_suspend_with_msb_set (void *data) { -unsigned long hartid =current_thread_info ()->hartid;unsigned long suspend_type =SBI_EXT_HSM_HART_SUSPEND_RETENTIVE | (_AC (1 ,UL ) << (__riscv_xlen -1 )); -struct sbiret ret =sbi_ecall (SBI_EXT_HSM ,SBI_EXT_HSM_HART_SUSPEND , suspend_type,0 ,0 ,0 ,0 ,0 ); -if (ret.error) -report_fail ("failed to retentive suspend cpu%d (hartid = %lx) with MSB set (error=%ld)" , -smp_processor_id (), hartid, ret.error); +hart_suspend_and_wait_ipi (suspend_type,0 ,0 , true,"retentive suspend with MSB set" ); }/* This test function is only being run on RV64 to verify that upper bits of suspend_type are ignored */ static void hart_non_retentive_suspend_with_msb_set (void *data) { -unsigned long hartid =current_thread_info ()->hartid;unsigned long suspend_type =SBI_EXT_HSM_HART_SUSPEND_NON_RETENTIVE | (_AC (1 ,UL ) << (__riscv_xlen -1 ));unsigned long params[] = { [SBI_HSM_MAGIC_IDX ] =SBI_HSM_MAGIC , - [SBI_HSM_HARTID_IDX ] = hartid, + [SBI_HSM_HARTID_IDX ] =current_thread_info ()->hartid, }; -struct sbiret ret =sbi_ecall (SBI_EXT_HSM ,SBI_EXT_HSM_HART_SUSPEND , suspend_type, -virt_to_phys (&sbi_hsm_check_non_retentive_suspend),virt_to_phys (params), -0 ,0 ,0 ); - -report_fail ("failed to non-retentive suspend cpu%d (hartid = %lx) with MSB set (error=%ld)" , -smp_processor_id (), hartid, ret.error); +hart_suspend_and_wait_ipi (suspend_type, +virt_to_phys (&sbi_hsm_check_non_retentive_suspend),virt_to_phys (params), + false,"non-retentive suspend with MSB set" ); }static bool hart_wait_on_status (unsigned long hartid,enum sbi_ext_hsm_sid status,unsigned long duration)
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 4/11 riscv: sbi: Ensure SUSP test gets an interrupt
In reply to Andrew JonesA system suspend may call WFI. Set a periodic timer to ensure we get an interrupt and don't hang forever.
--- riscv/sbi-tests.h | 2 ++ riscv/sbi.c | 70 ++++++++++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 25 deletions(-)
riscv/sbi-tests.h +2 -0
@@ -19,12 +19,14 @@#define SBI_SUSP_HARTID_IDX 2#define SBI_SUSP_TESTNUM_IDX 3#define SBI_SUSP_RESULTS_IDX 4 +#define SBI_SUSP_NR_IDX 5#define SBI_CSR_SSTATUS_IDX 0#define SBI_CSR_SIE_IDX 1#define SBI_CSR_STVEC_IDX 2#define SBI_CSR_SSCRATCH_IDX 3#define SBI_CSR_SATP_IDX 4 +#define SBI_CSR_NR_IDX 5#define SBI_SUSP_MAGIC 0x505b
riscv/sbi.c +45 -25
154 lines not on this page · raw message
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 5/11 riscv: sbi: Improve susp expected error output
In reply to Andrew JonesImprove the output of expected error tests. We don't use sbiret_report_error() because we're not passing in an SBI_ERR_* name to stringify.
--- riscv/sbi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
riscv/sbi.c +2 -3
@@ -1433,9 +1433,8 @@ static void check_susp(void) }else if (!params.returns) {report_fail ("unexpected return with error: %ld, value: %ld" , ret.error, ret.value); }else { -report (ret.error == params.ret.error,"expected sbi.error" ); -if (ret.error != params.ret.error) -report_info ("expected error %ld, received %ld" , params.ret.error, ret.error); +if (!report (ret.error == params.ret.error,"got expected sbi.error (%ld)" , params.ret.error)) +report_info ("expected sbi.error %ld, received %ld" , params.ret.error, ret.error); }report_prefix_pop ();
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Re: [kvm-unit-tests PATCH v2 05/11] riscv: sbi: Improve susp expected error output
Quoted 15 lines · Andrew Jones
Improve the output of expected error tests. We don't use
sbiret_report_error()because we're not passing in an SBI_ERR_* name to stringify.Signed-off-by Andrew Jones <[email protected]>--- riscv/sbi.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)riscv/sbi.c +0
-0@@ -1433,9 +1433,8 @@ static void check_susp(void) }else if (!params.returns) {
riscv/sbi.c static void check_susp(void) · line 1440
Quoted 10 lines
riscv/sbi.c +2
-3report_fail ("unexpected return with error: %ld, value: %ld" , ret.error, ret.value); }else { -report (ret.error == params.ret.error,"expected sbi.error" ); -if (ret.error != params.ret.error) -report_info ("expected error %ld, received %ld" , params.ret.error, ret.error); +if (!report (ret.error == params.ret.error,"got expected sbi.error (%ld)" , params.ret.error)) +report_info ("expected sbi.error %ld, received %ld" , params.ret.error, ret.error); }report_prefix_pop ();
Hi Andrew,
LGTM,
Thanks,
Clément
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 6/11 riscv: sbi: Improve interrupt handling cleanup
In reply to Andrew JonesEach test should clean up after itself so following tests don't need to worry about the current state and can just do its own prep.
--- riscv/sbi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
riscv/sbi.c +5 -5
@@ -394,6 +394,8 @@ static void ipi_hart_wait(void *data)timer_stop ();local_ipi_disable ();timer_irq_disable (); +install_irq_handler (IRQ_S_SOFT ,NULL ); +install_irq_handler (IRQ_S_TIMER ,NULL );cpumask_set_cpu (me, &ipi_done); }
@@ -1395,9 +1397,6 @@ static void check_susp(void)struct sbiret ret;int testnum, i; -local_irq_disable (); -timer_stop (); -report_prefix_push ("susp" );timer_setup (susp_timer);
@@ -1428,8 +1427,8 @@ static void check_susp(void)if (!params.returns && ret.error ==SBI_ERR_NOT_SUPPORTED ) {report_skip ("SUSP not supported?" ); -report_prefix_popn (2 ); -return ; +report_prefix_pop (); + goto out; }else if (!params.returns) {report_fail ("unexpected return with error: %ld, value: %ld" , ret.error, ret.value); }else {
@@ -1450,6 +1449,7 @@ static void check_susp(void)report_prefix_pop (); } +out:local_irq_disable ();timer_teardown ();
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 7/11 lib/cpumask: Add some operators
In reply to Andrew JonesWe have a need for cpumask_andnot(). Add that and a few friends.
--- lib/cpumask.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
lib/cpumask.h +56 -0
@@ -72,6 +72,62 @@ static inline bool cpumask_subset(const struct cpumask *src1, const struct cpumareturn !lastmask || !((cpumask_bits (src1)[i] & ~cpumask_bits (src2)[i]) & lastmask); } +/* false if dst is empty */ +static inline bool cpumask_and (cpumask_t *dst,const cpumask_t *src1,const cpumask_t *src2) +{ +unsigned long lastmask =BIT_MASK (nr_cpus) -1 ; +unsigned long ret =0 ; +int i; + +for (i =0 ; i <BIT_WORD (nr_cpus); ++i) { +cpumask_bits (dst)[i] =cpumask_bits (src1)[i] &cpumask_bits (src2)[i]; + ret |=cpumask_bits (dst)[i]; + } + +cpumask_bits (dst)[i] = (cpumask_bits (src1)[i] &cpumask_bits (src2)[i]) & lastmask; + +return ret |cpumask_bits (dst)[i]; +} + +static inline void cpumask_or (cpumask_t *dst,const cpumask_t *src1,const cpumask_t *src2) +{ +unsigned long lastmask =BIT_MASK (nr_cpus) -1 ; +int i; + +for (i =0 ; i <BIT_WORD (nr_cpus); ++i) +cpumask_bits (dst)[i] =cpumask_bits (src1)[i] |cpumask_bits (src2)[i]; + +cpumask_bits (dst)[i] = (cpumask_bits (src1)[i] |cpumask_bits (src2)[i]) & lastmask; +} + +static inline void cpumask_xor (cpumask_t *dst,const cpumask_t *src1,const cpumask_t *src2) +{ +unsigned long lastmask =BIT_MASK (nr_cpus) -1 ; +int i; + +for (i =0 ; i <BIT_WORD (nr_cpus); ++i) +cpumask_bits (dst)[i] =cpumask_bits (src1)[i] ^cpumask_bits (src2)[i]; + +cpumask_bits (dst)[i] = (cpumask_bits (src1)[i] ^cpumask_bits (src2)[i]) & lastmask; +} + +/* false if dst is empty */ +static inline bool cpumask_andnot (cpumask_t *dst,const cpumask_t *src1,const cpumask_t *src2) +{ +unsigned long lastmask =BIT_MASK (nr_cpus) -1 ; +unsigned long ret =0 ; +int i; + +for (i =0 ; i <BIT_WORD (nr_cpus); ++i) { +cpumask_bits (dst)[i] =cpumask_bits (src1)[i] & ~cpumask_bits (src2)[i]; + ret |=cpumask_bits (dst)[i]; + } + +cpumask_bits (dst)[i] = (cpumask_bits (src1)[i] & ~cpumask_bits (src2)[i]) & lastmask; + +return ret |cpumask_bits (dst)[i]; +} +static inline bool cpumask_equal (const struct cpumask *src1,const struct cpumask *src2) {unsigned long lastmask =BIT_MASK (nr_cpus) -1 ;
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 8/11 riscv: sbi: HSM suspend may not be supported
In reply to Andrew JonesThe spec doesn't require that any suspend types are supported and indeed KVM doesn't support non-retentive suspend. Tolerate SBI_ERR_NOT_SUPPORTED.
TODO: The HSM tests have lots of duplicated code and this patch adds even more. We need to refactor them and we should break them out into their own riscv/sbi-hsm.c file too.
--- riscv/sbi.c | 87 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 70 insertions(+), 17 deletions(-)
riscv/sbi.c +70 -17
@@ -571,6 +571,8 @@ static void hart_start_invalid_hartid(void *data) sbi_hsm_invalid_hartid_check = true; } +static cpumask_t hsm_suspend_not_supported; +static void ipi_nop (struct pt_regs *regs) {ipi_ack ();
@@ -587,7 +589,9 @@ static void hart_suspend_and_wait_ipi(unsigned long suspend_type, unsigned longlocal_irq_enable (); ret =sbi_hart_suspend_raw (suspend_type, resume_addr, opaque); -if (ret.error) +if (ret.error ==SBI_ERR_NOT_SUPPORTED ) +cpumask_set_cpu (smp_processor_id (), &hsm_suspend_not_supported); +else if (ret.error)report_fail ("failed to %s cpu%d (hartid = %lx) (error=%ld)" , typestr,smp_processor_id (), hartid, ret.error);else if (!returns)
@@ -707,7 +711,7 @@ static void check_hsm(void) {struct sbiret ret;unsigned long hartid; -cpumask_t secondary_cpus_mask, mask; +cpumask_t secondary_cpus_mask, mask, resume_mask;struct hart_state_transition_info transition_states;bool ipi_unavailable = false;int cpu, me =smp_processor_id ();
@@ -715,7 +719,7 @@ static void check_hsm(void)unsigned long hsm_timer_duration =getenv ("SBI_HSM_TIMER_DURATION" ) ?strtol (getenv ("SBI_HSM_TIMER_DURATION" ),NULL ,0 ) :200000 ;unsigned long sbi_hsm_hart_start_params[NR_CPUS *SBI_HSM_NUM_OF_PARAMS ]; -int count, check; +int count, check, expected_count, resume_count; max_cpus =MIN (MIN (max_cpus, nr_cpus),cpumask_weight (&cpu_present_mask));
@@ -879,6 +883,7 @@ static void check_hsm(void) goto sbi_hsm_hart_stop_tests; } +cpumask_clear (&hsm_suspend_not_supported);on_cpumask_async (&secondary_cpus_mask, hart_retentive_suspend,NULL ); transition_states = (struct hart_state_transition_info ) {
@@ -888,22 +893,36 @@ static void check_hsm(void) }; count =hart_wait_state_transition (&secondary_cpus_mask, hsm_timer_duration, &transition_states); -report (count == max_cpus -1 ,"all secondary harts retentive suspended" ); + expected_count = max_cpus -1 -cpumask_weight (&hsm_suspend_not_supported); + +if (expected_count !=0 ) { +if (expected_count != max_cpus -1 ) +report_info ("not all harts support retentive suspend" ); +report (count == expected_count,"supporting secondary harts retentive suspended" ); + }else { +report_skip ("retentive suspend not supported by any harts" ); + goto nonret_suspend_tests; + } + +cpumask_andnot (&resume_mask, &secondary_cpus_mask, &hsm_suspend_not_supported); + resume_count =cpumask_weight (&resume_mask);/* Ignore the return value since we check the status of each hart anyway */ -sbi_send_ipi_cpumask (&secondary_cpus_mask); +sbi_send_ipi_cpumask (&resume_mask); transition_states = (struct hart_state_transition_info ) { .initial_state =SBI_EXT_HSM_SUSPENDED , .intermediate_state =SBI_EXT_HSM_RESUME_PENDING , .final_state =SBI_EXT_HSM_STARTED , }; - count =hart_wait_state_transition (&secondary_cpus_mask, hsm_timer_duration, &transition_states); + count =hart_wait_state_transition (&resume_mask, hsm_timer_duration, &transition_states); -report (count == max_cpus -1 ,"all secondary harts retentive resumed" ); +report (count == resume_count,"supporting secondary harts retentive resumed" ); +nonret_suspend_tests:hart_wait_until_idle (&secondary_cpus_mask, hsm_timer_duration); +cpumask_clear (&hsm_suspend_not_supported);on_cpumask_async (&secondary_cpus_mask, hart_non_retentive_suspend,NULL ); transition_states = (struct hart_state_transition_info ) {
@@ -913,20 +932,32 @@ static void check_hsm(void) }; count =hart_wait_state_transition (&secondary_cpus_mask, hsm_timer_duration, &transition_states); -report (count == max_cpus -1 ,"all secondary harts non-retentive suspended" ); + expected_count = max_cpus -1 -cpumask_weight (&hsm_suspend_not_supported); + +if (expected_count !=0 ) { +if (expected_count != max_cpus -1 ) +report_info ("not all harts support non-retentive suspend" ); +report (count == expected_count,"supporting secondary harts non-retentive suspended" ); + }else { +report_skip ("non-retentive suspend not supported by any harts" ); + goto hsm_suspend_tests_done; + } + +cpumask_andnot (&resume_mask, &secondary_cpus_mask, &hsm_suspend_not_supported); + resume_count =cpumask_weight (&resume_mask);/* Ignore the return value since we check the status of each hart anyway */ -sbi_send_ipi_cpumask (&secondary_cpus_mask); +sbi_send_ipi_cpumask (&resume_mask); transition_states = (struct hart_state_transition_info ) { .initial_state =SBI_EXT_HSM_SUSPENDED , .intermediate_state =SBI_EXT_HSM_RESUME_PENDING , .final_state =SBI_EXT_HSM_STARTED , }; - count =hart_wait_state_transition (&secondary_cpus_mask, hsm_timer_duration, &transition_states); + count =hart_wait_state_transition (&resume_mask, hsm_timer_duration, &transition_states); check =0 ; -for_each_cpu (cpu, &secondary_cpus_mask) { +for_each_cpu (cpu, &resume_mask) { sbi_hsm_timer_fired = false;timer_start (hsm_timer_duration);
@@ -952,15 +983,16 @@ static void check_hsm(void) check++; } -report (count == max_cpus -1 ,"all secondary harts non-retentive resumed" ); -report (check == max_cpus -1 ,"all secondary harts have expected register values after non-retentive resume" ); +report (count == resume_count,"supporting secondary harts non-retentive resumed" ); +report (check == resume_count,"supporting secondary harts have expected register values after non-retentive resume" ); +hsm_suspend_tests_done:report_prefix_pop (); sbi_hsm_hart_stop_tests:report_prefix_push ("hart_stop" ); -if (ipi_unavailable) +if (ipi_unavailable || expected_count ==0 )on_cpumask_async (&secondary_cpus_mask, stop_cpu,NULL );else memset (sbi_hsm_stop_hart,1 ,sizeof (sbi_hsm_stop_hart));
@@ -994,6 +1026,7 @@ sbi_hsm_hart_stop_tests:/* Boot up the secondary cpu and let it proceed to the idle loop */ on_cpu (cpu, start_cpu,NULL ); +cpumask_clear (&hsm_suspend_not_supported);on_cpu_async (cpu, hart_retentive_suspend_with_msb_set,NULL ); transition_states = (struct hart_state_transition_info ) {
@@ -1003,7 +1036,14 @@ sbi_hsm_hart_stop_tests: }; count =hart_wait_state_transition (&mask, hsm_timer_duration, &transition_states); -report (count,"secondary hart retentive suspended with MSB set" ); + expected_count =1 -cpumask_weight (&hsm_suspend_not_supported); + +if (expected_count) { +report (count == expected_count,"retentive suspend with MSB set" ); + }else { +report_skip ("retentive suspend not supported by cpu%d" , cpu); + goto nonret_suspend_with_msb; + }/* Ignore the return value since we manually validate the status of the hart anyway */ sbi_send_ipi_cpu (cpu);
@@ -1017,10 +1057,12 @@ sbi_hsm_hart_stop_tests:report (count,"secondary hart retentive resumed with MSB set" ); +nonret_suspend_with_msb:/* Reset these flags so that we can reuse them for the non-retentive suspension test */ sbi_hsm_stop_hart[cpu] =0 ; sbi_hsm_non_retentive_hart_suspend_checks[cpu] =0 ; +cpumask_clear (&hsm_suspend_not_supported);on_cpu_async (cpu, hart_non_retentive_suspend_with_msb_set,NULL ); transition_states = (struct hart_state_transition_info ) {
@@ -1030,7 +1072,14 @@ sbi_hsm_hart_stop_tests: }; count =hart_wait_state_transition (&mask, hsm_timer_duration, &transition_states); -report (count,"secondary hart non-retentive suspended with MSB set" ); + expected_count =1 -cpumask_weight (&hsm_suspend_not_supported); + +if (expected_count) { +report (count == expected_count,"non-retentive suspend with MSB set" ); + }else { +report_skip ("non-retentive suspend not supported by cpu%d" , cpu); + goto hsm_hart_stop_test; + }/* Ignore the return value since we manually validate the status of the hart anyway */ sbi_send_ipi_cpu (cpu);
@@ -1071,11 +1120,15 @@ sbi_hsm_hart_stop_tests:report (count,"secondary hart non-retentive resumed with MSB set" );report (check,"secondary hart has expected register values after non-retentive resume with MSB set" ); +hsm_hart_stop_test:report_prefix_pop ();report_prefix_push ("hart_stop" ); - sbi_hsm_stop_hart[cpu] =1 ; +if (expected_count ==0 ) +on_cpu_async (cpu, stop_cpu,NULL ); +else + sbi_hsm_stop_hart[cpu] =1 ; transition_states = (struct hart_state_transition_info ) { .initial_state =SBI_EXT_HSM_STARTED ,
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 9/11 riscv: sbi: Probe/skip SUSP
In reply to Andrew JonesCleanly skip testing suspend when the SUSP extension isn't available.
--- riscv/sbi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
riscv/sbi.c +7 -1
@@ -1452,6 +1452,12 @@ static void check_susp(void)report_prefix_push ("susp" ); +if (!sbi_probe (SBI_EXT_SUSP )) { +report_skip ("SUSP extension not available" ); +report_prefix_pop (); +return ; + } +timer_setup (susp_timer);local_irq_enable ();timer_start (SBI_SUSP_TIMER_DURATION_US );
@@ -1479,7 +1485,7 @@ static void check_susp(void)local_irq_enable ();if (!params.returns && ret.error ==SBI_ERR_NOT_SUPPORTED ) { -report_skip ("SUSP not supported?" ); +report_fail ("probing claims support, but it's not?" );report_prefix_pop (); goto out; }else if (!params.returns) {
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 10/11 riscv: sbi: susp: Check upper bits of sleep_type are ignored
In reply to Andrew JonesWhen an SBI function parameter has a specific bit width which is less than that of a long, then the upper bits should be ignored by the SBI implementation. I.e. since sleep_type is a uint32_t, then on rv64 both 0 and 0x1_0000_0000 are valid and mean suspend to ram.
--- riscv/sbi.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
riscv/sbi.c +26 -6
@@ -67,7 +67,7 @@ static struct sbiret sbi_hart_suspend_raw(unsigned long suspend_type, unsigned lreturn sbi_ecall (SBI_EXT_HSM ,SBI_EXT_HSM_HART_SUSPEND , suspend_type, resume_addr, opaque,0 ,0 ,0 ); } -static struct sbiret sbi_system_suspend (uint32_t sleep_type,unsigned long resume_addr,unsigned long opaque) +static struct sbiret sbi_system_suspend_raw (unsigned long sleep_type,unsigned long resume_addr,unsigned long opaque) {return sbi_ecall (SBI_EXT_SUSP ,0 , sleep_type, resume_addr, opaque,0 ,0 ,0 ); }
@@ -1367,6 +1367,19 @@ static bool susp_type_prep(unsigned long ctx[], struct susp_params *params)return true; } +#if __riscv_xlen !=32 +static bool susp_type_prep2 (unsigned long ctx[],struct susp_params *params) +{ +bool r; + + r =susp_basic_prep (ctx, params); +assert (r); + params->sleep_type =BIT (32 ); + +return true; +} +#endif +static bool susp_badaddr_prep (unsigned long ctx[],struct susp_params *params) {phys_addr_t badaddr;
@@ -1432,6 +1445,7 @@ static void check_susp(void)#define SUSP_FIRST_TESTNUM 1SUSP_BASIC =SUSP_FIRST_TESTNUM ,SUSP_TYPE , +SUSP_TYPE2 ,SUSP_BAD_ADDR ,SUSP_ONE_ONLINE , NR_SUSP_TESTS,
@@ -1441,10 +1455,13 @@ static void check_susp(void)bool (*prep)(unsigned long ctx[],struct susp_params *params);void (*check)(unsigned long ctx[],struct susp_params *params); } susp_tests[] = { - [SUSP_BASIC] = { "basic", susp_basic_prep, susp_basic_check, }, - [SUSP_TYPE] = { "sleep_type", susp_type_prep, }, - [SUSP_BAD_ADDR] = { "bad addr", susp_badaddr_prep, }, - [SUSP_ONE_ONLINE] = { "one cpu online", susp_one_prep, }, + [SUSP_BASIC] = { "basic", susp_basic_prep, susp_basic_check, }, + [SUSP_TYPE] = { "sleep_type", susp_type_prep, }, +#if __riscv_xlen != 32 + [SUSP_TYPE2] = { "sleep_type upper bits", susp_type_prep2, susp_basic_check }, +#endif + [SUSP_BAD_ADDR] = { "bad addr", susp_badaddr_prep, }, + [SUSP_ONE_ONLINE] = { "one cpu online", susp_one_prep, }, };struct susp_params params;struct sbiret ret;
@@ -1466,6 +1483,9 @@ static void check_susp(void)report (ret.error ==SBI_ERR_NOT_SUPPORTED ,"funcid != 0 not supported" );for (i =SUSP_FIRST_TESTNUM ; i <NR_SUSP_TESTS ; i++) { +if (!susp_tests[i].name) +continue ; +report_prefix_push (susp_tests[i].name); ctx[SBI_SUSP_TESTNUM_IDX ] = i;
@@ -1480,7 +1500,7 @@ static void check_susp(void) }if ((testnum =setjmp (sbi_susp_jmp)) ==0 ) { - ret =sbi_system_suspend (params.sleep_type, params.resume_addr, params.opaque); + ret =sbi_system_suspend_raw (params.sleep_type, params.resume_addr, params.opaque);local_irq_enable ();
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
PATCH v2 11/11 riscv: sbi: Add bad fid tests
In reply to Andrew JonesEnsure we get the correct error code when attempting to use an invalid FID.
--- riscv/sbi-fwft.c | 2 ++ riscv/sbi-tests.h | 2 ++ riscv/sbi.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+)
riscv/sbi-fwft.c +2 -0
@@ -339,6 +339,8 @@ void check_fwft(void)return ; } +sbi_bad_fid (SBI_EXT_FWFT ); +fwft_check_base ();fwft_check_misaligned_exc_deleg ();fwft_check_pte_ad_hw_updating ();
riscv/sbi-tests.h +2 -0
@@ -70,5 +70,7 @@#define sbiret_check (ret, expected_error, expected_value) \ sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value") +void sbi_bad_fid (int ext); +#endif /* __ASSEMBLY__ */ #endif /* _RISCV_SBI_TESTS_H_ */
riscv/sbi.c +18 -0
@@ -72,6 +72,12 @@ static struct sbiret sbi_system_suspend_raw(unsigned long sleep_type, unsigned lreturn sbi_ecall (SBI_EXT_SUSP ,0 , sleep_type, resume_addr, opaque,0 ,0 ,0 ); } +void sbi_bad_fid (int ext) +{ +struct sbiret ret =sbi_ecall (ext,0xbad ,0 ,0 ,0 ,0 ,0 ,0 ); +sbiret_report_error (&ret,SBI_ERR_NOT_SUPPORTED ,"Bad FID" ); +} +static void start_cpu (void *data) {/* nothing to do */
@@ -178,6 +184,8 @@ static void check_base(void)report_prefix_push ("base" ); +sbi_bad_fid (SBI_EXT_BASE ); + ret =sbi_base (SBI_EXT_BASE_GET_SPEC_VERSION ,0 );report_prefix_push ("spec_version" );
@@ -331,6 +339,8 @@ static void check_time(void)return ; } +sbi_bad_fid (SBI_EXT_TIME ); +report_prefix_push ("set_timer" );install_irq_handler (IRQ_S_TIMER , timer_irq_handler);
@@ -438,6 +448,8 @@ static void check_ipi(void)return ; } +sbi_bad_fid (SBI_EXT_IPI ); +if (nr_cpus_present <2 ) {report_skip ("At least 2 cpus required" );report_prefix_pop ();
@@ -731,6 +743,8 @@ static void check_hsm(void)return ; } +sbi_bad_fid (SBI_EXT_HSM ); +report_prefix_push ("hart_get_status" ); hartid =current_thread_info ()->hartid;
@@ -1210,6 +1224,8 @@ static void check_dbcn(void)return ; } +sbi_bad_fid (SBI_EXT_DBCN ); +report_prefix_push ("write" );dbcn_write_test (DBCN_WRITE_TEST_STRING , num_bytes, false);
@@ -1475,6 +1491,8 @@ static void check_susp(void)return ; } +sbi_bad_fid (SBI_EXT_SUSP ); +timer_setup (susp_timer);local_irq_enable ();timer_start (SBI_SUSP_TIMER_DURATION_US );
Signature · 7 lines
2.48.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Re: [kvm-unit-tests PATCH v2 11/11] riscv: sbi: Add bad fid tests
Quoted 98 lines · Andrew Jones
Ensure we get the correct error code when attempting to use an invalid FID.
Signed-off-by Andrew Jones <[email protected]>--- riscv/sbi-fwft.c | 2 ++ riscv/sbi-tests.h | 2 ++ riscv/sbi.c | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+)riscv/sbi-fwft.c +2
-0@@ -339,6 +339,8 @@ void check_fwft(void)return ; } +sbi_bad_fid (SBI_EXT_FWFT ); +fwft_check_base ();fwft_check_misaligned_exc_deleg ();fwft_check_pte_ad_hw_updating ();riscv/sbi-tests.h +2
-0@@ -70,5 +70,7 @@#define sbiret_check (ret, expected_error, expected_value) \ sbiret_report(ret, expected_error, expected_value, "check sbi.error and sbi.value") +void sbi_bad_fid (int ext); +#endif /* __ASSEMBLY__ */ #endif /* _RISCV_SBI_TESTS_H_ */ riscv/sbi.c +16
-0@@ -72,6 +72,12 @@ static struct sbiret sbi_system_suspend_raw(unsigned long sleep_type, unsigned lreturn sbi_ecall (SBI_EXT_SUSP ,0 , sleep_type, resume_addr, opaque,0 ,0 ,0 ); } +void sbi_bad_fid (int ext) +{ +struct sbiret ret =sbi_ecall (ext,0xbad ,0 ,0 ,0 ,0 ,0 ,0 ); +sbiret_report_error (&ret,SBI_ERR_NOT_SUPPORTED ,"Bad FID" ); +} +static void start_cpu (void *data) {/* nothing to do */ @@ -178,6 +184,8 @@ static void check_base(void)report_prefix_push ("base" ); +sbi_bad_fid (SBI_EXT_BASE ); + ret =sbi_base (SBI_EXT_BASE_GET_SPEC_VERSION ,0 );report_prefix_push ("spec_version" );@@ -331,6 +339,8 @@ static void check_time(void)return ; } +sbi_bad_fid (SBI_EXT_TIME ); +report_prefix_push ("set_timer" );install_irq_handler (IRQ_S_TIMER , timer_irq_handler);@@ -438,6 +448,8 @@ static void check_ipi(void)return ; } +sbi_bad_fid (SBI_EXT_IPI ); +if (nr_cpus_present <2 ) {report_skip ("At least 2 cpus required" );report_prefix_pop ();@@ -731,6 +743,8 @@ static void check_hsm(void)return ; } +sbi_bad_fid (SBI_EXT_HSM ); +report_prefix_push ("hart_get_status" ); hartid =current_thread_info ()->hartid;@@ -1210,6 +1224,8 @@ static void check_dbcn(void)return ; } +sbi_bad_fid (SBI_EXT_DBCN ); +report_prefix_push ("write" );dbcn_write_test (DBCN_WRITE_TEST_STRING , num_bytes, false);
riscv/sbi.c static void check_susp(void) · line 1498
Quoted 8 lines
riscv/sbi.c +2
-0@@ -1475,6 +1491,8 @@ static void check_susp(void)return ; } +sbi_bad_fid (SBI_EXT_SUSP ); +timer_setup (susp_timer);local_irq_enable ();timer_start (SBI_SUSP_TIMER_DURATION_US );
Hi Andrew,
Even though it does not validate *all* invalid fid (which would be of course too long), at least that's something.
Thanks,
Clément
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv
Quoted 14 lines · Andrew Jones
Improvements:
- Ensure system suspend test won't hang
- Ensure HSM suspend tests won't hang
- Ensure state is cleaned up at the end of one extension's test before starting another
- Probe SUSP and skip cleanly
- Minor SUSP test output improvement
- Dropped upper bits fwft test formisaligned_exc_delegNew tests:
- Check bad FIDs for all extensions
- Check SUSPsleep_typeupper bits are ignored on RV64
- FWFT pte-hw-ad-updating tests
Quoted 6 lines
v2:
- Dropped upper bits fwft test formisaligned_exc_delegrather than change to kfail
- Added FWFT pte-hw-ad-updating tests
- Added a couple Clément tags
Merged.
Thanks,
drew
Signature · 3 lines
kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv