* [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes
@ 2011-05-11 4:09 Sasha Levin
2011-05-11 4:09 ` [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound Sasha Levin
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Sasha Levin @ 2011-05-11 4:09 UTC (permalink / raw)
To: penberg; +Cc: mingo, asias.hejun, prasadjoshi124, avi, gorcunov, kvm,
Sasha Levin
Add a memory gap between 0xe0000000 and 0x100000000
when using more than 0xe0000000 bytes for guest RAM.
This space is used by several things, PCI configuration
space for example.
This patch updates the e820 table, slot allocations
used for KVM_SET_USER_MEMORY_REGION, and the address
translation.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/bios.c | 27 +++++++++++++++++++++------
tools/kvm/include/kvm/e820.h | 2 +-
tools/kvm/include/kvm/kvm.h | 9 ++++++++-
tools/kvm/kvm.c | 22 ++++++++++++++++------
4 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/tools/kvm/bios.c b/tools/kvm/bios.c
index 2199c0c..cd417fa 100644
--- a/tools/kvm/bios.c
+++ b/tools/kvm/bios.c
@@ -61,7 +61,7 @@ static void e820_setup(struct kvm *kvm)
size = guest_flat_to_host(kvm, E820_MAP_SIZE);
mem_map = guest_flat_to_host(kvm, E820_MAP_START);
- *size = E820_MEM_AREAS;
+
mem_map[i++] = (struct e820_entry) {
.addr = REAL_MODE_IVT_BEGIN,
@@ -78,13 +78,28 @@ static void e820_setup(struct kvm *kvm)
.size = MB_BIOS_END - MB_BIOS_BEGIN,
.type = E820_MEM_RESERVED,
};
- mem_map[i++] = (struct e820_entry) {
- .addr = BZ_KERNEL_START,
- .size = kvm->ram_size - BZ_KERNEL_START,
- .type = E820_MEM_USABLE,
- };
+ if (kvm->ram_size < 0xe0000000) {
+ mem_map[i++] = (struct e820_entry) {
+ .addr = BZ_KERNEL_START,
+ .size = kvm->ram_size - BZ_KERNEL_START,
+ .type = E820_MEM_USABLE,
+ };
+ } else {
+ mem_map[i++] = (struct e820_entry) {
+ .addr = BZ_KERNEL_START,
+ .size = 0xe0000000 - BZ_KERNEL_START,
+ .type = E820_MEM_USABLE,
+ };
+ mem_map[i++] = (struct e820_entry) {
+ .addr = 0x100000000ULL,
+ .size = kvm->ram_size - 0xe0000000 - BZ_KERNEL_START,
+ .type = E820_MEM_USABLE,
+ };
+ }
BUILD_BUG_ON(i > E820_MEM_AREAS);
+
+ *size = i;
}
/**
diff --git a/tools/kvm/include/kvm/e820.h b/tools/kvm/include/kvm/e820.h
index 252ae1f..e0f5f2a 100644
--- a/tools/kvm/include/kvm/e820.h
+++ b/tools/kvm/include/kvm/e820.h
@@ -8,7 +8,7 @@
#define E820_MEM_USABLE 1
#define E820_MEM_RESERVED 2
-#define E820_MEM_AREAS 4
+#define E820_MEM_AREAS 5
struct e820_entry {
u64 addr; /* start of memory segment */
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 3dab78d..e9c16ea 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -60,7 +60,14 @@ static inline u32 segment_to_flat(u16 selector, u16 offset)
static inline void *guest_flat_to_host(struct kvm *self, unsigned long offset)
{
- return self->ram_start + offset;
+ /*
+ * We have a gap between 0xe0000000 and 0x100000000.
+ * Consider it when translating an address above 0x100000000.
+ */
+ if (offset < 0xe0000000)
+ return self->ram_start + offset;
+ else
+ return self->ram_start + 0xe0000000 + (offset - 0x100000000);
}
static inline void *guest_real_to_host(struct kvm *self, u16 selector, u16 offset)
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 65793f2..976b099 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -153,23 +153,33 @@ static bool kvm__cpu_supports_vm(void)
return regs.ecx & (1 << feature);
}
-void kvm__init_ram(struct kvm *self)
+static void kvm_register_mem_slot(struct kvm *kvm, u32 slot, u64 guest_phys, u64 size, u64 userspace_addr)
{
struct kvm_userspace_memory_region mem;
int ret;
mem = (struct kvm_userspace_memory_region) {
- .slot = 0,
- .guest_phys_addr = 0x0UL,
- .memory_size = self->ram_size,
- .userspace_addr = (unsigned long) self->ram_start,
+ .slot = slot,
+ .guest_phys_addr = guest_phys,
+ .memory_size = size,
+ .userspace_addr = userspace_addr,
};
- ret = ioctl(self->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
+ ret = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &mem);
if (ret < 0)
die_perror("KVM_SET_USER_MEMORY_REGION ioctl");
}
+void kvm__init_ram(struct kvm *self)
+{
+ if (self->ram_size < 0xe0000000) {
+ kvm_register_mem_slot(self, 0, 0, self->ram_size, (u64)self->ram_start);
+ } else {
+ kvm_register_mem_slot(self, 0, 0, 0xe0000000, (u64)self->ram_start);
+ kvm_register_mem_slot(self, 1, 0x100000000ULL, self->ram_size - 0xe0000000, (u64)self->ram_start + 0xe0000000);
+ }
+}
+
int kvm__max_cpus(struct kvm *self)
{
int ret;
--
1.7.5.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound
2011-05-11 4:09 [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Sasha Levin
@ 2011-05-11 4:09 ` Sasha Levin
2011-05-11 11:15 ` Ingo Molnar
2011-05-11 4:09 ` [PATCH 3/3] kvm tools: Use definitions from kernel headers Sasha Levin
2011-05-11 7:15 ` [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Ingo Molnar
2 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2011-05-11 4:09 UTC (permalink / raw)
To: penberg; +Cc: mingo, asias.hejun, prasadjoshi124, avi, gorcunov, kvm,
Sasha Levin
queue->pfn may be used to point at addresses larger
than 32 bit.
Prevent a wraparound when shifting it left.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/include/kvm/virtio.h | 5 +++++
tools/kvm/virtio/blk.c | 2 +-
tools/kvm/virtio/console.c | 2 +-
tools/kvm/virtio/net.c | 2 +-
tools/kvm/virtio/rng.c | 2 +-
5 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 7f92dea..beb234a 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -36,6 +36,11 @@ static inline bool virt_queue__available(struct virt_queue *vq)
return vq->vring.avail->idx != vq->last_avail_idx;
}
+static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
+{
+ return guest_flat_to_host(kvm, (unsigned long)pfn << 12);
+}
+
struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
u16 virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], u16 *out, u16 *in, struct kvm *kvm);
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 12c7029..9f1aa1d 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -197,7 +197,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, u16 port, void *data, int si
queue = &bdev->vqs[bdev->queue_selector];
queue->pfn = ioport__read32(data);
- p = guest_flat_to_host(self, queue->pfn << 12);
+ p = guest_pfn_to_host(self, queue->pfn);
vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, 4096);
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index f9031cb..87b816a 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -199,7 +199,7 @@ static bool virtio_console_pci_io_out(struct kvm *self, u16 port, void *data, in
queue = &cdev.vqs[cdev.queue_selector];
queue->pfn = ioport__read32(data);
- p = guest_flat_to_host(self, queue->pfn << 12);
+ p = guest_pfn_to_host(self, queue->pfn);
vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096);
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 8d430e3..3f3ee22 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -245,7 +245,7 @@ static bool virtio_net_pci_io_out(struct kvm *self, u16 port, void *data, int si
queue = &net_device.vqs[net_device.queue_selector];
queue->pfn = ioport__read32(data);
- p = guest_flat_to_host(self, queue->pfn << 12);
+ p = guest_pfn_to_host(self, queue->pfn);
vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, 4096);
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index f692dfd..1951d0d1c 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -129,7 +129,7 @@ static bool virtio_rng_pci_io_out(struct kvm *kvm, u16 port, void *data, int siz
queue = &rdev.vqs[rdev.queue_selector];
queue->pfn = ioport__read32(data);
- p = guest_flat_to_host(kvm, queue->pfn << 12);
+ p = guest_pfn_to_host(kvm, queue->pfn);
vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, 4096);
--
1.7.5.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] kvm tools: Use definitions from kernel headers
2011-05-11 4:09 [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Sasha Levin
2011-05-11 4:09 ` [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound Sasha Levin
@ 2011-05-11 4:09 ` Sasha Levin
2011-05-11 10:59 ` Ingo Molnar
2011-05-11 7:15 ` [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Ingo Molnar
2 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2011-05-11 4:09 UTC (permalink / raw)
To: penberg; +Cc: mingo, asias.hejun, prasadjoshi124, avi, gorcunov, kvm,
Sasha Levin
Instead of redefining virtio pci constants (or
not using them at all), use constants from kernel
header.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/include/kvm/virtio-pci-dev.h | 3 +
tools/kvm/include/kvm/virtio-pci.h | 74 --------------------------------
tools/kvm/include/kvm/virtio.h | 3 +-
tools/kvm/virtio/blk.c | 5 +-
tools/kvm/virtio/console.c | 9 ++--
tools/kvm/virtio/net.c | 9 ++--
tools/kvm/virtio/rng.c | 3 +-
7 files changed, 16 insertions(+), 90 deletions(-)
delete mode 100644 tools/kvm/include/kvm/virtio-pci.h
diff --git a/tools/kvm/include/kvm/virtio-pci-dev.h b/tools/kvm/include/kvm/virtio-pci-dev.h
index d2274d0..e946fe2 100644
--- a/tools/kvm/include/kvm/virtio-pci-dev.h
+++ b/tools/kvm/include/kvm/virtio-pci-dev.h
@@ -16,4 +16,7 @@
#define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE 0x0003
#define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004
+#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
+#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
+
#endif /* VIRTIO_PCI_DEV_H_ */
diff --git a/tools/kvm/include/kvm/virtio-pci.h b/tools/kvm/include/kvm/virtio-pci.h
deleted file mode 100644
index b507d1d..0000000
--- a/tools/kvm/include/kvm/virtio-pci.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Virtio PCI driver
- *
- * This module allows virtio devices to be used over a virtual PCI device.
- * This can be used with QEMU based VMMs like KVM or Xen.
- *
- * Copyright IBM Corp. 2007
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * This header is BSD licensed so anyone can use the definitions to implement
- * compatible drivers/servers.
- */
-
-#ifndef _LINUX_VIRTIO_PCI_H
-#define _LINUX_VIRTIO_PCI_H
-
-/* A 32-bit r/o bitmask of the features supported by the host */
-#define VIRTIO_PCI_HOST_FEATURES 0
-
-/* A 32-bit r/w bitmask of features activated by the guest */
-#define VIRTIO_PCI_GUEST_FEATURES 4
-
-/* A 32-bit r/w PFN for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_PFN 8
-
-/* A 16-bit r/o queue size for the currently selected queue */
-#define VIRTIO_PCI_QUEUE_NUM 12
-
-/* A 16-bit r/w queue selector */
-#define VIRTIO_PCI_QUEUE_SEL 14
-
-/* A 16-bit r/w queue notifier */
-#define VIRTIO_PCI_QUEUE_NOTIFY 16
-
-/* An 8-bit device status register */
-#define VIRTIO_PCI_STATUS 18
-
-/*
- * An 8-bit r/o interrupt status register.
- *
- * Reading the value will return the current contents of
- * the ISR and will also clear it. This is effectively
- * a read-and-acknowledge.
- */
-#define VIRTIO_PCI_ISR 19
-
-/*
- * MSI-X registers: only enabled if MSI-X is enabled.
- */
-
-/* A 16-bit vector for configuration changes */
-#define VIRTIO_MSI_CONFIG_VECTOR 20
-
-/* A 16-bit vector for selected queue notifications */
-#define VIRTIO_MSI_QUEUE_VECTOR 22
-
-/* Vector value used to disable MSI for queue */
-#define VIRTIO_MSI_NO_VECTOR 0xffff
-
-/*
- * Config space size.
- */
-#define VIRTIO_PCI_CONFIG_NOMSI 20
-#define VIRTIO_PCI_CONFIG_MSI 24
-
-/*
- * Virtio config space constants.
- */
-#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
-
-#endif /* _LINUX_VIRTIO_PCI_H */
diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index beb234a..1c83574 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -2,6 +2,7 @@
#define KVM__VIRTIO_H
#include <linux/virtio_ring.h>
+#include <linux/virtio_pci.h>
#include <linux/types.h>
#include <sys/uio.h>
@@ -38,7 +39,7 @@ static inline bool virt_queue__available(struct virt_queue *vq)
static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
{
- return guest_flat_to_host(kvm, (unsigned long)pfn << 12);
+ return guest_flat_to_host(kvm, (unsigned long)pfn << VIRTIO_PCI_QUEUE_ADDR_SHIFT);
}
struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, u32 head, u32 len);
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 9f1aa1d..8d480bf 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -1,6 +1,5 @@
#include "kvm/virtio-blk.h"
-#include "kvm/virtio-pci.h"
#include "kvm/virtio-pci-dev.h"
#include "kvm/irq.h"
#include "kvm/disk-image.h"
@@ -58,7 +57,7 @@ static bool virtio_blk_dev_in(struct blk_dev *bdev, void *data, unsigned long of
if (size != 1 || count != 1)
return false;
- ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]);
+ ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]);
return true;
}
@@ -199,7 +198,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, u16 port, void *data, int si
queue->pfn = ioport__read32(data);
p = guest_pfn_to_host(self, queue->pfn);
- vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, 4096);
+ vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
*job = (struct blk_dev_job) {
.vq = queue,
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index 87b816a..38f52f9 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -1,5 +1,4 @@
#include "kvm/virtio-console.h"
-#include "kvm/virtio-pci.h"
#include "kvm/virtio-pci-dev.h"
#include "kvm/disk-image.h"
#include "kvm/virtio.h"
@@ -104,10 +103,10 @@ static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long o
if (size != 1 || count != 1)
return false;
- if ((offset - VIRTIO_PCI_CONFIG_NOMSI) > sizeof(struct virtio_console_config))
- error("config offset is too big: %li", offset - VIRTIO_PCI_CONFIG_NOMSI);
+ if ((offset - VIRTIO_MSI_CONFIG_VECTOR) > sizeof(struct virtio_console_config))
+ error("config offset is too big: %li", offset - VIRTIO_MSI_CONFIG_VECTOR);
- ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]);
+ ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]);
return true;
}
@@ -201,7 +200,7 @@ static bool virtio_console_pci_io_out(struct kvm *self, u16 port, void *data, in
queue->pfn = ioport__read32(data);
p = guest_pfn_to_host(self, queue->pfn);
- vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, 4096);
+ vring_init(&queue->vring, VIRTIO_CONSOLE_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
if (cdev.queue_selector == VIRTIO_CONSOLE_TX_QUEUE)
cdev.jobs[cdev.queue_selector] = thread_pool__add_job(self, virtio_console_handle_callback, queue);
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 3f3ee22..2009d4a 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -1,5 +1,4 @@
#include "kvm/virtio-net.h"
-#include "kvm/virtio-pci.h"
#include "kvm/virtio-pci-dev.h"
#include "kvm/virtio.h"
#include "kvm/ioport.h"
@@ -154,10 +153,10 @@ static bool virtio_net_pci_io_device_specific_in(void *data, unsigned long offse
if (size != 1 || count != 1)
return false;
- if ((offset - VIRTIO_PCI_CONFIG_NOMSI) > sizeof(struct virtio_net_config))
- error("config offset is too big: %li", offset - VIRTIO_PCI_CONFIG_NOMSI);
+ if ((offset - VIRTIO_MSI_CONFIG_VECTOR) > sizeof(struct virtio_net_config))
+ error("config offset is too big: %li", offset - VIRTIO_MSI_CONFIG_VECTOR);
- ioport__write8(data, config_space[offset - VIRTIO_PCI_CONFIG_NOMSI]);
+ ioport__write8(data, config_space[offset - VIRTIO_MSI_CONFIG_VECTOR]);
return true;
}
@@ -247,7 +246,7 @@ static bool virtio_net_pci_io_out(struct kvm *self, u16 port, void *data, int si
queue->pfn = ioport__read32(data);
p = guest_pfn_to_host(self, queue->pfn);
- vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, 4096);
+ vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
break;
}
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 1951d0d1c..cf258fa 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -1,6 +1,5 @@
#include "kvm/virtio-rng.h"
-#include "kvm/virtio-pci.h"
#include "kvm/virtio-pci-dev.h"
#include "kvm/disk-image.h"
@@ -131,7 +130,7 @@ static bool virtio_rng_pci_io_out(struct kvm *kvm, u16 port, void *data, int siz
queue->pfn = ioport__read32(data);
p = guest_pfn_to_host(kvm, queue->pfn);
- vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, 4096);
+ vring_init(&queue->vring, VIRTIO_RNG_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
rdev.jobs[rdev.queue_selector] = thread_pool__add_job(kvm, virtio_rng_do_io, queue);
--
1.7.5.rc3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes
2011-05-11 4:09 [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Sasha Levin
2011-05-11 4:09 ` [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound Sasha Levin
2011-05-11 4:09 ` [PATCH 3/3] kvm tools: Use definitions from kernel headers Sasha Levin
@ 2011-05-11 7:15 ` Ingo Molnar
2 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2011-05-11 7:15 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, asias.hejun, prasadjoshi124, avi, gorcunov, kvm
* Sasha Levin <levinsasha928@gmail.com> wrote:
> Add a memory gap between 0xe0000000 and 0x100000000
> when using more than 0xe0000000 bytes for guest RAM.
>
> This space is used by several things, PCI configuration
> space for example.
>
> This patch updates the e820 table, slot allocations
> used for KVM_SET_USER_MEMORY_REGION, and the address
> translation.
Btw., in changelogs you really want to mention the *motivation* and effect of
patches - not just the workings of the patch. Everyone can see what a patch
does, so the motivation and effects are a lot more important and should be
mentioned first in the patch - explaining how the patch does it is a distant
third factor in terms of changelog-content importance ...
If someone reads these without context he has no idea that these patches are
fixing crashes and memory corruption with guest RAM sizes that cross the 4GB
boundary.
> + if (kvm->ram_size < 0xe0000000) {
> + .size = 0xe0000000 - BZ_KERNEL_START,
> + .size = kvm->ram_size - 0xe0000000 - BZ_KERNEL_START,
> + * We have a gap between 0xe0000000 and 0x100000000.
> + if (offset < 0xe0000000)
> + return self->ram_start + 0xe0000000 + (offset - 0x100000000);
> + if (self->ram_size < 0xe0000000) {
> + kvm_register_mem_slot(self, 0, 0, 0xe0000000, (u64)self->ram_start);
> + kvm_register_mem_slot(self, 1, 0x100000000ULL, self->ram_size - 0xe0000000, (u64)self->ram_start + 0xe0000000);
0xe0000000 is repeated 9 times in the code!
We tend to add symbols when values are repeated only twice. Often we add a
symbol and an explanation when a magic value is used only *once*.
It is absolutely vital to define a symbol for this and document that it means
and why we need it.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] kvm tools: Use definitions from kernel headers
2011-05-11 4:09 ` [PATCH 3/3] kvm tools: Use definitions from kernel headers Sasha Levin
@ 2011-05-11 10:59 ` Ingo Molnar
0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2011-05-11 10:59 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, asias.hejun, prasadjoshi124, avi, gorcunov, kvm
* Sasha Levin <levinsasha928@gmail.com> wrote:
> +++ b/tools/kvm/include/kvm/virtio-pci-dev.h
> @@ -16,4 +16,7 @@
> #define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE 0x0003
> #define PCI_SUBSYSTEM_ID_VIRTIO_RNG 0x0004
>
> +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
> +#define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET 0x1af4
Please look at the resulting header file in an editor.
Can you see any visual inconsistency with your change applied?
Thanks,
Ingo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound
2011-05-11 4:09 ` [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound Sasha Levin
@ 2011-05-11 11:15 ` Ingo Molnar
0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2011-05-11 11:15 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, asias.hejun, prasadjoshi124, avi, gorcunov, kvm
* Sasha Levin <levinsasha928@gmail.com> wrote:
> +++ b/tools/kvm/include/kvm/virtio.h
> @@ -36,6 +36,11 @@ static inline bool virt_queue__available(struct virt_queue *vq)
> return vq->vring.avail->idx != vq->last_avail_idx;
> }
>
> +static inline void *guest_pfn_to_host(struct kvm *kvm, u32 pfn)
> +{
> + return guest_flat_to_host(kvm, (unsigned long)pfn << 12);
> +}
We should at minimum document that on 32-bit hosts this will clip things at
4GB.
Documenting such things helps, in case someone ventures into fixing this
limitation in the future.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-11 17:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-11 4:09 [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Sasha Levin
2011-05-11 4:09 ` [PATCH 2/3 V2] kvm tools: Prevent PFN wraparound Sasha Levin
2011-05-11 11:15 ` Ingo Molnar
2011-05-11 4:09 ` [PATCH 3/3] kvm tools: Use definitions from kernel headers Sasha Levin
2011-05-11 10:59 ` Ingo Molnar
2011-05-11 7:15 ` [PATCH 1/3] kvm tools: Add memory gap for larger RAM sizes Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox