Re: [PATCH RFC 2/5] KVM: use a rapper function to calculate the sizes of dirty bitmaps

Takuya Yoshikawa
2010-04-12T01:50:49Z

(2010/04/12 2:12), Avi Kivity wrote:
> On 04/09/2010 12:32 PM, Takuya Yoshikawa wrote:
>> We will use this later in other parts.
>>
>
> s/rapper/wrapper/...

Oh, my poor English, sorry.

>
>>
>> +static inline int kvm_dirty_bitmap_bytes(struct kvm_memory_slot
>> *memslot)
>> +{
>> + return ALIGN(memslot->npages, BITS_PER_LONG) / 8;
>> +}
>> +
>
> 'int' may overflow.

Then, we have to fix a bit more.

In mark_page_dirty(), we pass unsigned long rel_gfn to __set_bit(),
but __set_bit() takes the offset as int.

We have to shift the base before using __set_bit().

I'll send this as a separate bug fix.

>
>> struct kvm_kernel_irq_routing_entry {
>> u32 gsi;
>> u32 type;
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index 9379533..5ab581e 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -645,7 +645,7 @@ skip_lpage:
>>
>> /* Allocate page dirty bitmap if needed */
>> if ((new.flags& KVM_MEM_LOG_DIRTY_PAGES)&& !new.dirty_bitmap) {
>> - unsigned dirty_bytes = ALIGN(npages, BITS_PER_LONG) / 8;
>> + int dirty_bytes = kvm_dirty_bitmap_bytes(&new);
>
> Ah, an existing bug.
>