A few miscellaneous fixes
Subsystems (3)
cover A few miscellaneous fixes
While recently working on kvm-unit-tests I found a few bugs. Posting the patches now since the series I'm working on may not get merged for awhile.
Andrew Jones (3):
lib/string: Fix getenv name matching
scripts: Save rematch before calling out of for_each_unittest arm/arm64: Change dcache_line_size to ulong
lib/arm/asm/processor.h | 2 +- lib/arm/setup.c | 2 +- lib/arm64/asm/processor.h | 2 +- lib/string.c | 5 ++++- scripts/common.bash | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/3 lib/string: Fix getenv name matching
Without confirming that the name length exactly matches too, then the string comparison would return the same value for VAR* as for VAR, when VAR came first in the environ array.
--- lib/string.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/string.c +4 -1
@@ -171,10 +171,13 @@ extern char **environ;char *getenv (const char *name) {char **envp = environ, *delim; +int len;while (*envp) { delim =strchr (*envp,'=' ); -if (delim &&strncmp (name, *envp, delim - *envp) ==0 ) +assert (delim); + len = delim - *envp; +if (strlen (name) == len &&strncmp (name, *envp, len) ==0 )return delim +1 ; ++envp; }
Signature · 1 line
2.26.2
Re: [PATCH kvm-unit-tests 1/3] lib/string: Fix getenv name matching
Quoted 19 lines · Andrew Jones
Without confirming that the name length exactly matches too, then the string comparison would return the same value for VAR* as for VAR, when VAR came first in the environ array.
Signed-off-by Andrew Jones <[email protected]>--- lib/string.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)lib/string.c +1
-0@@ -171,10 +171,13 @@ extern char **environ;char *getenv (const char *name) {char **envp = environ, *delim; +int len;
lib/string.c extern char **environ; · line 183
Quoted 10 lines
lib/string.c +3
-1while (*envp) { delim =strchr (*envp,'=' ); -if (delim &&strncmp (name, *envp, delim - *envp) ==0 ) +assert (delim); + len = delim - *envp; +if (strlen (name) == len &&strncmp (name, *envp, len) ==0 )return delim +1 ; ++envp; }
Paolo Bonzini
maintainerRe: [PATCH kvm-unit-tests 1/3] lib/string: Fix getenv name matching
In reply to Andrew JonesQuoted 5 lines · Andrew Jones
+ if (strlen(name) == len &&
strncmp(name, *envp, len)== 0)return delim + 1; ++envp; }-- 2.26.2
Slightly more efficient:
+ if (memcmp(name, *envp, len) == 0 && !name[len])
(strncmp is not needed since we know there's no NULL between *envp and *envp+len, and after memcmp we know the same about the first len characters of name).
Paolo
PATCH 2/3 scripts: Save rematch before calling out of for_each_unittest
In reply to Andrew JonesIf we don't save BASH_REMATCH before calling another function, and that other function also uses [[...]], then we'll lose the test.
--- scripts/common.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/common.bash +3 -1
@@ -13,15 +13,17 @@ function for_each_unittest() local check local accel local timeout + local rematch exec {fd}<"$unittests" while read -r -u $fd line; do if [[ "$line" =~ ^\[(.*)\]$ ]]; then + rematch=${BASH_REMATCH[1]} if [ -n "${testname}" ]; then $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" fi - testname=${BASH_REMATCH[1]} + testname=$rematch smp=1 kernel="" opts=""
Signature · 1 line
2.26.2
Re: [PATCH kvm-unit-tests 2/3] scripts: Save rematch before calling out of for_each_unittest
Quoted 23 lines · Andrew Jones
If we don't save
BASH_REMATCHbefore calling another function, and that other function also uses [[...]], then we'll lose the test.Signed-off-by Andrew Jones <[email protected]>--- scripts/common.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)scripts/common.bash +1
-0@@ -13,15 +13,17 @@ function for_each_unittest() local check local accel local timeout + local rematch exec {fd}<"$unittests" while read -r -u $fd line; do
scripts/common.bash function for_each_unittest() · line 29
Quoted 10 lines
scripts/common.bash +2
-1if [[ "$line" =~ ^\[(.*)\]$ ]]; then + rematch=${BASH_REMATCH[1]} if [ -n "${testname}" ]; then $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" fi - testname=${BASH_REMATCH[1]} + testname=$rematch smp=1 kernel="" opts=""
PATCH 3/3 arm/arm64: Change dcache_line_size to ulong
In reply to Andrew Jonesdcache_line_size is treated like a long in assembly, so make it one.
--- lib/arm/asm/processor.h | 2 +- lib/arm/setup.c | 2 +- lib/arm64/asm/processor.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
lib/arm/asm/processor.h +1 -1
@@ -89,6 +89,6 @@ static inline u32 get_ctr(void) return read_sysreg(CTR); } -extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* _ASMARM_PROCESSOR_H_ */
lib/arm/setup.c +1 -1
@@ -42,7 +42,7 @@ static struct mem_region __initial_mem_regions[NR_INITIAL_MEM_REGIONS + 1];struct mem_region *mem_regions = __initial_mem_regions;phys_addr_t __phys_offset, __phys_end; -u32 dcache_line_size; +unsigned long dcache_line_size;int mpidr_to_cpu (uint64_t mpidr) {
lib/arm64/asm/processor.h +1 -1
@@ -115,7 +115,7 @@ static inline u64 get_ctr(void)return read_sysreg (ctr_el0); } -extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PROCESSOR_H_ */
Signature · 1 line
2.26.2
Re: [PATCH kvm-unit-tests 3/3] arm/arm64: Change dcache_line_size to ulong
Quoted 40 lines · Andrew Jones
dcache_line_sizeis treated like a long in assembly, so make it one.Signed-off-by Andrew Jones <[email protected]>--- lib/arm/asm/processor.h | 2 +- lib/arm/setup.c | 2 +- lib/arm64/asm/processor.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)lib/arm/asm/processor.h +1
-1@@ -89,6 +89,6 @@ static inline u32 get_ctr(void) return read_sysreg(CTR); } -extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* _ASMARM_PROCESSOR_H_ */ lib/arm/setup.c +1
-1@@ -42,7 +42,7 @@ static struct mem_region __initial_mem_regions[NR_INITIAL_MEM_REGIONS + 1];struct mem_region *mem_regions = __initial_mem_regions;phys_addr_t __phys_offset, __phys_end; -u32 dcache_line_size; +unsigned long dcache_line_size;int mpidr_to_cpu (uint64_t mpidr) {lib/arm64/asm/processor.h +0
-0
lib/arm64/asm/processor.h static inline u64 get_ctr(void) · line 121
Quoted 8 lines
lib/arm64/asm/processor.h +1
-1@@ -115,7 +115,7 @@ static inline u64 get_ctr(void)return read_sysreg (ctr_el0); } -extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PROCESSOR_H_ */
Re: [PATCH kvm-unit-tests 3/3] arm/arm64: Change dcache_line_size to ulong
Quoted 43 lines · Thomas Huth
Quoted 42 lines · Andrew Jones
dcache_line_sizeis treated like a long in assembly, so make it one.Signed-off-by Andrew Jones <[email protected]>--- lib/arm/asm/processor.h | 2 +- lib/arm/setup.c | 2 +- lib/arm64/asm/processor.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)lib/arm/asm/processor.h +1
-1@@ -89,6 +89,6 @@ static inline u32 get_ctr(void) return read_sysreg(CTR); } -extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* _ASMARM_PROCESSOR_H_ */ lib/arm/setup.c +1
-1@@ -42,7 +42,7 @@ static struct mem_region __initial_mem_regions[NR_INITIAL_MEM_REGIONS + 1];struct mem_region *mem_regions = __initial_mem_regions;phys_addr_t __phys_offset, __phys_end; -u32 dcache_line_size; +unsigned long dcache_line_size;int mpidr_to_cpu (uint64_t mpidr) {lib/arm64/asm/processor.h +0
-0@@ -115,7 +115,7 @@ static inline u64 get_ctr(void)return read_sysreg (ctr_el0); }
Quoted 9 lines
lib/arm64/asm/processor.h static inline u64 get_ctr(void) · line 121
Quoted 6 lines
lib/arm64/asm/processor.h +1
-1-extern u32 dcache_line_size; +extern unsigned long dcache_line_size;#endif /* !__ASSEMBLY__ */ #endif /* _ASMARM64_PROCESSOR_H_ */ Reviewed-by Thomas Huth <[email protected]>
Queued all three, thanks.
Paolo
Re: [PATCH kvm-unit-tests 3/3] arm/arm64: Change dcache_line_size to ulong
Quoted 3 lines · Paolo Bonzini
Queued all three, thanks.
Hi Paolo,
Can you please push these?
Thanks,
drew