All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jes Sorensen <Jes.Sorensen@redhat.com>
To: "Kevin O'Connor" <kevin@koconnor.net>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	Avi Kivity <avi@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	seabios@seabios.org, Alexander Graf <agraf@suse.de>
Subject: [PATCH] QEMU-KVM - provide e820 table via fw_cfg
Date: Tue, 26 Jan 2010 22:53:51 +0100	[thread overview]
Message-ID: <4B5F646F.7040001@redhat.com> (raw)
In-Reply-To: <4B5F640C.2030907@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

Hi,

This is the QEMU-KVM part of the patch. If we can agree on this
approach, I will do a version for upstream QEMU as well.

Cheers,
Jes


[-- Attachment #2: 0011-qemu-kvm-e820-table.patch --]
[-- Type: text/plain, Size: 3920 bytes --]

Use qemu-cfg to provide the BIOS with an optional table of e820 entries.

Notify the BIOS of the location of the TSS+EPT range to by reserving
it via the e820 table.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>

---
 hw/pc.c           |   35 +++++++++++++++++++++++++++++++++++
 hw/pc.h           |    9 +++++++++
 qemu-kvm-x86.c    |    7 +++++++
 target-i386/kvm.c |    7 +++++++
 4 files changed, 58 insertions(+)

Index: qemu-kvm/hw/pc.c
===================================================================
--- qemu-kvm.orig/hw/pc.c
+++ qemu-kvm/hw/pc.c
@@ -66,6 +66,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -74,6 +75,21 @@ static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
 
+#define E820_NR_ENTRIES		16
+
+struct e820_entry {
+    uint64_t address;
+    uint64_t length;
+    uint32_t type;
+};
+
+struct e820_table {
+    uint32_t count;
+    struct e820_entry entry[E820_NR_ENTRIES];
+};
+
+static struct e820_table e820_table;
+
 qemu_irq *ioapic_irq_hack;
 
 typedef struct isa_irq_state {
@@ -444,6 +460,23 @@ static void bochs_bios_write(void *opaqu
     }
 }
 
+int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
+{
+    int index = e820_table.count;
+    struct e820_entry *entry;
+
+    if (index >= E820_NR_ENTRIES)
+        return -EBUSY;
+    entry = &e820_table.entry[index];
+
+    entry->address = address;
+    entry->length = length;
+    entry->type = type;
+
+    e820_table.count++;
+    return e820_table.count;
+}
+
 static void *bochs_bios_init(void)
 {
     void *fw_cfg;
@@ -475,6 +508,8 @@ static void *bochs_bios_init(void)
     if (smbios_table)
         fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
                          smbios_table, smbios_len);
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
+                     sizeof(struct e820_table));
 
     /* allocate memory for the NUMA channel: one (64bit) word for the number
      * of nodes, one word for each VCPU->node and one word for each node to
Index: qemu-kvm/hw/pc.h
===================================================================
--- qemu-kvm.orig/hw/pc.h
+++ qemu-kvm/hw/pc.h
@@ -169,4 +169,13 @@ void extboot_init(BlockDriverState *bs, 
 
 int cpu_is_bsp(CPUState *env);
 
+/* e820 types */
+#define E820_RAM        1
+#define E820_RESERVED   2
+#define E820_ACPI       3
+#define E820_NVS        4
+#define E820_UNUSABLE   5
+
+int e820_add_entry(uint64_t, uint64_t, uint32_t);
+
 #endif
Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 {
 #ifdef KVM_CAP_SET_TSS_ADDR
 	int r;
+        /*
+         * Tell fw_cfg to notify the BIOS to reserve the range.
+         */
+        if (e820_add_entry(addr, 0x4000, E820_RESERVED) < 0) {
+            perror("e820_add_entry() table is full");
+            exit(1);
+        }
 
 	r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
 	if (r > 0) {
Index: qemu-kvm/target-i386/kvm.c
===================================================================
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -298,6 +298,13 @@ int kvm_arch_init(KVMState *s, int smp_c
      * as unavaible memory.  FIXME, need to ensure the e820 map deals with
      * this?
      */
+    /*
+     * Tell fw_cfg to notify the BIOS to reserve the range.
+     */
+    if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) {
+        perror("e820_add_entry() table is full");
+        exit(1);
+    }
     return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
                     

WARNING: multiple messages have this Message-ID (diff)
From: Jes Sorensen <Jes.Sorensen@redhat.com>
To: Kevin O'Connor <kevin@koconnor.net>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	kvm@vger.kernel.org, seabios@seabios.org,
	Alexander Graf <agraf@suse.de>,
	qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCH] QEMU-KVM - provide e820 table via fw_cfg
Date: Tue, 26 Jan 2010 22:53:51 +0100	[thread overview]
Message-ID: <4B5F646F.7040001@redhat.com> (raw)
In-Reply-To: <4B5F640C.2030907@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 140 bytes --]

