All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: "jack.chen" <zhunxun@gmail.com>
Cc: KVM maillist <kvm@vger.kernel.org>
Subject: Re: kvm memslot questions
Date: Tue, 13 Dec 2016 15:32:40 +0100	[thread overview]
Message-ID: <20161213143240.GA9488@potion> (raw)
In-Reply-To: <CADUDsAqcx3=wFDp7rvx4uoQCwQZbxnF+KmxEF_8D=PpggY7WJg@mail.gmail.com>

2016-12-13 09:23+0800, jack.chen:
> thank you very very much!
> 1、
> I want to alloc VM memory in KVM ,not installing anything in VM,and  I
> want to write data to that memory then let VM use it! So in order to
> know which memory is not used by VM,I need check the bitmap,but at
> first,I found the dirty_bitmap of slot I want to use is NULL,so I have
> to set KVM_MEM_LOG_DIRTY_PAGES flags in KVM matually.

The bitmap doesn't say if the memory is unused and userspace can zero
the bitmap at any time, so KVM cannot depend on it for this purpose.
VM uses everything that is configured with KVM_SET_USER_MEMORY_REGION.

A simple way to get unused memory for KVM<->guest communication is to
let the guest reserve some memory for KVM -- see MSR_KVM_STEAL_TIME or
MSR_KVM_SYSTEM_TIME_NEW for an example.
Guest will provide an address and KVM will fill the address with data.

> 2、
> And I have another question,the function in KVM to set dirty_bitmap call
> static inline void set_bit_le(int nr, void *addr)
> {
> set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
> }
> 
> when test the bit,I do not know if I should use BITOP_LE_SWIZZLE,It
> seems that that right without SWIZZLE.

BITOP_LE_SWIZZLE is 0 on x86 so it doesn't matter -- I assume your code
isn't going to be useable on different endianess.
(And cannot use the bitmap for what you are doing anyway. ;])


> 2016-12-12 23:17 GMT+08:00 Radim Krčmář <rkrcmar@redhat.com>:
>> 2016-12-12 17:18+0800, jack.chen:
>>> hello,now I want to know which GFN of VM  is available,so I set
>>> kvm_userspace_mem->flags |= 0x1; in kvm_vm_ioctl function ,so KVM can
>>> create dirty_bitmap for slots
>>
>> The caller of KVM_SET_USER_MEMORY_REGION knows which GFNs are
>> "available", because it configures that into
>> kvm_userspace_mem->guest_phys_addr and kvm_userspace_mem->size.
>>
>> KVM knows which GFNs are "available", because it remembers all memory
>> regions that were configured.
>>
>>> case KVM_SET_USER_MEMORY_REGION: {
>>> struct kvm_userspace_memory_region kvm_userspace_mem;
>>>
>>> ……
>>> kvm_userspace_mem->flags |= 0x1;
>>
>> Why do you want to use the dirty page bitmap in KVM?
>>
>>> r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_userspace_mem);
>>> break;
>>>
>>> and I have 2 questions:
>>> 1.
>>> if corresponding bit is setted,the GFN is used by VM,other than it is
>>> available!right?
>>
>> The GFN is always available.
>> If the corresponding bit in dirty log is set, then the GFN was modified
>> since userspace did the last KVM_GET_DIRTY_LOG ioctl.
>>
>>> 2、
>>> how to check wheather the bit is 1 or not,the test_bit function
>>> returns -1 to me,I do not know if I use wrong function!
>>> thanks in advance!!!
>>
>> test_bit() from arch/x86/include/asm/bitops.h returns bool so there is
>> something wrong with your test_bit().
>>
>> In any case, see kvm_vm_ioctl_get_dirty_log() for what is needed to
>> access the dirty log.

  reply	other threads:[~2016-12-13 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-12  9:18 kvm memslot questions jack.chen
2016-12-12 15:17 ` Radim Krčmář
2016-12-13  1:23   ` jack.chen
2016-12-13 14:32     ` Radim Krčmář [this message]
2016-12-14  2:50       ` jack.chen
2016-12-14 14:07         ` Radim Krčmář
     [not found] <rxwwlxuupev1ml4hff0l4cwy.1481725635921@email.android.com>
2016-12-14 18:42 ` Radim Krčmář
2016-12-15  1:03   ` jack.chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161213143240.GA9488@potion \
    --to=rkrcmar@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=zhunxun@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.