Skip to content

Commit 66119f8

Browse files
sean-jcClaudio Imbrenda
authored andcommitted
KVM: Do not restrict the size of KVM-internal memory regions
Exempt KVM-internal memslots from the KVM_MEM_MAX_NR_PAGES restriction, as the limit on the number of pages exists purely to play nice with dirty bitmap operations, which use 32-bit values to index the bitmaps, and dirty logging isn't supported for KVM-internal memslots. Link: https://lore.kernel.org/all/20240802205003.353672-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Reviewed-by: Christoph Schlameuss <schlameuss@linux.ibm.com> Reviewed-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20250123144627.312456-2-imbrenda@linux.ibm.com Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com> Message-ID: <20250123144627.312456-2-imbrenda@linux.ibm.com>
1 parent 4514eda commit 66119f8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

virt/kvm/kvm_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,15 @@ static int kvm_set_memory_region(struct kvm *kvm,
19711971
return -EINVAL;
19721972
if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
19731973
return -EINVAL;
1974-
if ((mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)
1974+
1975+
/*
1976+
* The size of userspace-defined memory regions is restricted in order
1977+
* to play nice with dirty bitmap operations, which are indexed with an
1978+
* "unsigned int". KVM's internal memory regions don't support dirty
1979+
* logging, and so are exempt.
1980+
*/
1981+
if (id < KVM_USER_MEM_SLOTS &&
1982+
(mem->memory_size >> PAGE_SHIFT) > KVM_MEM_MAX_NR_PAGES)
19751983
return -EINVAL;
19761984

19771985
slots = __kvm_memslots(kvm, as_id);

0 commit comments

Comments
 (0)