Hi,

This is the QEMU-KVM part of the patch. If we can agree on this
approach, I will do a version for upstream QEMU as well.

Cheers,
Jes


[-- Attachment #2: 0011-qemu-kvm-e820-table.patch --]
[-- Type: text/plain, Size: 3920 bytes --]

Use qemu-cfg to provide the BIOS with an optional table of e820 entries.

Notify the BIOS of the location of the TSS+EPT range to by reserving
it via the e820 table.

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>

---
 hw/pc.c           |   35 +++++++++++++++++++++++++++++++++++
 hw/pc.h           |    9 +++++++++
 qemu-kvm-x86.c    |    7 +++++++
 target-i386/kvm.c |    7 +++++++
 4 files changed, 58 insertions(+)

Index: qemu-kvm/hw/pc.c
===================================================================
--- qemu-kvm.orig/hw/pc.c
+++ qemu-kvm/hw/pc.c
@@ -66,6 +66,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -74,6 +75,21 @@ static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
 
+#define E820_NR_ENTRIES		16
+
+struct e820_entry {
+    uint64_t address;
+    uint64_t length;
+    uint32_t type;
+};
+
+struct e820_table {
+    uint32_t count;
+    struct e820_entry entry[E820_NR_ENTRIES];
+};
+
+static struct e820_table e820_table;
+
 qemu_irq *ioapic_irq_hack;
 
 typedef struct isa_irq_state {
@@ -444,6 +460,23 @@ static void bochs_bios_write(void *opaqu
     }
 }
 
+int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
+{
+    int index = e820_table.count;
+    struct e820_entry *entry;
+
+    if (index >= E820_NR_ENTRIES)
+        return -EBUSY;
+    entry = &e820_table.entry[index];
+
+    entry->address = address;
+    entry->length = length;
+    entry->type = type;
+
+    e820_table.count++;
+    return e820_table.count;
+}
+
 static void *bochs_bios_init(void)
 {
     void *fw_cfg;
@@ -475,6 +508,8 @@ static void *bochs_bios_init(void)
     if (smbios_table)
         fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
                          smbios_table, smbios_len);
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
+                     sizeof(struct e820_table));
 
     /* allocate memory for the NUMA channel: one (64bit) word for the number
      * of nodes, one word for each VCPU->node and one word for each node to
Index: qemu-kvm/hw/pc.h
===================================================================
--- qemu-kvm.orig/hw/pc.h
+++ qemu-kvm/hw/pc.h
@@ -169,4 +169,13 @@ void extboot_init(BlockDriverState *bs, 
 
 int cpu_is_bsp(CPUState *env);
 
+/* e820 types */
+#define E820_RAM        1
+#define E820_RESERVED   2
+#define E820_ACPI       3
+#define E820_NVS        4
+#define E820_UNUSABLE   5
+
+int e820_add_entry(uint64_t, uint64_t, uint32_t);
+
 #endif
