kvm:x86:Fix error handling in the function kvm_write_wall_clock
A message that is not in the archive (sent off-list or not yet received): [email protected]
Paolo Bonzini
maintainerQuoted 9 lines · Nicholas Krause
This fixes error handling in the function
kvm_write_wall_clockby checking if any of the calls tokvm_write_guesthave failed inside this paricutlar function and if so print to the console withpr_errthat we are unable to write the data to the guest system to warn the user of this failure before directly returning to the caller of the functionkvm_write_wall_checkas we cannot continue the function to this function after a failed call toSigned-off-by Nicholas Krause <[email protected]>
I think I have explained before why this is mostly unnecessary, but the patch can be saved. I'll go through the problems again first.
Review
Quoted 5 lines
(quoted diff) +4
-1- kvm_write_guest(kvm, wall_clock, &version, sizeof(version)); + if (kvm_write_guest(kvm, wall_clock, &version, sizeof(version))) { + pr_err("Unable to correctly write data to guest system\n"); + return; + }
You've written a message to the log that can be triggered by the guest (by writing an invalid value to the wall clock MSR). We don't let the guest spam the host logs.
Review static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) · line 1177
Quoted 11 lines
(quoted diff) +4
-1/* * The guest calculates current wall clock time by adding@@ -1168,10 +1171,16 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) wc.nsec = boot.tv_nsec; wc.version = version; - kvm_write_guest(kvm, wall_clock, &wc, sizeof(wc)); + if (kvm_write_guest(kvm, wall_clock, &wc, sizeof(wc))) { + pr_err("Unable to correctly write data to guest system\n"); + return; + }
The other kvm_write_guest will probably also fail but, if it doesn't, you've left an odd version in the data structure. The guest will loop forever waiting for the even value.
Plus, same problem with logs.
Review static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock) · line 1183
Quoted 7 lines
(quoted diff) +4
-1version++; - kvm_write_guest(kvm, wall_clock, &version, sizeof(version)); + if (kvm_write_guest(kvm, wall_clock, &version, sizeof(version))) { + pr_err("Unable to correctly write data to guest system\n"); + return; + } }
Same problem with logs, and the return is not useful.
Can you send a patch that only adds a return if the *first* kvm_write_guest fails? You can leave aside the others, and not add any pr_err.
Thanks,
Paolo
Quoted 2 lines
(quoted diff) +0
-0static uint32_t div_frac(uint32_t dividend, uint32_t divisor)