From: Gleb Natapov <gleb@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: mtosatti@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [PATCH] kvm: Detect number of available memory slots from the host kernel
Date: Sun, 9 Dec 2012 16:20:43 +0200 [thread overview]
Message-ID: <20121209142043.GB29003@redhat.com> (raw)
In-Reply-To: <20121207194503.20524.17054.stgit@bling.home>
On Fri, Dec 07, 2012 at 12:46:10PM -0700, Alex Williamson wrote:
> The kernel already exposes an interface for this, x86 returns a proper
> value and for the rest we can default to the defacto standard of 32.
> The primary motivation for this is to support more PCI assigned
> devices, both through pci-assign and vfio-pci.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> kvm-all.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index 8e9a8d8..34d97f3 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -71,7 +71,8 @@ typedef struct kvm_dirty_log KVMDirtyLog;
>
> struct KVMState
> {
> - KVMSlot slots[32];
> + KVMSlot *slots;
> + int num_slots;
> int fd;
> int vmfd;
> int coalesced_mmio;
> @@ -120,7 +121,7 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> if (s->slots[i].memory_size == 0) {
> return &s->slots[i];
> }
> @@ -136,7 +137,7 @@ static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (start_addr == mem->start_addr &&
> @@ -158,7 +159,7 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
> KVMSlot *found = NULL;
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (mem->memory_size == 0 ||
> @@ -180,7 +181,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (ram >= mem->ram && ram < mem->ram + mem->memory_size) {
> @@ -340,7 +341,7 @@ static int kvm_set_migration_log(int enable)
>
> s->migration_log = enable;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> mem = &s->slots[i];
>
> if (!mem->memory_size) {
> @@ -1268,9 +1269,6 @@ int kvm_init(void)
> #ifdef KVM_CAP_SET_GUEST_DEBUG
> QTAILQ_INIT(&s->kvm_sw_breakpoints);
> #endif
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> - s->slots[i].slot = i;
> - }
> s->vmfd = -1;
> s->fd = qemu_open("/dev/kvm", O_RDWR);
> if (s->fd == -1) {
> @@ -1324,6 +1322,16 @@ int kvm_init(void)
> goto err;
> }
>
> + s->num_slots = kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS);
> + if (s->num_slots <= 0) {
kvm_check_extension() never returns negative value, so !s->num_slots
check is enough. Other than that minor nit looks OK.
> + s->num_slots = 32;
> + }
> + s->slots = g_malloc0(s->num_slots * sizeof(*s->slots));
> +
> + for (i = 0; i < s->num_slots; i++) {
> + s->slots[i].slot = i;
> + }
> +
> s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO);
>
> s->broken_set_mem_region = 1;
> @@ -1393,6 +1401,7 @@ err:
> if (s->fd != -1) {
> close(s->fd);
> }
> + g_free(s->slots);
> g_free(s);
>
> return ret;
--
Gleb.
WARNING: multiple messages have this Message-ID (diff)
From: Gleb Natapov <gleb@redhat.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: mtosatti@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH] kvm: Detect number of available memory slots from the host kernel
Date: Sun, 9 Dec 2012 16:20:43 +0200 [thread overview]
Message-ID: <20121209142043.GB29003@redhat.com> (raw)
In-Reply-To: <20121207194503.20524.17054.stgit@bling.home>
On Fri, Dec 07, 2012 at 12:46:10PM -0700, Alex Williamson wrote:
> The kernel already exposes an interface for this, x86 returns a proper
> value and for the rest we can default to the defacto standard of 32.
> The primary motivation for this is to support more PCI assigned
> devices, both through pci-assign and vfio-pci.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> kvm-all.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index 8e9a8d8..34d97f3 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -71,7 +71,8 @@ typedef struct kvm_dirty_log KVMDirtyLog;
>
> struct KVMState
> {
> - KVMSlot slots[32];
> + KVMSlot *slots;
> + int num_slots;
> int fd;
> int vmfd;
> int coalesced_mmio;
> @@ -120,7 +121,7 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> if (s->slots[i].memory_size == 0) {
> return &s->slots[i];
> }
> @@ -136,7 +137,7 @@ static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (start_addr == mem->start_addr &&
> @@ -158,7 +159,7 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
> KVMSlot *found = NULL;
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (mem->memory_size == 0 ||
> @@ -180,7 +181,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> KVMSlot *mem = &s->slots[i];
>
> if (ram >= mem->ram && ram < mem->ram + mem->memory_size) {
> @@ -340,7 +341,7 @@ static int kvm_set_migration_log(int enable)
>
> s->migration_log = enable;
>
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> + for (i = 0; i < s->num_slots; i++) {
> mem = &s->slots[i];
>
> if (!mem->memory_size) {
> @@ -1268,9 +1269,6 @@ int kvm_init(void)
> #ifdef KVM_CAP_SET_GUEST_DEBUG
> QTAILQ_INIT(&s->kvm_sw_breakpoints);
> #endif
> - for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
> - s->slots[i].slot = i;
> - }
> s->vmfd = -1;
> s->fd = qemu_open("/dev/kvm", O_RDWR);
> if (s->fd == -1) {
> @@ -1324,6 +1322,16 @@ int kvm_init(void)
> goto err;
> }
>
> + s->num_slots = kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS);
> + if (s->num_slots <= 0) {
kvm_check_extension() never returns negative value, so !s->num_slots
check is enough. Other than that minor nit looks OK.
> + s->num_slots = 32;
> + }
> + s->slots = g_malloc0(s->num_slots * sizeof(*s->slots));
> +
> + for (i = 0; i < s->num_slots; i++) {
> + s->slots[i].slot = i;
> + }
> +
> s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO);
>
> s->broken_set_mem_region = 1;
> @@ -1393,6 +1401,7 @@ err:
> if (s->fd != -1) {
> close(s->fd);
> }
> + g_free(s->slots);
> g_free(s);
>
> return ret;
--
Gleb.
next prev parent reply other threads:[~2012-12-09 14:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-07 19:46 [PATCH] kvm: Detect number of available memory slots from the host kernel Alex Williamson
2012-12-07 19:46 ` [Qemu-devel] " Alex Williamson
2012-12-09 14:20 ` Gleb Natapov [this message]
2012-12-09 14:20 ` Gleb Natapov
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=20121209142043.GB29003@redhat.com \
--to=gleb@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.