Index: qemu-kvm/qemu-kvm-x86.c
===================================================================
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 {
 #ifdef KVM_CAP_SET_TSS_ADDR
 	int r;
+        /*
+         * Tell fw_cfg to notify the BIOS to reserve the range.
+         */
+        if (e820_add_entry(addr, 0x4000, E820_RESERVED) < 0) {
+            perror("e820_add_entry() table is full");
+            exit(1);
+        }
 
 	r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
 	if (r > 0) {
Index: qemu-kvm/target-i386/kvm.c
===================================================================
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -298,6 +298,13 @@ int kvm_arch_init(KVMState *s, int smp_c
      * as unavaible memory.  FIXME, need to ensure the e820 map deals with
      * this?
      */
+    /*
+     * Tell fw_cfg to notify the BIOS to reserve the range.
+     */
+    if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) {
+        perror("e820_add_entry() table is full");
+        exit(1);
+    }
     return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
                     

  reply	other threads:[~2010-01-26 21:54 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-25 16:46 [PATCH] Seabios - read e820 reserve from qemu_cfg Jes Sorensen
2010-01-25 16:46 ` [Qemu-devel] " Jes Sorensen
2010-01-25 16:49 ` [PATCH] QEMU-KVM - provide e820 reserve through qemu_cfg Jes Sorensen
2010-01-25 16:49   ` [Qemu-devel] " Jes Sorensen
2010-01-25 16:52   ` [PATCH] QEMU " Jes Sorensen
2010-01-25 16:52     ` [Qemu-devel] " Jes Sorensen
2010-01-25 16:58     ` Alexander Graf
2010-01-25 16:58       ` [Qemu-devel] " Alexander Graf
2010-01-25 17:13       ` Jes Sorensen
2010-01-25 17:13         ` [Qemu-devel] " Jes Sorensen
2010-01-25 17:28         ` Alexander Graf
2010-01-25 17:28           ` [Qemu-devel] " Alexander Graf
2010-01-25 17:46           ` Jes Sorensen
2010-01-25 17:46             ` [Qemu-devel] " Jes Sorensen
2010-01-25 20:04             ` Alexander Graf
2010-01-25 20:04               ` [Qemu-devel] " Alexander Graf
2010-01-25 20:14               ` Anthony Liguori
2010-01-25 20:14                 ` [Qemu-devel] " Anthony Liguori
2010-01-25 21:05                 ` Jes Sorensen
2010-01-25 21:05                   ` [Qemu-devel] " Jes Sorensen
2010-01-25 21:08                   ` Alexander Graf
2010-01-25 21:08                     ` [Qemu-devel] " Alexander Graf
2010-01-25 21:24                     ` Jes Sorensen
2010-01-25 21:24                       ` [Qemu-devel] " Jes Sorensen
2010-01-26  6:46         ` Gleb Natapov
2010-01-26  6:46           ` [Qemu-devel] " Gleb Natapov
2010-01-26  8:36           ` Jes Sorensen
2010-01-26  8:36             ` [Qemu-devel] " Jes Sorensen
2010-01-26  0:24 ` [PATCH] Seabios - read e820 reserve from qemu_cfg Kevin O'Connor
2010-01-26  0:24   ` [Qemu-devel] " Kevin O'Connor
2010-01-26 21:52   ` [PATCH] Seabios - read e820 table " Jes Sorensen
2010-01-26 21:52     ` [Qemu-devel] " Jes Sorensen
2010-01-26 21:53     ` Jes Sorensen [this message]
2010-01-26 21:53       ` [Qemu-devel] [PATCH] QEMU-KVM - provide e820 table via fw_cfg Jes Sorensen
2010-01-26 21:55       ` Alexander Graf
2010-01-26 21:55         ` [Qemu-devel] " Alexander Graf
2010-01-28  4:39     ` [PATCH] Seabios - read e820 table from qemu_cfg Kevin O'Connor
2010-01-28  4:39       ` [Qemu-devel] " Kevin O'Connor
2010-01-29  9:03       ` Jes Sorensen
2010-01-29  9:03         ` [Qemu-devel] " Jes Sorensen
2010-01-29 16:08         ` Gleb Natapov
2010-01-29 16:08           ` [Qemu-devel] " Gleb Natapov
2010-01-30  3:35         ` Kevin O'Connor
2010-01-30  3:35           ` [Qemu-devel] " Kevin O'Connor
2010-02-08 10:31       ` Jes Sorensen
2010-02-08 10:31         ` [Qemu-devel] " Jes Sorensen
2010-02-14  3:16         ` Kevin O'Connor
2010-02-14  3:16           ` [Qemu-devel] " Kevin O'Connor

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=4B5F646F.7040001@redhat.com \
    --to=jes.sorensen@redhat.com \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=kevin@koconnor.net \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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.