diff options
-rw-r--r-- | arch/ia64/kvm/kvm-ia64.c | 2 | ||||
-rw-r--r-- | arch/s390/kvm/kvm-s390.h | 2 | ||||
-rw-r--r-- | arch/x86/kvm/mmu.c | 7 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 2 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 4 | ||||
-rw-r--r-- | arch/x86/kvm/x86.h | 7 | ||||
-rw-r--r-- | include/linux/kvm_host.h | 7 | ||||
-rw-r--r-- | virt/kvm/iommu.c | 4 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 13 |
9 files changed, 33 insertions, 15 deletions
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c index d7bac1f75af0..d5f4e9161201 100644 --- a/arch/ia64/kvm/kvm-ia64.c +++ b/arch/ia64/kvm/kvm-ia64.c | |||
@@ -1381,7 +1381,7 @@ static void kvm_release_vm_pages(struct kvm *kvm) | |||
1381 | int i, j; | 1381 | int i, j; |
1382 | unsigned long base_gfn; | 1382 | unsigned long base_gfn; |
1383 | 1383 | ||
1384 | slots = rcu_dereference(kvm->memslots); | 1384 | slots = kvm_memslots(kvm); |
1385 | for (i = 0; i < slots->nmemslots; i++) { | 1385 | for (i = 0; i < slots->nmemslots; i++) { |
1386 | memslot = &slots->memslots[i]; | 1386 | memslot = &slots->memslots[i]; |
1387 | base_gfn = memslot->base_gfn; | 1387 | base_gfn = memslot->base_gfn; |
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h index 60f09ab3672c..cfa9d1777457 100644 --- a/arch/s390/kvm/kvm-s390.h +++ b/arch/s390/kvm/kvm-s390.h | |||
@@ -72,7 +72,7 @@ static inline void kvm_s390_vcpu_set_mem(struct kvm_vcpu *vcpu) | |||
72 | struct kvm_memslots *memslots; | 72 | struct kvm_memslots *memslots; |
73 | 73 | ||
74 | idx = srcu_read_lock(&vcpu->kvm->srcu); | 74 | idx = srcu_read_lock(&vcpu->kvm->srcu); |
75 | memslots = rcu_dereference(vcpu->kvm->memslots); | 75 | memslots = kvm_memslots(vcpu->kvm); |
76 | 76 | ||
77 | mem = &memslots->memslots[0]; | 77 | mem = &memslots->memslots[0]; |
78 | 78 | ||
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 7a17db1cdcd6..0682a393ad90 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -787,7 +787,7 @@ static int kvm_handle_hva(struct kvm *kvm, unsigned long hva, | |||
787 | int retval = 0; | 787 | int retval = 0; |
788 | struct kvm_memslots *slots; | 788 | struct kvm_memslots *slots; |
789 | 789 | ||
790 | slots = rcu_dereference(kvm->memslots); | 790 | slots = kvm_memslots(kvm); |
791 | 791 | ||
792 | for (i = 0; i < slots->nmemslots; i++) { | 792 | for (i = 0; i < slots->nmemslots; i++) { |
793 | struct kvm_memory_slot *memslot = &slots->memslots[i]; | 793 | struct kvm_memory_slot *memslot = &slots->memslots[i]; |
@@ -3016,7 +3016,8 @@ unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm) | |||
3016 | unsigned int nr_pages = 0; | 3016 | unsigned int nr_pages = 0; |
3017 | struct kvm_memslots *slots; | 3017 | struct kvm_memslots *slots; |
3018 | 3018 | ||
3019 | slots = rcu_dereference(kvm->memslots); | 3019 | slots = kvm_memslots(kvm); |
3020 | |||
3020 | for (i = 0; i < slots->nmemslots; i++) | 3021 | for (i = 0; i < slots->nmemslots; i++) |
3021 | nr_pages += slots->memslots[i].npages; | 3022 | nr_pages += slots->memslots[i].npages; |
3022 | 3023 | ||
@@ -3292,7 +3293,7 @@ static int count_rmaps(struct kvm_vcpu *vcpu) | |||
3292 | int i, j, k, idx; | 3293 | int i, j, k, idx; |
3293 | 3294 | ||
3294 | idx = srcu_read_lock(&kvm->srcu); | 3295 | idx = srcu_read_lock(&kvm->srcu); |
3295 | slots = rcu_dereference(kvm->memslots); | 3296 | slots = kvm_memslots(kvm); |
3296 | for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { | 3297 | for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { |
3297 | struct kvm_memory_slot *m = &slots->memslots[i]; | 3298 | struct kvm_memory_slot *m = &slots->memslots[i]; |
3298 | struct kvm_rmap_desc *d; | 3299 | struct kvm_rmap_desc *d; |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 0b896ac7e4bb..d0a10b5612e9 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -1558,7 +1558,7 @@ static gva_t rmode_tss_base(struct kvm *kvm) | |||
1558 | struct kvm_memslots *slots; | 1558 | struct kvm_memslots *slots; |
1559 | gfn_t base_gfn; | 1559 | gfn_t base_gfn; |
1560 | 1560 | ||
1561 | slots = rcu_dereference(kvm->memslots); | 1561 | slots = kvm_memslots(kvm); |
1562 | base_gfn = kvm->memslots->memslots[0].base_gfn + | 1562 | base_gfn = kvm->memslots->memslots[0].base_gfn + |
1563 | kvm->memslots->memslots[0].npages - 3; | 1563 | kvm->memslots->memslots[0].npages - 3; |
1564 | return base_gfn << PAGE_SHIFT; | 1564 | return base_gfn << PAGE_SHIFT; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 58a96e6a234c..638248c96999 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -2497,7 +2497,7 @@ gfn_t unalias_gfn_instantiation(struct kvm *kvm, gfn_t gfn) | |||
2497 | struct kvm_mem_alias *alias; | 2497 | struct kvm_mem_alias *alias; |
2498 | struct kvm_mem_aliases *aliases; | 2498 | struct kvm_mem_aliases *aliases; |
2499 | 2499 | ||
2500 | aliases = rcu_dereference(kvm->arch.aliases); | 2500 | aliases = kvm_aliases(kvm); |
2501 | 2501 | ||
2502 | for (i = 0; i < aliases->naliases; ++i) { | 2502 | for (i = 0; i < aliases->naliases; ++i) { |
2503 | alias = &aliases->aliases[i]; | 2503 | alias = &aliases->aliases[i]; |
@@ -2516,7 +2516,7 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) | |||
2516 | struct kvm_mem_alias *alias; | 2516 | struct kvm_mem_alias *alias; |
2517 | struct kvm_mem_aliases *aliases; | 2517 | struct kvm_mem_aliases *aliases; |
2518 | 2518 | ||
2519 | aliases = rcu_dereference(kvm->arch.aliases); | 2519 | aliases = kvm_aliases(kvm); |
2520 | 2520 | ||
2521 | for (i = 0; i < aliases->naliases; ++i) { | 2521 | for (i = 0; i < aliases->naliases; ++i) { |
2522 | alias = &aliases->aliases[i]; | 2522 | alias = &aliases->aliases[i]; |
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index b7a404722d2b..f4b54458285b 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h | |||
@@ -65,6 +65,13 @@ static inline int is_paging(struct kvm_vcpu *vcpu) | |||
65 | return kvm_read_cr0_bits(vcpu, X86_CR0_PG); | 65 | return kvm_read_cr0_bits(vcpu, X86_CR0_PG); |
66 | } | 66 | } |
67 | 67 | ||
68 | static inline struct kvm_mem_aliases *kvm_aliases(struct kvm *kvm) | ||
69 | { | ||
70 | return rcu_dereference_check(kvm->arch.aliases, | ||
71 | srcu_read_lock_held(&kvm->srcu) | ||
72 | || lockdep_is_held(&kvm->slots_lock)); | ||
73 | } | ||
74 | |||
68 | void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); | 75 | void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); |
69 | void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); | 76 | void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); |
70 | 77 | ||
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 55830638aeb1..1ed030bad59e 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h | |||
@@ -250,6 +250,13 @@ void kvm_exit(void); | |||
250 | void kvm_get_kvm(struct kvm *kvm); | 250 | void kvm_get_kvm(struct kvm *kvm); |
251 | void kvm_put_kvm(struct kvm *kvm); | 251 | void kvm_put_kvm(struct kvm *kvm); |
252 | 252 | ||
253 | static inline struct kvm_memslots *kvm_memslots(struct kvm *kvm) | ||
254 | { | ||
255 | return rcu_dereference_check(kvm->memslots, | ||
256 | srcu_read_lock_held(&kvm->srcu) | ||
257 | || lockdep_is_held(&kvm->slots_lock)); | ||
258 | } | ||
259 | |||
253 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) | 260 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) |
254 | #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB) | 261 | #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB) |
255 | static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; } | 262 | static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; } |
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index 80fd3ad3b2de..37ca71ebdba8 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c | |||
@@ -78,7 +78,7 @@ static int kvm_iommu_map_memslots(struct kvm *kvm) | |||
78 | int i, r = 0; | 78 | int i, r = 0; |
79 | struct kvm_memslots *slots; | 79 | struct kvm_memslots *slots; |
80 | 80 | ||
81 | slots = rcu_dereference(kvm->memslots); | 81 | slots = kvm_memslots(kvm); |
82 | 82 | ||
83 | for (i = 0; i < slots->nmemslots; i++) { | 83 | for (i = 0; i < slots->nmemslots; i++) { |
84 | r = kvm_iommu_map_pages(kvm, &slots->memslots[i]); | 84 | r = kvm_iommu_map_pages(kvm, &slots->memslots[i]); |
@@ -217,7 +217,7 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm) | |||
217 | int i; | 217 | int i; |
218 | struct kvm_memslots *slots; | 218 | struct kvm_memslots *slots; |
219 | 219 | ||
220 | slots = rcu_dereference(kvm->memslots); | 220 | slots = kvm_memslots(kvm); |
221 | 221 | ||
222 | for (i = 0; i < slots->nmemslots; i++) { | 222 | for (i = 0; i < slots->nmemslots; i++) { |
223 | kvm_iommu_put_pages(kvm, slots->memslots[i].base_gfn, | 223 | kvm_iommu_put_pages(kvm, slots->memslots[i].base_gfn, |
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d6351a34b297..4901ec5061ba 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -834,7 +834,7 @@ EXPORT_SYMBOL_GPL(kvm_is_error_hva); | |||
834 | struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn) | 834 | struct kvm_memory_slot *gfn_to_memslot_unaliased(struct kvm *kvm, gfn_t gfn) |
835 | { | 835 | { |
836 | int i; | 836 | int i; |
837 | struct kvm_memslots *slots = rcu_dereference(kvm->memslots); | 837 | struct kvm_memslots *slots = kvm_memslots(kvm); |
838 | 838 | ||
839 | for (i = 0; i < slots->nmemslots; ++i) { | 839 | for (i = 0; i < slots->nmemslots; ++i) { |
840 | struct kvm_memory_slot *memslot = &slots->memslots[i]; | 840 | struct kvm_memory_slot *memslot = &slots->memslots[i]; |
@@ -856,7 +856,7 @@ struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn) | |||
856 | int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) | 856 | int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) |
857 | { | 857 | { |
858 | int i; | 858 | int i; |
859 | struct kvm_memslots *slots = rcu_dereference(kvm->memslots); | 859 | struct kvm_memslots *slots = kvm_memslots(kvm); |
860 | 860 | ||
861 | gfn = unalias_gfn_instantiation(kvm, gfn); | 861 | gfn = unalias_gfn_instantiation(kvm, gfn); |
862 | for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { | 862 | for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { |
@@ -900,7 +900,7 @@ out: | |||
900 | int memslot_id(struct kvm *kvm, gfn_t gfn) | 900 | int memslot_id(struct kvm *kvm, gfn_t gfn) |
901 | { | 901 | { |
902 | int i; | 902 | int i; |
903 | struct kvm_memslots *slots = rcu_dereference(kvm->memslots); | 903 | struct kvm_memslots *slots = kvm_memslots(kvm); |
904 | struct kvm_memory_slot *memslot = NULL; | 904 | struct kvm_memory_slot *memslot = NULL; |
905 | 905 | ||
906 | gfn = unalias_gfn(kvm, gfn); | 906 | gfn = unalias_gfn(kvm, gfn); |
@@ -1994,7 +1994,9 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, | |||
1994 | int len, const void *val) | 1994 | int len, const void *val) |
1995 | { | 1995 | { |
1996 | int i; | 1996 | int i; |
1997 | struct kvm_io_bus *bus = rcu_dereference(kvm->buses[bus_idx]); | 1997 | struct kvm_io_bus *bus; |
1998 | |||
1999 | bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); | ||
1998 | for (i = 0; i < bus->dev_count; i++) | 2000 | for (i = 0; i < bus->dev_count; i++) |
1999 | if (!kvm_iodevice_write(bus->devs[i], addr, len, val)) | 2001 | if (!kvm_iodevice_write(bus->devs[i], addr, len, val)) |
2000 | return 0; | 2002 | return 0; |
@@ -2006,8 +2008,9 @@ int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, | |||
2006 | int len, void *val) | 2008 | int len, void *val) |
2007 | { | 2009 | { |
2008 | int i; | 2010 | int i; |
2009 | struct kvm_io_bus *bus = rcu_dereference(kvm->buses[bus_idx]); | 2011 | struct kvm_io_bus *bus; |
2010 | 2012 | ||
2013 | bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); | ||
2011 | for (i = 0; i < bus->dev_count; i++) | 2014 | for (i = 0; i < bus->dev_count; i++) |
2012 | if (!kvm_iodevice_read(bus->devs[i], addr, len, val)) | 2015 | if (!kvm_iodevice_read(bus->devs[i], addr, len, val)) |
2013 | return 0; | 2016 | return 0; |