Skip to contentSkip to conversation

selftests: Fix vm_handle_exception undefined error

PATCH In review Chen Lifu 3 participants 6 messages Jul 9, 2021 – Aug 16, 2021

Subsystems (2)
lore
Share & tools
lore

Chen Lifu

author
#0 lore raw

PATCH 1/2 selftests: Fix vm_handle_exception undefined error

Compile setftests on x86_64 occurs following error:
make -C tools/testing/selftests
...

x86_64/hyperv_features.c:618:2: warning: implicit declaration of function ‘vm_handle_exception’ [-Wimplicit-function-declaration]
618 | vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
/usr/bin/ld: /tmp/cclOnpml.o: in function `main':
tools/testing/selftests/kvm/x86_64/hyperv_features.c:618: undefined reference to `vm_handle_exception'
collect2: error: ld returned 1 exit status

The reason is that commit b78f4a596692 ("KVM: selftests: Rename vm_handle_exception") renamed "vm_handle_exception" function to "vm_install_exception_handler" function.

Fix it by replacing "vm_handle_exception" with "vm_install_exception_handler" in corresponding selftests files.

---
 tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +-
 tools/testing/selftests/kvm/x86_64/mmu_role_test.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/hyperv_features.c +1 -1
index 42bd658f52a8..af27c7e829c1 100644
@@ -615,7 +615,7 @@ int main(void)
 
 	vm_init_descriptor_tables(vm);
 	vcpu_init_descriptor_tables(vm, VCPU_ID);
