diff mbox series

[kvmtool,v1,2/2] Do not a print a warning on failing host<->guest address translation

Message ID 20250120161800.30270-3-alexandru.elisei@arm.com (mailing list archive)
State New
Headers show
Series Error handling fixes | expand

Commit Message

Alexandru Elisei Jan. 20, 2025, 4:18 p.m. UTC
guest_flat_to_host() and host_to_guest_flat return NULL, respectively 0,
when the address is not found in the existing memslots. It is expected that
the calling code will handle this error.

However, both functions also print an error message containing the
offending address. This can be redundant, if the calling code also prints
the address, or even misleading, if the calling code can gracefully handle
the failure, like is the case in kvm__dump_mem().

Change the warning to a debug, since knowing the address might still be
useful for those call sites where the address isn't printed, or if the
error isn't handled at all.

Before, when running the PMU test from kvm-unit-tests using the test
runner, which redirects stdout (where kvm__dump_mem() writes) and stderr
(where pr_warning() writes):

  Error: KVM exit reason: 9 ("KVM_EXIT_FAIL_ENTRY")
  Warning: unable to translate guest address 0x0 to host

 Registers:

<snip>

*lr:
 0x00000000: <unknown>
 0x00000008: <unknown>
 0x00000010: <unknown>
 0x00000018: <unknown>

The error is caused by the VCPU migrating to a physical CPU with a
different PMU. In the example, the warning not only is unnecessary, but is
quite a distance away from the offending address and can confuse the person
looking at the code, like it happened to the patch author.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kvm.c b/kvm.c
index 42b881217df6..07089cf1b332 100644
--- a/kvm.c
+++ b/kvm.c
@@ -354,7 +354,7 @@  void *guest_flat_to_host(struct kvm *kvm, u64 offset)
 			return bank->host_addr + (offset - bank_start);
 	}
 
-	pr_warning("unable to translate guest address 0x%llx to host",
+	pr_debug("unable to translate guest address 0x%llx to host",
 			(unsigned long long)offset);
 	return NULL;
 }
@@ -371,7 +371,7 @@  u64 host_to_guest_flat(struct kvm *kvm, void *ptr)
 			return bank->guest_phys_addr + (ptr - bank_start);
 	}
 
-	pr_warning("unable to translate host address %p to guest", ptr);
+	pr_debug("unable to translate host address %p to guest", ptr);
 	return 0;
 }