forked from luck/tmp_suning_uos_patched
KVM: Return immediately if __kvm_gfn_to_hva_cache_init() fails
Check the result of __kvm_gfn_to_hva_cache_init() and return immediately instead of relying on the kvm_is_error_hva() check to detect errors so that it's abundantly clear KVM intends to immediately bail on an error. Note, the hva check is still mandatory to handle errors on subqeuesnt calls with the same generation. Similarly, always return -EFAULT on error so that multiple (bad) calls for a given generation will get the same result, e.g. on an illegal gfn wrap, propagating the return from __kvm_gfn_to_hva_cache_init() would cause the initial call to return -EINVAL and subsequent calls to return -EFAULT. Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
6ad1e29fe0
commit
dc9ce71e66
|
@ -2180,8 +2180,10 @@ int kvm_write_guest_offset_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
|||
|
||||
BUG_ON(len + offset > ghc->len);
|
||||
|
||||
if (slots->generation != ghc->generation)
|
||||
__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len);
|
||||
if (slots->generation != ghc->generation) {
|
||||
if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (kvm_is_error_hva(ghc->hva))
|
||||
return -EFAULT;
|
||||
|
@ -2213,8 +2215,10 @@ int kvm_read_guest_cached(struct kvm *kvm, struct gfn_to_hva_cache *ghc,
|
|||
|
||||
BUG_ON(len > ghc->len);
|
||||
|
||||
if (slots->generation != ghc->generation)
|
||||
__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len);
|
||||
if (slots->generation != ghc->generation) {
|
||||
if (__kvm_gfn_to_hva_cache_init(slots, ghc, ghc->gpa, ghc->len))
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if (kvm_is_error_hva(ghc->hva))
|
||||
return -EFAULT;
|
||||
|
|
Loading…
Reference in New Issue
Block a user