riscv: sbi: Improve DBCN and BASE
Subsystems (3)
cover riscv: sbi: Improve DBCN and BASE
Improve the tests for DBCN and BASE. For DBCN, use xfail when for failed highmem tests when we know the SBI implementation doesn't support highmem (such as 32-bit OpenSBI). For BASE, per the spec, ensure the bit 31 is zero and ensure we always treat bits 63:32 as UNKNOWN.
Andrew Jones (2):
riscv: sbi: Highmem isn't always supported
riscv: sbi: Improve spec version test
lib/riscv/sbi.c | 2 +- riscv/sbi.c | 38 ++++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 13 deletions(-)
Signature · 1 line
2.46.0
PATCH 1/2 riscv: sbi: Highmem isn't always supported
When an SBI implementation has opted not to support memory accesses above 4G (highmem), such as 32-bit OpenSBI, then report failures to access that memory as "expected failures". Use yet another environment variable to inform the testsuite of this SBI implementation behavior.
--- riscv/sbi.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
riscv/sbi.c +15 -8
@@ -288,7 +288,7 @@ static void check_time(void)#define DBCN_WRITE_TEST_STRING "DBCN_WRITE_TEST_STRING\n"#define DBCN_WRITE_BYTE_TEST_BYTE ((u8)'a') -static void dbcn_write_test (const char *s,unsigned long num_bytes) +static void dbcn_write_test (const char *s,unsigned long num_bytes,bool xfail) {unsigned long base_addr_lo, base_addr_hi;phys_addr_t paddr =virt_to_phys ((void *)s);
@@ -305,12 +305,13 @@ static void dbcn_write_test(const char *s, unsigned long num_bytes) num_calls++; }while (num_bytes !=0 && ret.error ==SBI_SUCCESS ); -report (ret.error ==SBI_SUCCESS ,"write success (error=%ld)" , ret.error); +report_xfail (xfail, ret.error ==SBI_SUCCESS ,"write success (error=%ld)" , ret.error);report_info ("%d sbi calls made" , num_calls); }static void dbcn_high_write_test (const char *s,unsigned long num_bytes, -phys_addr_t page_addr,size_t page_offset) +phys_addr_t page_addr,size_t page_offset, +bool highmem_supported) {int nr_pages = page_offset ?2 :1 ;void *vaddr;
@@ -326,7 +327,7 @@ static void dbcn_high_write_test(const char *s, unsigned long num_bytes,for (int i =0 ; i < nr_pages; ++i)install_page (current_pgtable (), page_addr + i *PAGE_SIZE , vaddr + i *PAGE_SIZE );memcpy (vaddr + page_offset,DBCN_WRITE_TEST_STRING , num_bytes); -dbcn_write_test (vaddr + page_offset, num_bytes); +dbcn_write_test (vaddr + page_offset, num_bytes, !highmem_supported); }/*
@@ -338,6 +339,7 @@ static void check_dbcn(void)unsigned long num_bytes =strlen (DBCN_WRITE_TEST_STRING );unsigned long base_addr_lo, base_addr_hi;bool do_invalid_addr = false; +bool highmem_supported = true;phys_addr_t paddr;struct sbiret ret;const char *tmp;
@@ -353,21 +355,26 @@ static void check_dbcn(void)report_prefix_push ("write" ); -dbcn_write_test (DBCN_WRITE_TEST_STRING , num_bytes); +dbcn_write_test (DBCN_WRITE_TEST_STRING , num_bytes, false);assert (num_bytes <PAGE_SIZE );report_prefix_push ("page boundary" ); buf =alloc_pages (1 );memcpy (&buf[PAGE_SIZE - num_bytes /2 ],DBCN_WRITE_TEST_STRING , num_bytes); -dbcn_write_test (&buf[PAGE_SIZE - num_bytes /2 ], num_bytes); +dbcn_write_test (&buf[PAGE_SIZE - num_bytes /2 ], num_bytes, false);report_prefix_pop (); + tmp =getenv ("SBI_HIGHMEM_NOT_SUPPORTED" ); +if (tmp &&atol (tmp) !=0 ) + highmem_supported = false; +report_prefix_push ("high boundary" ); tmp =getenv ("SBI_DBCN_SKIP_HIGH_BOUNDARY" );if (!tmp ||atol (tmp) ==0 )dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes, -HIGH_ADDR_BOUNDARY -PAGE_SIZE ,PAGE_SIZE - num_bytes /2 ); +HIGH_ADDR_BOUNDARY -PAGE_SIZE ,PAGE_SIZE - num_bytes /2 , + highmem_supported);else report_skip ("user disabled" );report_prefix_pop ();
@@ -379,7 +386,7 @@ static void check_dbcn(void) tmp =getenv ("HIGH_PAGE" );if (tmp) paddr =strtoull (tmp,NULL ,0 ); -dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes, paddr,0 ); +dbcn_high_write_test (DBCN_WRITE_TEST_STRING , num_bytes, paddr,0 , highmem_supported); }else {report_skip ("user disabled" ); }
Signature · 1 line
2.46.0
PATCH 2/2 riscv: sbi: Improve spec version test
In reply to Andrew JonesSBI spec version states that bit 31 must be zero and doesn't say anything about bits greater than 31 (for rv64). Check that bit 31 is zero and assume all other bits are UNKNOWN, so mask them off before testing.
--- lib/riscv/sbi.c | 2 +- riscv/sbi.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-)
lib/riscv/sbi.c +1 -1
@@ -97,7 +97,7 @@ long sbi_probe(int ext)struct sbiret ret; ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_GET_SPEC_VERSION ,0 ,0 ,0 ,0 ,0 ,0 ); -assert (!ret.error && ret.value >=2 ); +assert (!ret.error && (ret.value &0x7ffffffful ) >=2 ); ret =sbi_ecall (SBI_EXT_BASE ,SBI_EXT_BASE_PROBE_EXT , ext,0 ,0 ,0 ,0 ,0 );assert (!ret.error);
riscv/sbi.c +11 -4
@@ -105,18 +105,25 @@ static void check_base(void)report_prefix_push ("base" ); ret =sbi_base (SBI_EXT_BASE_GET_SPEC_VERSION ,0 ); -if (ret.error || ret.value <2 ) { -report_skip ("SBI spec version 0.2 or higher required" ); -return ; - } +if (!ret.error) + ret.value &=0xfffffffful ;report_prefix_push ("spec_version" );if (env_or_skip ("SBI_SPEC_VERSION" )) { expected = (long )strtoul (getenv ("SBI_SPEC_VERSION" ),NULL ,0 ); +assert_msg (!(expected &BIT (31 )),"SBI spec version bit 31 must be zero" ); +assert_msg (__riscv_xlen ==32 || !(expected >>32 ),"SBI spec version bits greater than 31 are UNKNOWN" );gen_report (&ret,0 , expected); }report_prefix_pop (); + ret.value &=0x7ffffffful ; + +if (ret.error || ret.value <2 ) { +report_skip ("SBI spec version 0.2 or higher required" ); +return ; + } +report_prefix_push ("impl_id" );if (env_or_skip ("SBI_IMPL_ID" )) { expected = (long )strtoul (getenv ("SBI_IMPL_ID" ),NULL ,0 );
Signature · 1 line
2.46.0
Re: [kvm-unit-tests PATCH 2/2] riscv: sbi: Improve spec version test
Quoted 4 lines · Andrew Jones
SBI spec version states that bit 31 must be zero and doesn't say anything about bits greater than 31 (for rv64). Check that bit 31 is zero and assume all other bits are UNKNOWN, so mask them off before testing.
The spec has changed for the 3.0 release to also require bits 32 and up to be zero for rv64. I'll send another version of this patch.
Thanks,
drew