kvm-s390.c (6a656832aa75784d02dccd8d37fc5c0896064c2e) | kvm-s390.c (a54d806688fe1e482350ce759a8a0fc9ebf814b0) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * hosting IBM Z kernel virtual machines (s390x) 4 * 5 * Copyright IBM Corp. 2008, 2020 6 * 7 * Author(s): Carsten Otte <cotte@de.ibm.com> 8 * Christian Borntraeger <borntraeger@de.ibm.com> --- 1023 unchanged lines hidden (view full) --- 1032 * Must be called with kvm->srcu held to avoid races on memslots, and with 1033 * kvm->slots_lock to avoid races with ourselves and kvm_s390_vm_stop_migration. 1034 */ 1035static int kvm_s390_vm_start_migration(struct kvm *kvm) 1036{ 1037 struct kvm_memory_slot *ms; 1038 struct kvm_memslots *slots; 1039 unsigned long ram_pages = 0; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * hosting IBM Z kernel virtual machines (s390x) 4 * 5 * Copyright IBM Corp. 2008, 2020 6 * 7 * Author(s): Carsten Otte <cotte@de.ibm.com> 8 * Christian Borntraeger <borntraeger@de.ibm.com> --- 1023 unchanged lines hidden (view full) --- 1032 * Must be called with kvm->srcu held to avoid races on memslots, and with 1033 * kvm->slots_lock to avoid races with ourselves and kvm_s390_vm_stop_migration. 1034 */ 1035static int kvm_s390_vm_start_migration(struct kvm *kvm) 1036{ 1037 struct kvm_memory_slot *ms; 1038 struct kvm_memslots *slots; 1039 unsigned long ram_pages = 0; |
1040 int slotnr; | 1040 int bkt; |
1041 1042 /* migration mode already enabled */ 1043 if (kvm->arch.migration_mode) 1044 return 0; 1045 slots = kvm_memslots(kvm); | 1041 1042 /* migration mode already enabled */ 1043 if (kvm->arch.migration_mode) 1044 return 0; 1045 slots = kvm_memslots(kvm); |
1046 if (!slots || !slots->used_slots) | 1046 if (!slots || kvm_memslots_empty(slots)) |
1047 return -EINVAL; 1048 1049 if (!kvm->arch.use_cmma) { 1050 kvm->arch.migration_mode = 1; 1051 return 0; 1052 } 1053 /* mark all the pages in active slots as dirty */ | 1047 return -EINVAL; 1048 1049 if (!kvm->arch.use_cmma) { 1050 kvm->arch.migration_mode = 1; 1051 return 0; 1052 } 1053 /* mark all the pages in active slots as dirty */ |
1054 for (slotnr = 0; slotnr < slots->used_slots; slotnr++) { 1055 ms = slots->memslots + slotnr; | 1054 kvm_for_each_memslot(ms, bkt, slots) { |
1056 if (!ms->dirty_bitmap) 1057 return -EINVAL; 1058 /* 1059 * The second half of the bitmap is only used on x86, 1060 * and would be wasted otherwise, so we put it to good 1061 * use here to keep track of the state of the storage 1062 * attributes. 1063 */ --- 907 unchanged lines hidden (view full) --- 1971{ 1972 return ____gfn_to_memslot(slots, gfn, true); 1973} 1974 1975static unsigned long kvm_s390_next_dirty_cmma(struct kvm_memslots *slots, 1976 unsigned long cur_gfn) 1977{ 1978 struct kvm_memory_slot *ms = gfn_to_memslot_approx(slots, cur_gfn); | 1055 if (!ms->dirty_bitmap) 1056 return -EINVAL; 1057 /* 1058 * The second half of the bitmap is only used on x86, 1059 * and would be wasted otherwise, so we put it to good 1060 * use here to keep track of the state of the storage 1061 * attributes. 1062 */ --- 907 unchanged lines hidden (view full) --- 1970{ 1971 return ____gfn_to_memslot(slots, gfn, true); 1972} 1973 1974static unsigned long kvm_s390_next_dirty_cmma(struct kvm_memslots *slots, 1975 unsigned long cur_gfn) 1976{ 1977 struct kvm_memory_slot *ms = gfn_to_memslot_approx(slots, cur_gfn); |
1979 int slotidx = ms - slots->memslots; | |
1980 unsigned long ofs = cur_gfn - ms->base_gfn; | 1978 unsigned long ofs = cur_gfn - ms->base_gfn; |
1979 struct rb_node *mnode = &ms->gfn_node[slots->node_idx]; |
|
1981 1982 if (ms->base_gfn + ms->npages <= cur_gfn) { | 1980 1981 if (ms->base_gfn + ms->npages <= cur_gfn) { |
1983 slotidx--; | 1982 mnode = rb_next(mnode); |
1984 /* If we are above the highest slot, wrap around */ | 1983 /* If we are above the highest slot, wrap around */ |
1985 if (slotidx < 0) 1986 slotidx = slots->used_slots - 1; | 1984 if (!mnode) 1985 mnode = rb_first(&slots->gfn_tree); |
1987 | 1986 |
1988 ms = slots->memslots + slotidx; | 1987 ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]); |
1989 ofs = 0; 1990 } 1991 ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, ofs); | 1988 ofs = 0; 1989 } 1990 ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, ofs); |
1992 while ((slotidx > 0) && (ofs >= ms->npages)) { 1993 slotidx--; 1994 ms = slots->memslots + slotidx; | 1991 while (ofs >= ms->npages && (mnode = rb_next(mnode))) { 1992 ms = container_of(mnode, struct kvm_memory_slot, gfn_node[slots->node_idx]); |
1995 ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, 0); 1996 } 1997 return ms->base_gfn + ofs; 1998} 1999 2000static int kvm_s390_get_cmma(struct kvm *kvm, struct kvm_s390_cmma_log *args, 2001 u8 *res, unsigned long bufsize) 2002{ 2003 unsigned long mem_end, cur_gfn, next_gfn, hva, pgstev; 2004 struct kvm_memslots *slots = kvm_memslots(kvm); 2005 struct kvm_memory_slot *ms; 2006 | 1993 ofs = find_next_bit(kvm_second_dirty_bitmap(ms), ms->npages, 0); 1994 } 1995 return ms->base_gfn + ofs; 1996} 1997 1998static int kvm_s390_get_cmma(struct kvm *kvm, struct kvm_s390_cmma_log *args, 1999 u8 *res, unsigned long bufsize) 2000{ 2001 unsigned long mem_end, cur_gfn, next_gfn, hva, pgstev; 2002 struct kvm_memslots *slots = kvm_memslots(kvm); 2003 struct kvm_memory_slot *ms; 2004 |
2007 if (unlikely(!slots->used_slots)) | 2005 if (unlikely(kvm_memslots_empty(slots))) |
2008 return 0; 2009 2010 cur_gfn = kvm_s390_next_dirty_cmma(slots, args->start_gfn); 2011 ms = gfn_to_memslot(kvm, cur_gfn); 2012 args->count = 0; 2013 args->start_gfn = cur_gfn; 2014 if (!ms) 2015 return 0; --- 3078 unchanged lines hidden --- | 2006 return 0; 2007 2008 cur_gfn = kvm_s390_next_dirty_cmma(slots, args->start_gfn); 2009 ms = gfn_to_memslot(kvm, cur_gfn); 2010 args->count = 0; 2011 args->start_gfn = cur_gfn; 2012 if (!ms) 2013 return 0; --- 3078 unchanged lines hidden --- |