aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorChristoffer Dall <christoffer.dall@linaro.org>2014-08-19 06:15:00 -0400
committerChristoffer Dall <christoffer.dall@linaro.org>2014-08-27 16:46:08 -0400
commit64d831269ccbca1fc6d739a0f3c8aa24afb43a5e (patch)
treef31585ef953ddd09ab3327b79a9b0b406a089f8e /virt
parent7b46268d29543e313e731606d845e65c17f232e4 (diff)
KVM: Introduce gfn_to_hva_memslot_prot
To support read-only memory regions on arm and arm64, we have a need to resolve a gfn to an hva given a pointer to a memslot to avoid looping through the memslots twice and to reuse the hva error checking of gfn_to_hva_prot(), add a new gfn_to_hva_memslot_prot() function and refactor gfn_to_hva_prot() to use this function. Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/kvm_main.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 5a0817ee996e..76c92a7249c4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1076,9 +1076,9 @@ EXPORT_SYMBOL_GPL(gfn_to_hva);
1076 * If writable is set to false, the hva returned by this function is only 1076 * If writable is set to false, the hva returned by this function is only
1077 * allowed to be read. 1077 * allowed to be read.
1078 */ 1078 */
1079unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable) 1079unsigned long gfn_to_hva_memslot_prot(struct kvm_memory_slot *slot,
1080 gfn_t gfn, bool *writable)
1080{ 1081{
1081 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
1082 unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false); 1082 unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false);
1083 1083
1084 if (!kvm_is_error_hva(hva) && writable) 1084 if (!kvm_is_error_hva(hva) && writable)
@@ -1087,6 +1087,13 @@ unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
1087 return hva; 1087 return hva;
1088} 1088}
1089 1089
1090unsigned long gfn_to_hva_prot(struct kvm *kvm, gfn_t gfn, bool *writable)
1091{
1092 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
1093
1094 return gfn_to_hva_memslot_prot(slot, gfn, writable);
1095}
1096
1090static int kvm_read_hva(void *data, void __user *hva, int len) 1097static int kvm_read_hva(void *data, void __user *hva, int len)
1091{ 1098{
1092 return __copy_from_user(data, hva, len); 1099 return __copy_from_user(data, hva, len);