-	vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
+	vm_install_exception_handler(vm, GP_VECTOR, guest_gp_handler);
 
 	pr_info("Testing access to Hyper-V specific MSRs\n");
 	guest_test_msrs_access(vm, addr_gva2hva(vm, msr_gva),
tools/testing/selftests/kvm/x86_64/mmu_role_test.c +1 -1
index 523371cf8e8f..da2325fcad87 100644
@@ -71,7 +71,7 @@ static void mmu_role_test(u32 *cpuid_reg, u32 evil_cpuid_val)
 	/* Set up a #PF handler to eat the RSVD #PF and signal all done! */
 	vm_init_descriptor_tables(vm);
 	vcpu_init_descriptor_tables(vm, VCPU_ID);
-	vm_handle_exception(vm, PF_VECTOR, guest_pf_handler);
+	vm_install_exception_handler(vm, PF_VECTOR, guest_pf_handler);
 
 	r = _vcpu_run(vm, VCPU_ID);
 	TEST_ASSERT(r == 0, "vcpu_run failed: %d\n", r);
Signature · 1 line
2.32.0
author
#1 lore raw

PATCH 2/2 selftests: Fix fscanf warning

Compile selftests occurs the following warnings:
make -C tools/testing/selftests
...

lib/test_util.c: In function ‘get_trans_hugepagesz’:
lib/test_util.c:138:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

  138 |  fscanf(f, "%ld", &size);
      |  ^~~~~~~~~~~~~~~~~~~~~~~
x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
x86_64/mmio_warning_test.c:85:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
   85 |  fscanf(f, "%d", &warnings);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64/xen_shinfo_test.c: In function ‘get_run_delay’:
x86_64/xen_shinfo_test.c:109:9: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  109 |         fscanf(fp, "%ld %ld ", &val[0], &val[1]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
steal_time.c: In function ‘get_run_delay’:
steal_time.c:228:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
  228 |  fscanf(fp, "%ld %ld ", &val[0], &val[1]);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check the return value of ‘fscanf’ to fix it.

---
 tools/testing/selftests/kvm/lib/test_util.c            | 3 ++-
 tools/testing/selftests/kvm/steal_time.c               | 3 ++-
 tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 3 ++-
 tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c   | 3 ++-
 4 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/kvm/lib/test_util.c +2 -1
index af1031fed97f..02ed0d5c3aa5 100644
@@ -135,7 +135,8 @@ size_t get_trans_hugepagesz(void)
 	f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
 	TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size");
 
-	fscanf(f, "%ld", &size);
+	if (fscanf(f, "%ld", &size) != 1)
+		size = 0;
 	fclose(f);
 
 	return size;
tools/testing/selftests/kvm/steal_time.c +2 -1
index b0031f2d38fd..18f231c45a12 100644
@@ -225,7 +225,8 @@ static long get_run_delay(void)
 
 	sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
 	fp = fopen(path, "r");
-	fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
 	fclose(fp);
 
 	return val[1];
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +2 -1
index e6480fd5c4bd..e770037e5cc9 100644
@@ -82,7 +82,8 @@ int get_warnings_count(void)
 	FILE *f;
 
 	f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
-	fscanf(f, "%d", &warnings);
+	if (fscanf(f, "%d", &warnings) != 1)
+		warnings = 0;
 	fclose(f);
 
 	return warnings;
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +2 -1
index 117bf49a3d79..6efda86083f1 100644
@@ -106,7 +106,8 @@ static long get_run_delay(void)
 
         sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
         fp = fopen(path, "r");
-        fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
         fclose(fp);
 
         return val[1];
Signature · 1 line
2.32.0
author
#2 lore raw

ping//Re: [PATCH -next 2/2] selftests: Fix fscanf warning

Quoted 88 lines · Chen Lifu

Compile selftests occurs the following warnings:
make -C tools/testing/selftests
...

lib/test_util.c: In function ‘get_trans_hugepagesz’:
lib/test_util.c:138:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]

   138 |  fscanf(f, "%ld", &size);
       |  ^~~~~~~~~~~~~~~~~~~~~~~
x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
x86_64/mmio_warning_test.c:85:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
    85 |  fscanf(f, "%d", &warnings);
       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64/xen_shinfo_test.c: In function ‘get_run_delay’:
x86_64/xen_shinfo_test.c:109:9: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
   109 |         fscanf(fp, "%ld %ld ", &val[0], &val[1]);
       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
steal_time.c: In function ‘get_run_delay’:
steal_time.c:228:2: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
   228 |  fscanf(fp, "%ld %ld ", &val[0], &val[1]);
       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check the return value of ‘fscanf’ to fix it.

---
  tools/testing/selftests/kvm/lib/test_util.c            | 3 ++-
  tools/testing/selftests/kvm/steal_time.c               | 3 ++-
  tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 3 ++-
  tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c   | 3 ++-
  4 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/kvm/lib/test_util.c +2 -1
index af1031fed97f..02ed0d5c3aa5 100644
@@ -135,7 +135,8 @@ size_t get_trans_hugepagesz(void)
  	f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
  	TEST_ASSERT(f != NULL, "Error in opening transparent_hugepage/hpage_pmd_size");
 
-	fscanf(f, "%ld", &size);
+	if (fscanf(f, "%ld", &size) != 1)
+		size = 0;
  	fclose(f);
 
  	return size;
tools/testing/selftests/kvm/steal_time.c +2 -1
index b0031f2d38fd..18f231c45a12 100644
@@ -225,7 +225,8 @@ static long get_run_delay(void)
 
  	sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
  	fp = fopen(path, "r");
-	fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
  	fclose(fp);
 
  	return val[1];
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +2 -1
index e6480fd5c4bd..e770037e5cc9 100644
@@ -82,7 +82,8 @@ int get_warnings_count(void)
  	FILE *f;
 
  	f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
-	fscanf(f, "%d", &warnings);
+	if (fscanf(f, "%d", &warnings) != 1)
+		warnings = 0;
  	fclose(f);
 
  	return warnings;
tools/testing/selftests/kvm/x86_64/xen_shinfo_test.c +2 -1
index 117bf49a3d79..6efda86083f1 100644
@@ -106,7 +106,8 @@ static long get_run_delay(void)
 
          sprintf(path, "/proc/%ld/schedstat", syscall(SYS_gettid));
          fp = fopen(path, "r");
-        fscanf(fp, "%ld %ld ", &val[0], &val[1]);
+	if (fscanf(fp, "%ld %ld ", &val[0], &val[1]) != 2)
+		val[1] = 0;
          fclose(fp);
 
          return val[1];
maintainer
#3 lore raw
In reply to Chen Lifu
Quoted 13 lines · Chen Lifu

Compile setftests on x86_64 occurs following error:
make -C tools/testing/selftests
...

x86_64/hyperv_features.c:618:2: warning: implicit declaration of function ‘vm_handle_exception’ [-Wimplicit-function-declaration]
618 | vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
/usr/bin/ld: /tmp/cclOnpml.o: in function `main':
tools/testing/selftests/kvm/x86_64/hyperv_features.c:618: undefined reference to `vm_handle_exception'
collect2: error: ld returned 1 exit status

The reason is that commit b78f4a596692 ("KVM: selftests: Rename vm_handle_exception") renamed "vm_handle_exception" function to "vm_install_exception_handler" function.

Quoted 9 lines

Fix it by replacing "vm_handle_exception" with "vm_install_exception_handler" in corresponding selftests files.

---
  tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +-
  tools/testing/selftests/kvm/x86_64/mmu_role_test.c   | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

Please include kvm in the commit summary. I think it is not getting the right attention because of the summary line.

Same for the second patch in this series.

thanks,
-- Shuah

maintainer Reviewed-by Andrew Jones Reviewed-by Ricardo Koller
#4 lore raw
Quoted 25 lines · Shuah Khan
Quoted 13 lines · Chen Lifu

Compile setftests on x86_64 occurs following error:
make -C tools/testing/selftests
...

x86_64/hyperv_features.c:618:2: warning: implicit declaration of function ‘vm_handle_exception’ [-Wimplicit-function-declaration] 618 |  vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
/usr/bin/ld: /tmp/cclOnpml.o: in function `main':
tools/testing/selftests/kvm/x86_64/hyperv_features.c:618: undefined reference to `vm_handle_exception'
collect2: error: ld returned 1 exit status

The reason is that commit b78f4a596692 ("KVM: selftests: Rename vm_handle_exception") renamed "vm_handle_exception" function to "vm_install_exception_handler" function.

Quoted 9 lines

Fix it by replacing "vm_handle_exception" with "vm_install_exception_handler" in corresponding selftests files.

---
  tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +- tools/testing/selftests/kvm/x86_64/mmu_role_test.c   | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines

Please include kvm in the commit summary. I think it is not getting the right attention because of the summary line.

The same patch was already committed:

commit f8f0edabcc09fafd695ed2adc0eb825104e35d5c
Author: Marc Zyngier <[email protected]>
Date: Thu Jul 1 08:19:28 2021 +0100

KVM: selftests: x86: Address missing vm_install_exception_handler conversions

Commit b78f4a59669 ("KVM: selftests: Rename vm_handle_exception") raced with a couple of new x86 tests, missing two vm_handle_exception to vm_install_exception_handler conversions.

Help the two broken tests to catch up with the new world.

Cc Andrew Jones <[email protected]>
CC Ricardo Koller <[email protected]>
Cc Paolo Bonzini <[email protected]>

Message-Id: <[email protected]>

For the other patch, returning 0 is going to cause issues elsewhere in the tests. Either the test is failed immediately, or all callers must be examined carefully.

Paolo

author
#5 lore raw

Thanks. Got it.

Quoted 57 lines · Paolo Bonzini
Quoted 25 lines · Shuah Khan
Quoted 13 lines · Chen Lifu

Compile setftests on x86_64 occurs following error:
make -C tools/testing/selftests
...

x86_64/hyperv_features.c:618:2: warning: implicit declaration of function ‘vm_handle_exception’ [-Wimplicit-function-declaration] 618 |  vm_handle_exception(vm, GP_VECTOR, guest_gp_handler);
/usr/bin/ld: /tmp/cclOnpml.o: in function `main':
tools/testing/selftests/kvm/x86_64/hyperv_features.c:618: undefined reference to `vm_handle_exception'
collect2: error: ld returned 1 exit status

The reason is that commit b78f4a596692 ("KVM: selftests: Rename vm_handle_exception") renamed "vm_handle_exception" function to "vm_install_exception_handler" function.

Quoted 9 lines

Fix it by replacing "vm_handle_exception" with "vm_install_exception_handler" in corresponding selftests files.

---
  tools/testing/selftests/kvm/x86_64/hyperv_features.c | 2 +- tools/testing/selftests/kvm/x86_64/mmu_role_test.c   | 2 +-

  2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines

Please include kvm in the commit summary. I think it is not getting the right attention because of the summary line.

The same patch was already committed:

   commit f8f0edabcc09fafd695ed2adc0eb825104e35d5c
   Author: Marc Zyngier <[email protected]> Date:   Thu Jul 1 08:19:28 2021 +0100

   KVM: selftests: x86: Address missing vm_install_exception_handler
conversions
   Commit b78f4a59669 ("KVM: selftests: Rename vm_handle_exception") raced with a couple of new x86 tests, missing two vm_handle_exception to vm_install_exception_handler conversions.
   Help the two broken tests to catch up with the new world.

Cc Andrew Jones <[email protected]>
CC Ricardo Koller <[email protected]>
Cc Paolo Bonzini <[email protected]>

   Message-Id: <[email protected]>

For the other patch, returning 0 is going to cause issues elsewhere in the tests.  Either the test is failed immediately, or all callers must be examined carefully.

Paolo

.