Re: [PATCH] kvm tools: powerpc: convert spapr pci to new device iterators

2012-11-28 Thread Matt Evans

Hi Will,

On 2012-11-27 13:00, Will Deacon wrote:

Commit 8d35d32d0148 (kvm tools: add generic device registration
mechanism) introduced a tree-based device lookup-by-bus mechanism as
well as iterators to enumerate the devices on a particular bus.

Whilst both x86 and ppc were converted by the original patch, the 
spapr

pci changes were incomplete, so include the required changes here.

Compile-tested only on ppc64 970mp. Note that I had to hack the 
Makefile

in order to build guest_init.o with a toolchain defaulting to ppc:

 $(GUEST_INIT): guest/init.c
$(E)   LINK $@
-   $(Q) $(CC) -static guest/init.c -o $@
-   $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
+   $(Q) $(CC) -m64 -static guest/init.c -o $@
+   $(Q) $(LD) -m elf64ppc -r -b binary -o guest/guest_init.o
$(GUEST_INIT)

 $(DEPS):

Cc: Matt Evans m...@ozlabs.org
Signed-off-by: Will Deacon will.dea...@arm.com


I lack PPC
But this patch appears too good
To be left aside

Acked-by: Matt Evans m...@ozlabs.org


Cheers,

Matt


---
 tools/kvm/powerpc/spapr_pci.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/powerpc/spapr_pci.c 
b/tools/kvm/powerpc/spapr_pci.c

index 5f4016c..ed4b9ab 100644
--- a/tools/kvm/powerpc/spapr_pci.c
+++ b/tools/kvm/powerpc/spapr_pci.c
@@ -15,6 +15,7 @@

 #include spapr.h
 #include spapr_pci.h
+#include kvm/devices.h
 #include kvm/fdt.h
 #include kvm/util.h
 #include kvm/pci.h
@@ -248,6 +249,7 @@ int spapr_populate_pci_devices(struct kvm *kvm,
   void *fdt)
 {
int bus_off, node_off = 0, devid, fn, i, n, devices;
+   struct device_header *dev_hdr;
char nodename[256];
struct {
uint32_t hi;
@@ -301,14 +303,15 @@ int spapr_populate_pci_devices(struct kvm *kvm,

/* Populate PCI devices and allocate IRQs */
devices = 0;
-
-   for (devid = 0; devid  KVM_MAX_DEVICES; devid++) {
+   dev_hdr = device__first_dev(DEVICE_BUS_PCI);
+   while (dev_hdr) {
uint32_t *irqmap = interrupt_map[devices];
-   struct pci_device_header *hdr = pci__find_dev(devid);
+   struct pci_device_header *hdr = dev_hdr-data;

if (!hdr)
continue;

+   devid = dev_hdr-dev_num;
fn = 0; /* kvmtool doesn't yet do multifunction devices */

sprintf(nodename, pci@%u,%u, devid, fn);
@@ -413,6 +416,7 @@ int spapr_populate_pci_devices(struct kvm *kvm,
 		/* We don't set ibm,dma-window property as we don't have an IOMMU. 
*/


++devices;
+   dev_hdr = device__next_dev(dev_hdr);
}

/* Write interrupt map */


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [RFC PATCH 16/16] kvm tools: add support for ARMv7 processors

2012-11-13 Thread Matt Evans
Hi Pekka,

On 13 November 2012 07:40 Pekka Enberg wrote:

 On Mon, 12 Nov 2012, Will Deacon wrote:
  This patch adds initial support for ARMv7 processors (more
 specifically,
  Cortex-A15) to kvmtool.
 
  Everything is driven by FDT, including dynamic generation of virtio
 nodes
  for MMIO devices (PCI is not used due to lack of a suitable host-
 bridge).
 
  The virtual timers and virtual interrupt controller (VGIC) are
 provided
  by the kernel and require very little in terms of userspace code.
 
  Signed-off-by: Will Deacon will.dea...@arm.com

 I'm happy with this but I'm not really an ARM guy. Is there anyone in
 the
 ARM/KVM community who is interested in reviewing this?

For the sake of transparency, I sent some minor feedback to Will off-list so 
that my (Outlook :( ) broken linewraps  legal autoappend signature (see above 
and below) wouldn't pollute the thread on-list.  He'll use my IMAP address next 
time. ;-)

I *think* Will was going to make some small changes, if you've already merged 
it then a follow-up set perhaps?

(Modulo minor changes,
Acked-By: Matt Evans m...@ozlabs.org
)

Cheers,


Matt


-- IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium.  Thank you.

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool

2012-07-17 Thread Matt Evans

Hi Michael,

On 2012-07-17 06:00, Michael Ellerman wrote:


This is a series for kvmtool that uses a newish kernel API to get
MMU info, which is then fed to the guest.

Currently we just make a good guess based on the PVR, but that is
potentially flakey in a few ways. The most notable is that if you 
don't
specify hugepages we don't boot - because the guest is told we 
support

16M pages, but we don't really (on HV).


Just had a look, all good.  Thanks for tidying some old FIXMEs, 
especially the page/segment DT props encoding grot -- and the designated 
inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
;-)



Acked-by: Matt Evans m...@ozlabs.org


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH] Use kernel supplied MMU info for kvm tool

2012-07-17 Thread Matt Evans

Hi Michael,

On 2012-07-17 06:00, Michael Ellerman wrote:


This is a series for kvmtool that uses a newish kernel API to get
MMU info, which is then fed to the guest.

Currently we just make a good guess based on the PVR, but that is
potentially flakey in a few ways. The most notable is that if you 
don't
specify hugepages we don't boot - because the guest is told we 
support

16M pages, but we don't really (on HV).


Just had a look, all good.  Thanks for tidying some old FIXMEs, 
especially the page/segment DT props encoding grot -- and the designated 
inits in the cpuinfo struct, whew, I heard the scream on IRC.  Sorry. 
;-)



Acked-by: Matt Evans m...@ozlabs.org


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tool: Fix powerpc/kvm-cpu.c for new KVM_SET_ONE_REG API

2012-07-04 Thread Matt Evans

On 04/07/2012, at 2:39 PM, Michael Ellerman wrote:

 I think this code was based on an earlier version of the KVM_SET_ONE_REG
 API, which at the time was in agraf's tree but not mainline?
 
 Either way it doesn't compile as is, so fix it up.

Bit late, but I concur, all the patches look just swell.  Thank you!


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC/PATCH 1/2] kvm tools, seabios: Add --bios option to vm run

2012-02-25 Thread Matt Evans
On 25 Feb 2012, at 02:23, Anthony Liguori aligu...@us.ibm.com wrote:

 On 02/24/2012 09:05 AM, Pekka Enberg wrote:
 This patch adds a --bios command line option to vm run. You can use this 
 to
 try to boot with SeaBIOS, for example:
 
   ./vm run --bios=/usr/share/seabios/bios.bin \
 --disk $HOME/images/debian_lenny_amd64_standard.qcow2
 
 This doesn't boot yet for obvious reasons but at least people can now start 
 to
 play with external BIOS images easily.
 
 You may want to call it firmware as other platforms also have firmware.  For 
 instance, it may be desirable to use the same interface to load SLOF with 
 spapr.

Seconded, BIOS is a bit of an arch-specific phrase... and antique ;)


Matt


 
 
 Cc: Yang Baihamo...@gmail.com
 Cc: Matt Evansm...@ozlabs.org
 Cc: Ron Minnichrminn...@gmail.com
 Cc: Anthony Liguorialigu...@us.ibm.com
 Cc: John Florenj...@jfloren.net
 Cc: Sasha Levinlevinsasha...@gmail.com
 Cc: Cyrill Gorcunovgorcu...@openvz.org
 Cc: Asias Heasias.he...@gmail.com
 Cc: Ingo Molnarmi...@elte.hu
 Signed-off-by: Pekka Enbergpenb...@kernel.org
 ---
  tools/kvm/Makefile   |2 +
  tools/kvm/builtin-run.c  |   32 +++--
  tools/kvm/include/kvm/kvm.h  |1 +
  tools/kvm/powerpc/boot.c |8 +++
  tools/kvm/x86/boot.c |   41 
 ++
  tools/kvm/x86/include/kvm/bios.h |3 +-
  6 files changed, 75 insertions(+), 12 deletions(-)
  create mode 100644 tools/kvm/powerpc/boot.c
  create mode 100644 tools/kvm/x86/boot.c
 
 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index cfa5547..0a9c2cc 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -113,6 +113,7 @@ LIBFDT_OBJS = $(patsubst 
 %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
  #x86
  ifeq ($(ARCH),x86)
  DEFINES += -DCONFIG_X86
 +OBJS+= x86/boot.o
  OBJS+= x86/cpuid.o
  OBJS+= x86/interrupt.o
  OBJS+= x86/ioport.o
 @@ -129,6 +130,7 @@ endif
  # POWER/ppc:  Actually only support ppc64 currently.
  ifeq ($(uname_M), ppc64)
  DEFINES += -DCONFIG_PPC
 +OBJS+= powerpc/boot.o
  OBJS+= powerpc/ioport.o
  OBJS+= powerpc/irq.o
  OBJS+= powerpc/kvm.o
 diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
 index 466169e..f96c581 100644
 --- a/tools/kvm/builtin-run.c
 +++ b/tools/kvm/builtin-run.c
 @@ -76,6 +76,7 @@ static const char *kernel_cmdline;
  static const char *kernel_filename;
  static const char *vmlinux_filename;
  static const char *initrd_filename;
 +static const char *bios_filename;
  static const char *image_filename[MAX_DISK_IMAGES];
  static const char *console;
  static const char *dev;
 @@ -458,6 +459,8 @@ static const struct option options[] = {
  Initial RAM disk image),
  OPT_STRING('p', params,kernel_cmdline, params,
  Kernel command line arguments),
 +OPT_STRING('b', bios,bios_filename, bios,
 +BIOS to boot in virtual machine),
 
  OPT_GROUP(Networking options:),
  OPT_CALLBACK_DEFAULT('n', network, NULL, network params,
 @@ -1110,14 +1113,16 @@ static int kvm_cmd_run_init(int argc, const char 
 **argv)
  printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
  kernel_filename, ram_size / 1024 / 1024, nrcpus, guest_name);
 
 -if (!kvm__load_kernel(kvm, kernel_filename, initrd_filename,
 -real_cmdline, vidmode))
 -die(unable to load kernel %s, kernel_filename);
 +if (!bios_filename) {
 +if (!kvm__load_kernel(kvm, kernel_filename,
 +initrd_filename, real_cmdline, vidmode))
 +die(unable to load kernel %s, kernel_filename);
 
 -kvm-vmlinux = vmlinux_filename;
 -r = symbol_init(kvm);
 -if (r  0)
 -pr_debug(symbol_init() failed with error %d\n, r);
 +kvm-vmlinux = vmlinux_filename;
 +r = symbol_init(kvm);
 +if (r  0)
 +pr_debug(symbol_init() failed with error %d\n, r);
 +}
 
  ioport__setup_arch();
 
 @@ -1218,10 +1223,15 @@ static int kvm_cmd_run_init(int argc, const char 
 **argv)
 
  kvm__start_timer(kvm);
 
 -kvm__arch_setup_firmware(kvm);
 -if (r  0) {
 -pr_err(kvm__arch_setup_firmware() failed with error %d\n, r);
 -goto fail;
 +if (bios_filename) {
 +if (!kvm__load_bios(kvm, bios_filename))
 +die(unable to load bios %s: %s, bios_filename, 
 strerror(errno));
 +} else {
 +kvm__arch_setup_firmware(kvm);
 +if (r  0) {
 +pr_err(kvm__arch_setup_firmware() failed with error %d\n, r);
 +goto fail;
 +}
  }
 
  for (i = 0; i  nrcpus; i++) {
 diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
 index 7870118..258d11a 100644
 --- a/tools/kvm/include/kvm/kvm.h
 +++ b/tools/kvm/include/kvm/kvm.h
 @@ -39,6 +39,7 @@ int kvm__recommended_cpus(struct kvm *kvm);
  int kvm__max_cpus(struct kvm *kvm);
  void 

[PATCH] kvm tools: Enable PPC64 to build static

2012-02-05 Thread Matt Evans
By enable, I mean fix; the re-jigged commit 7ef85e8b builds libfdt
using OBJS rather than OTHEROBJS hence ignores the relaxed CFLAGS.

This commit builds it via OTHEROBJS.

Signed-off-by: Matt Evans m...@ozlabs.org
---

Pekka, not quite sure how this slipped through as I was building static
in testing... hrm.  The orthogonal 'build static' patch broke
the PPC64 stuff.  Simple fix tho.


 tools/kvm/Makefile |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 4dc2522..cfa5547 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -142,7 +142,7 @@ ifeq ($(uname_M), ppc64)
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
-   OBJS+= $(LIBFDT_OBJS)
+   OTHEROBJS   += $(LIBFDT_OBJS)
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
 endif
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Enable PPC64 to build static

2012-02-05 Thread Matt Evans
By enable, I mean fix; the re-jigged commit 7ef85e8b builds libfdt
using OBJS rather than OTHEROBJS hence ignores the relaxed CFLAGS.

This commit builds it via OTHEROBJS.

Signed-off-by: Matt Evans m...@ozlabs.org
---

Pekka, not quite sure how this slipped through as I was building static
in testing... hrm.  The orthogonal 'build static' patch broke
the PPC64 stuff.  Simple fix tho.


 tools/kvm/Makefile |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 4dc2522..cfa5547 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -142,7 +142,7 @@ ifeq ($(uname_M), ppc64)
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
-   OBJS+= $(LIBFDT_OBJS)
+   OTHEROBJS   += $(LIBFDT_OBJS)
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
 endif
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V3] kvm tools: Add build target for statically-linked binary

2012-02-01 Thread Matt Evans
This commit adds a target for 'lkvm-static' which is linked -static.

(This can be useful to construct kvmtool binaries for minimalist
auto-test host filesystems.)

Since extra features (SDL, AIO, VNC etc.) are auto-detected in the makefile
AND some features may only work when linked one way (but not both), the
feature detection now checks for both dynamic  static success.  Intermediate
objects build with correct flags (e.g. CONFIG_HAS_AIO) for the end target.

Signed-off-by: Matt Evans m...@ozlabs.org
---

V3:  OK, I solved the problem of probe for dynamic optional lib, fail to
link it statically with a second set of probes, for static optional libs,
with appropriate dependencies to tie all this back to lkvm-static.


 tools/kvm/Makefile |   98 ---
 1 files changed, 69 insertions(+), 29 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index ccf10fb..513bb51 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -143,52 +143,76 @@ else
UNSUPP_ERR =
 endif
 
+###
+
+# Detect optional features.
+# On a given system, some libs may link statically, some may not; so, check
+# both and only build those that link!
 
 FLAGS_BFD := $(CFLAGS) -lbfd
-has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
-ifeq ($(has_bfd),y)
-   CFLAGS  += -DCONFIG_HAS_BFD
-   OBJS+= symbol.o
-   LIBS+= -lbfd
+ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)),y)
+   CFLAGS_DYNOPT   += -DCONFIG_HAS_BFD
+   OBJS_DYNOPT += symbol.o
+   LIBS_DYNOPT += -lbfd
+endif
+ifeq ($(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD) -static),y)
+   CFLAGS_STATOPT  += -DCONFIG_HAS_BFD
+   OBJS_STATOPT+= symbol.o
+   LIBS_STATOPT+= -lbfd
 endif
 
 FLAGS_VNCSERVER := $(CFLAGS) -lvncserver
-has_vncserver := $(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER))
-ifeq ($(has_vncserver),y)
-   OBJS+= ui/vnc.o
-   CFLAGS  += -DCONFIG_HAS_VNCSERVER
-   LIBS+= -lvncserver
+ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER)),y)
+   OBJS_DYNOPT += ui/vnc.o
+   CFLAGS_DYNOPT   += -DCONFIG_HAS_VNCSERVER
+   LIBS_DYNOPT += -lvncserver
+endif
+ifeq ($(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER) -static),y)
+   OBJS_STATOPT+= ui/vnc.o
+   CFLAGS_STATOPT  += -DCONFIG_HAS_VNCSERVER
+   LIBS_STATOPT+= -lvncserver
 endif
 
 FLAGS_SDL := $(CFLAGS) -lSDL
-has_SDL := $(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL))
-ifeq ($(has_SDL),y)
-   OBJS+= ui/sdl.o
-   CFLAGS  += -DCONFIG_HAS_SDL
-   LIBS+= -lSDL
+ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL)),y)
+   OBJS_DYNOPT += ui/sdl.o
+   CFLAGS_DYNOPT   += -DCONFIG_HAS_SDL
+   LIBS_DYNOPT += -lSDL
+endif
+ifeq ($(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL) -static), y)
+   OBJS_STATOPT+= ui/sdl.o
+   CFLAGS_STATOPT  += -DCONFIG_HAS_SDL
+   LIBS_STATOPT+= -lSDL
 endif
 
 FLAGS_ZLIB := $(CFLAGS) -lz
-has_ZLIB := $(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB))
-ifeq ($(has_ZLIB),y)
-   CFLAGS  += -DCONFIG_HAS_ZLIB
-   LIBS+= -lz
+ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB)),y)
+   CFLAGS_DYNOPT   += -DCONFIG_HAS_ZLIB
+   LIBS_DYNOPT += -lz
+endif
+ifeq ($(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB) -static),y)
+   CFLAGS_STATOPT  += -DCONFIG_HAS_ZLIB
+   LIBS_STATOPT+= -lz
 endif
 
 FLAGS_AIO := $(CFLAGS) -laio
-has_AIO := $(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO))
-ifeq ($(has_AIO),y)
-   CFLAGS  += -DCONFIG_HAS_AIO
-   LIBS+= -laio
+ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO)),y)
+   CFLAGS_DYNOPT   += -DCONFIG_HAS_AIO
+   LIBS_DYNOPT += -laio
+endif
+ifeq ($(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO) -static),y)
+   CFLAGS_STATOPT  += -DCONFIG_HAS_AIO
+   LIBS_STATOPT+= -laio
 endif
 
+###
+
 LIBS   += -lrt
 LIBS   += -lpthread
 LIBS   += -lutil
 
 
 DEPS   := $(patsubst %.o,%.d,$(OBJS))
-OBJS   += $(OTHEROBJS)
 
 DEFINES+= -D_FILE_OFFSET_BITS=64
 DEFINES+= -D_GNU_SOURCE
@@ -229,9 +253,21 @@ KVMTOOLS-VERSION-FILE:
@$(SHELL_PATH) util/KVMTOOLS-VERSION-GEN $(OUTPUT)
 -include $(OUTPUT)KVMTOOLS-VERSION-FILE
 
-$(PROGRAM): $(DEPS) $(OBJS)
+# When building -static all objects are built with appropriate flags, which
+# may differ between static  dynamic .o.  The objects are separated into
+# .o and .static.o.  See the %.o: %.c rules below.
+#
+# $(OTHEROBJS) are things that do not get substituted like this.
+#
+STATIC_OBJS = $(patsubst %.o,%.static.o,$(OBJS) $(OBJS_STATOPT))
+
+$(PROGRAM)-static:  $(DEPS) $(STATIC_OBJS) $(OTHEROBJS)
+   $(E)   LINK $@
+   $(Q) $(CC) -static $(CFLAGS) $(STATIC_OBJS) $(OTHEROBJS) $(LIBS) 
$(LIBS_STATOPT) -o $@
+
+$(PROGRAM): $(DEPS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS)
$(E)   LINK $@
-   $(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
+   $(Q) $(CC) $(CFLAGS) $(OBJS) $(OBJS_DYNOPT) $(OTHEROBJS) $(LIBS) 
$(LIBS_DYNOPT) -o

Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree

2012-01-31 Thread Matt Evans

On 31 Jan 2012, at 18:59, Pekka Enberg wrote:

 On Tue, Jan 31, 2012 at 8:34 AM, Matt Evans m...@ozlabs.org wrote:
 +static struct cpu_info cpu_power7_info = {
 +   POWER7,
 +   power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
 +   power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
 +   32, /* SLB size */
 +   51200,  /* TB frequency */
 +   128,/* d-cache block size */
 +   128,/* i-cache block size */
 +   CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
 +};
 
 Why don't you use C99 initializers here?

...just out of bad bad habit :)  Initialisers'd be cleaner, I'll convert them.


Thanks!


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V4 3/7] kvm tools: Add SPAPR PPC64 hcall rtascall structure

2012-01-31 Thread Matt Evans

On 31 Jan 2012, at 19:11, Pekka Enberg wrote:

 On Tue, Jan 31, 2012 at 8:34 AM, Matt Evans m...@ozlabs.org wrote:
 +#define DEBUG_SPAPR_HCALLS
 
 I suppose this shouldn't be defined by default?

Well, I had a bit of a debate about it.  I left it on as it is actually 
interesting whilst experimenting with different SPAPR guests.  For instance 
(and this is really out there, there are other reasons why this won't work) if 
someone tries an AIX guest it'd be good to see lots of Unsupported! spew.  
(The 'unsupported' message could be a warning but that might also get annoying, 
OTOH.)  I would prefer to leave it on for the moment.

 
 +#ifdef DEBUG_SPAPR_HCALLS
 +#define hcall_dprintf(fmt, ...) \
 +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define hcall_dprintf(fmt, ...) \
 +do { } while (0)
 +#endif
 
 I don't expect you to fix this but this sort of thing really cries out
 for userspace tracepoints.

Ha!  Yes...


Cheers,


Matt--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree

2012-01-31 Thread Matt Evans

On 31 Jan 2012, at 18:59, Pekka Enberg wrote:

 On Tue, Jan 31, 2012 at 8:34 AM, Matt Evans m...@ozlabs.org wrote:
 +static struct cpu_info cpu_power7_info = {
 +   POWER7,
 +   power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
 +   power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
 +   32, /* SLB size */
 +   51200,  /* TB frequency */
 +   128,/* d-cache block size */
 +   128,/* i-cache block size */
 +   CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
 +};
 
 Why don't you use C99 initializers here?

...just out of bad bad habit :)  Initialisers'd be cleaner, I'll convert them.


Thanks!


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V4 3/7] kvm tools: Add SPAPR PPC64 hcall rtascall structure

2012-01-31 Thread Matt Evans

On 31 Jan 2012, at 19:11, Pekka Enberg wrote:

 On Tue, Jan 31, 2012 at 8:34 AM, Matt Evans m...@ozlabs.org wrote:
 +#define DEBUG_SPAPR_HCALLS
 
 I suppose this shouldn't be defined by default?

Well, I had a bit of a debate about it.  I left it on as it is actually 
interesting whilst experimenting with different SPAPR guests.  For instance 
(and this is really out there, there are other reasons why this won't work) if 
someone tries an AIX guest it'd be good to see lots of Unsupported! spew.  
(The 'unsupported' message could be a warning but that might also get annoying, 
OTOH.)  I would prefer to leave it on for the moment.

 
 +#ifdef DEBUG_SPAPR_HCALLS
 +#define hcall_dprintf(fmt, ...) \
 +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define hcall_dprintf(fmt, ...) \
 +do { } while (0)
 +#endif
 
 I don't expect you to fix this but this sort of thing really cries out
 for userspace tracepoints.

Ha!  Yes...


Cheers,


Matt--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Repair running on non ioeventfd-capable platforms

2012-01-30 Thread Matt Evans

Commit d3923126a24212f1e746a84a575dadbd9f259418 added a bunch of
nice error checking around ioevent__init() but the init may gracefully
fail if ioevents simply aren't supported (PPC64 KVM).

This commit adds a new return code for the init -- positive, but
identifiable as 'not success 0'.

Signed-off-by: Matt Evans m...@ozlabs.org
---

Sasha, you screwed PPC64!  And it took me a month to notice hahaha!

 tools/kvm/ioeventfd.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 9133101..f2d5a30 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/ioeventfd.c
@@ -67,7 +67,7 @@ int ioeventfd__init(struct kvm *kvm)
 
ioeventfd_avail = kvm__supports_extension(kvm, KVM_CAP_IOEVENTFD);
if (!ioeventfd_avail)
-   return -ENOSYS;
+   return 1; /* Not fatal, but let caller determine no-go. */
 
epoll_fd = epoll_create(IOEVENTFD_MAX_EVENTS);
if (epoll_fd  0)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V4 0/7] Add initial SPAPR PPC64 architecture support

2012-01-30 Thread Matt Evans
This series adds support for a PPC64 platform, SPAPR, on top of the previous
more general PPC64 CPU support.  This platform is paravirtualised, with most
of the MMU hypercalls being dealt with in the kernel.  Userland needs to
describe the environment to the machine with a device tree, cope with some
hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate
the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque
machine.

With this series, normal pSeries kernels boot fine (including RH kernels that
include virtio support out of the box).  There is no support for PPC32 or
'bare metal' PPC64 guests as yet.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

The kernels are loaded as flat binaries and booted directly.  The intention
is to later support loading firmware such as SLOF.

Some of the code within is borrowed/based upon code in QEMU, particularly
the XICS emulation, device tree construction and PCI setup.

-- Changes since V3:
   - Gained another patch to provide PPC KVM-PR support (widens userbase :p )
 This allocates a page table, sets up a few more regs etc.  Also,
 removes restriction that mandates use of hugepages.
 Requires KVM-PR to implement H_BULK_REMOVE (separate patch)
   - Cleaned up FDT generation to detect host CPU  generate based
 on its properties; now supports PPC970 as well as POWER7
   - Removed redefinition of hypercall #defines, using asm/hvcall.h instead
   - More sensible MMIO layering; CPU passes MMIO to PHB, PHB then decides
 which PCI window is accessed.
   - Die if kernel-handled hypercalls ever get to userland
   - Build in libfdt as sugggested -- it's small and present in our sourcetree,
 and removes external dependency on 64bit libfdt (which isn't in some
 distros).
   - Spit  polish

Thanks to David  Alex for the PPC-related reviews!

Matt Evans (7):
  kvm tools: PPC64, add HPT/SDR1 for -PR KVM
  kvm tools: Generate SPAPR PPC64 guest device tree
  kvm tools: Add SPAPR PPC64 hcall  rtascall structure
  kvm tools: Add SPAPR PPC64 HV console
  kvm tools: Add PPC64 XICS interrupt controller support
  kvm tools: Add PPC64 PCI Host Bridge
  kvm tools: Add PPC64 kvm_cpu__emulate_io()

 tools/kvm/Makefile   |   31 ++-
 tools/kvm/powerpc/cpu_info.c |   83 
 tools/kvm/powerpc/cpu_info.h |   43 +++
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   17 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   12 +-
 tools/kvm/powerpc/irq.c  |   43 ++-
 tools/kvm/powerpc/kvm-cpu.c  |   64 +++-
 tools/kvm/powerpc/kvm.c  |  290 ++-
 tools/kvm/powerpc/spapr.h|   93 +
 tools/kvm/powerpc/spapr_hcall.c  |  134 +++
 tools/kvm/powerpc/spapr_hvcons.c |  102 +
 tools/kvm/powerpc/spapr_hvcons.h |   19 +
 tools/kvm/powerpc/spapr_pci.c|  423 +
 tools/kvm/powerpc/spapr_pci.h|   57 +++
 tools/kvm/powerpc/spapr_rtas.c   |  229 
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 17 files changed, 2150 insertions(+), 27 deletions(-)
 create mode 100644 tools/kvm/powerpc/cpu_info.c
 create mode 100644 tools/kvm/powerpc/cpu_info.h
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V4 1/7] kvm tools: PPC64, add HPT/SDR1 for -PR KVM

2012-01-30 Thread Matt Evans
Allocate a page table and point SDR1 to it in order to support the -PR
PPC64 KVM mode.  (The alternative, -HV mode, is available only on a small
set of machines.)

This patch also removes the previous dependency on mapping guest RAM with
huge pages; PR KVM doesn't require them so the user isn't forced to use them.

A new option, '--hugetlbfs default', uses a default path for 16M pages for
HV mode, if required.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/powerpc/include/kvm/kvm-arch.h |2 ++
 tools/kvm/powerpc/kvm-cpu.c  |   24 +---
 tools/kvm/powerpc/kvm.c  |   25 ++---
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index c4b493c..8653871 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -52,6 +52,8 @@ struct kvm {
u64 ram_size;
void*ram_start;
 
+   u64 sdr1;
+
boolnmi_disabled;
 
boolsingle_step;
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index ea99666..60379d0 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -76,7 +76,8 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long 
cpu_id)
if (vcpu-kvm_run == MAP_FAILED)
die(unable to mmap vcpu fd);
 
-   ioctl(vcpu-vcpu_fd, KVM_ENABLE_CAP, papr_cap);
+   if (ioctl(vcpu-vcpu_fd, KVM_ENABLE_CAP, papr_cap)  0)
+   die(unable to enable PAPR capability);
 
/*
 * We start all CPUs, directing non-primary threads into the kernel's
@@ -121,9 +122,26 @@ static void kvm_cpu__setup_regs(struct kvm_cpu *vcpu)
 static void kvm_cpu__setup_sregs(struct kvm_cpu *vcpu)
 {
/*
-* No sregs setup is required on PPC64/SPAPR (but there may be setup
-* required for non-paravirtualised platforms, e.g. TLB/SLB setup).
+* Some sregs setup to initialise SDR1/PVR/HIOR on PPC64 SPAPR
+* platforms using PR KVM.  (Technically, this is all ignored on
+* SPAPR HV KVM.)  Different setup is required for non-PV non-SPAPR
+* platforms!  (FIXME.)
 */
+   struct kvm_sregs sregs;
+   struct kvm_one_reg reg = {};
+
+   if (ioctl(vcpu-vcpu_fd, KVM_GET_SREGS, sregs)  0)
+   die(KVM_GET_SREGS failed);
+
+   sregs.u.s.sdr1 = vcpu-kvm-sdr1;
+
+   if (ioctl(vcpu-vcpu_fd, KVM_SET_SREGS, sregs)  0)
+   die(KVM_SET_SREGS failed);
+
+   reg.id = KVM_ONE_REG_PPC_HIOR;
+   reg.u.reg64 = 0;
+   if (ioctl(vcpu-vcpu_fd, KVM_SET_ONE_REG, reg)  0)
+   die(KVM_SET_ONE_REG failed);
 }
 
 /**
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 58982ff..8bd1fe2 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -72,19 +72,24 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 {
int cap_ppc_rma;
+   unsigned long hpt;
 
kvm-ram_size   = ram_size;
 
/*
-* Currently, we must map from hugetlbfs; if --hugetlbfs not specified,
-* try a default path:
+* Currently, HV-mode PPC64 SPAPR requires that we map from hugetlfs.
+* Allow a 'default' option to assist.
+* PR-mode does not require this.
 */
-   if (!hugetlbfs_path) {
-   hugetlbfs_path = HUGETLBFS_PATH;
-   pr_info(Using default %s for memory, hugetlbfs_path);
+   if (hugetlbfs_path) {
+   if (!strcmp(hugetlbfs_path, default))
+   hugetlbfs_path = HUGETLBFS_PATH;
+   kvm-ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm-ram_size);
+   } else {
+   kvm-ram_start = mmap(0, kvm-ram_size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE,
+ -1, 0);
}
-
-   kvm-ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm-ram_size);
if (kvm-ram_start == MAP_FAILED)
die(Couldn't map %lld bytes for RAM (%d)\n,
kvm-ram_size, errno);
@@ -95,6 +100,12 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
kvm-rtas_gra = kvm-fdt_gra - RTAS_MAX_SIZE;
madvise(kvm-ram_start, kvm-ram_size, MADV_MERGEABLE);
 
+   /* FIXME:  SPAPR-PR specific; allocate a guest HPT. */
+   if (posix_memalign((void **)hpt, (1HPT_ORDER), (1HPT_ORDER)))
+   die(Can't allocate %d bytes for HPT\n, (1HPT_ORDER));
+
+   kvm-sdr1 = ((hpt + 0x3ULL)  ~0x3ULL) | (HPT_ORDER-18);
+
/* FIXME: This is book3s-specific */
cap_ppc_rma = ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_PPC_RMA

[PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree

2012-01-30 Thread Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which
subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.

The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism
is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs.
Future support of more CPUs is possible.

libfdt is included from scripts/dtc/libfdt.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |   26 -
 tools/kvm/powerpc/cpu_info.c |   83 
 tools/kvm/powerpc/cpu_info.h |   43 
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   11 ++
 tools/kvm/powerpc/kvm-cpu.c  |1 +
 tools/kvm/powerpc/kvm.c  |  154 +-
 6 files changed, 312 insertions(+), 6 deletions(-)
 create mode 100644 tools/kvm/powerpc/cpu_info.c
 create mode 100644 tools/kvm/powerpc/cpu_info.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index e3250a9..917fe97 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -105,6 +105,8 @@ ifeq ($(uname_M),x86_64)
DEFINES  += -DCONFIG_X86_64
 endif
 
+LIBFDT_SRC = fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o
+LIBFDT_OBJS = $(patsubst %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
 
 ### Arch-specific stuff
 
@@ -130,9 +132,14 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
+   OBJS+= powerpc/cpu_info.o
OBJS+= powerpc/kvm-cpu.o
+# We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
+# so just build it in:
+   CFLAGS  += -I../../scripts/dtc/libfdt
+   OBJS+= $(LIBFDT_OBJS)
ARCH_INCLUDE := powerpc/include
-   CFLAGS += -m64
+   CFLAGS  += -m64
 endif
 
 ###
@@ -198,10 +205,6 @@ DEFINES+= -DBUILD_ARCH='$(ARCH)'
 KVM_INCLUDE := include
 CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 
-fno-strict-aliasing -g
 
-ifneq ($(WERROR),0)
-   WARNINGS += -Werror
-endif
-
 WARNINGS += -Wall
 WARNINGS += -Wcast-align
 WARNINGS += -Wformat=2
@@ -220,6 +223,13 @@ WARNINGS += -Wwrite-strings
 
 CFLAGS += $(WARNINGS)
 
+# Some targets may use 'external' sources that don't build totally cleanly.
+CFLAGS_EASYGOING := $(CFLAGS)
+
+ifneq ($(WERROR),0)
+   CFLAGS += -Werror
+endif
+
 all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) 
$(GUEST_INIT_S2)
 
 arch_support_check:
@@ -262,6 +272,12 @@ builtin-help.d: $(KVM_INCLUDE)/common-cmds.h
 
 $(OBJS):
 
+# This rule relaxes the -Werror on libfdt, since for now it still has
+# a bunch of warnings. :(
+../../scripts/dtc/libfdt/%.o: ../../scripts/dtc/libfdt/%.c
+   $(E)   CC   $@
+   $(Q) $(CC) -c $(CFLAGS_EASYGOING) $ -o $@
+
 util/rbtree.o: ../../lib/rbtree.c
$(E)   CC   $@
$(Q) $(CC) -c $(CFLAGS) $ -o $@
diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
new file mode 100644
index 000..c364b74
--- /dev/null
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -0,0 +1,83 @@
+/*
+ * PPC CPU identification
+ *
+ * This is a very simple host CPU info struct to get us going.
+ * For the little host information we need, I don't want to grub about
+ * parsing stuff in /proc/device-tree so just match host PVR to differentiate
+ * PPC970 and POWER7 (which is all that's currently supported).
+ *
+ * Qemu does something similar but this is MUCH simpler!
+ *
+ * Copyright 2012 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include cpu_info.h
+#include kvm/util.h
+
+/* POWER7 */
+
+/*
+ * Basic set of pages for POWER7.  It actually supports more but there were 
some
+ * limitations as to which may be advertised to the guest.  FIXME when this
+ * settles down -- for now use basic set:
+ */
+static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 
0x1, 0x18, 0x0};
+/* POWER7 has 1T segments, so advertise these */
+static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0x, 0x};
+
+static struct cpu_info cpu_power7_info = {
+   POWER7,
+   power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
+   power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
+   32, /* SLB size */
+   51200,  /* TB frequency */
+   128,/* d-cache block size */
+   128,/* i-cache block size */
+   CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
+};
+
+/* PPC970/G5 */
+
+static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 
0x18, 0x0};
+
+static struct cpu_info cpu_970_info = {
+   G5,
+   g5_page_sizes_prop, sizeof(g5_page_sizes_prop

[PATCH V4 4/7] kvm tools: Add SPAPR PPC64 HV console

2012-01-30 Thread Matt Evans
This adds the console code, plus VIO HV terminal nodes are added to
the device tree so the guest kernel will pick it up.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/kvm.c  |   33 
 tools/kvm/powerpc/spapr_hvcons.c |  102 ++
 tools/kvm/powerpc/spapr_hvcons.h |   19 +++
 4 files changed, 155 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index f6a8ac2..648550a 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -136,6 +136,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm-cpu.o
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
+   OBJS+= powerpc/spapr_hvcons.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 891fa65..bb98c10 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -17,6 +17,7 @@
 #include cpu_info.h
 
 #include spapr.h
+#include spapr_hvcons.h
 
 #include linux/kvm.h
 
@@ -133,6 +134,8 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
/* FIXME: SPAPR-specific */
hypercall_init();
register_core_rtas();
+   /* Now that hypercalls are initialised, register a couple for the 
console: */
+   spapr_hvcons_init();
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)
@@ -151,6 +154,12 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
kvm__irq_line(kvm, irq, 0);
 }
 
+void kvm__arch_periodic_poll(struct kvm *kvm)
+{
+   /* FIXME: Should register callbacks to platform-specific polls */
+   spapr_hvcons_poll(kvm);
+}
+
 int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline)
 {
void *p;
@@ -266,6 +275,13 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property(fdt, linux,initrd-end,
   ird_end_prop, sizeof(ird_end_prop)));
}
+
+   /*
+* stdout-path: This is assuming we're using the HV console.  Also, the
+* address is hardwired until we do a VIO bus.
+*/
+   _FDT(fdt_property_string(fdt, linux,stdout-path,
+/vdevice/vty@3000));
_FDT(fdt_end_node(fdt));
 
/*
@@ -352,6 +368,23 @@ static void setup_fdt(struct kvm *kvm)
}
_FDT(fdt_end_node(fdt));
 
+   /*
+* VIO: See comment in linux,stdout-path; we don't yet represent a VIO
+* bus/address allocation so addresses are hardwired here.
+*/
+   _FDT(fdt_begin_node(fdt, vdevice));
+   _FDT(fdt_property_cell(fdt, #address-cells, 0x1));
+   _FDT(fdt_property_cell(fdt, #size-cells, 0x0));
+   _FDT(fdt_property_string(fdt, device_type, vdevice));
+   _FDT(fdt_property_string(fdt, compatible, IBM,vdevice));
+   _FDT(fdt_begin_node(fdt, vty@3000));
+   _FDT(fdt_property_string(fdt, name, vty));
+   _FDT(fdt_property_string(fdt, device_type, serial));
+   _FDT(fdt_property_string(fdt, compatible, hvterm1));
+   _FDT(fdt_property_cell(fdt, reg, 0x3000));
+   _FDT(fdt_end_node(fdt));
+   _FDT(fdt_end_node(fdt));
+
/* Finalise: */
_FDT(fdt_end_node(fdt)); /* Root node */
_FDT(fdt_finish(fdt));
diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c
new file mode 100644
index 000..511dbe1
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_hvcons.c
@@ -0,0 +1,102 @@
+/*
+ * SPAPR HV console
+ *
+ * Borrowed lightly from QEMU's spapr_vty.c, Copyright (c) 2010 David Gibson,
+ * IBM Corporation.
+ *
+ * Copyright (c) 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include kvm/term.h
+#include kvm/kvm.h
+#include kvm/kvm-cpu.h
+#include kvm/util.h
+#include spapr.h
+#include spapr_hvcons.h
+
+#include stdio.h
+#include sys/uio.h
+#include errno.h
+
+#include linux/byteorder.h
+
+union hv_chario {
+   struct {
+   uint64_t char0_7;
+   uint64_t char8_15;
+   } a;
+   uint8_t buf[16];
+};
+
+static unsigned long h_put_term_char(struct kvm_cpu *vcpu, unsigned long 
opcode, unsigned long *args)
+{
+   /* To do: Read register from args[0], and check it. */
+   unsigned long len = args[1];
+   union hv_chario data;
+   struct iovec iov;
+
+   if (len  16) {
+   return H_PARAMETER;
+   }
+   data.a.char0_7 = cpu_to_be64(args[2]);
+   data.a.char8_15 = cpu_to_be64(args[3]);
+
+   iov.iov_base

[PATCH V4 7/7] kvm tools: Add PPC64 kvm_cpu__emulate_io()

2012-01-30 Thread Matt Evans
This is the final piece of the puzzle for PPC SPAPR PCI; this
function splits MMIO accesses into the two PHB windows  directs
things to MMIO/IO emulation as appropriate.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   10 +-
 tools/kvm/powerpc/kvm-cpu.c  |   22 ++
 3 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 2d97b66..332b374 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/spapr_pci.o
OBJS+= powerpc/xics.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index c1c6539..7520c04 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -14,7 +14,7 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include stdbool.h
 #include pthread.h
 
 #define MSR_SF (1UL63)
@@ -65,4 +65,12 @@ struct kvm_cpu {
 
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level);
 
+/* This is never actually called on PPC. */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return false;
+}
+
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write);
+
 #endif /* KVM__KVM_CPU_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 7dd1679..2505c69 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -15,6 +15,7 @@
 #include kvm/kvm.h
 
 #include spapr.h
+#include spapr_pci.h
 #include xics.h
 
 #include sys/ioctl.h
@@ -24,6 +25,7 @@
 #include string.h
 #include errno.h
 #include stdio.h
+#include assert.h
 
 static int debug_fd;
 
@@ -192,6 +194,26 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
return ret;
 }
 
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write)
+{
+   /*
+* FIXME: This function will need to be split in order to support
+* various PowerPC platforms/PHB types, etc.  It currently assumes SPAPR
+* PPC64 guest.
+*/
+   bool ret = false;
+
+   if ((phys_addr = SPAPR_PCI_WIN_START) 
+   (phys_addr  SPAPR_PCI_WIN_END)) {
+   ret = spapr_phb_mmio(kvm, phys_addr, data, len, is_write);
+   } else {
+   pr_warning(MMIO %s unknown address %llx (size %d)!\n,
+  is_write ? write to : read from,
+  phys_addr, len);
+   }
+   return ret;
+}
+
 #define CONDSTR_BIT(m, b) (((m)  MSR_##b) ? #b  : )
 
 void kvm_cpu__show_registers(struct kvm_cpu *vcpu)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V4 3/7] kvm tools: Add SPAPR PPC64 hcall rtascall structure

2012-01-30 Thread Matt Evans
This patch adds the basic structure for HV calls, their registration and some of
the simpler calls.  A similar layout for RTAS calls is also added, again with
some of the simpler RTAS calls used by the guest.  The SPAPR RTAS stub is
generated inline.  Also, nodes for RTAS are added to the device tree.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile  |2 +
 tools/kvm/powerpc/kvm-cpu.c |6 +
 tools/kvm/powerpc/kvm.c |   41 +++-
 tools/kvm/powerpc/spapr.h   |   84 ++
 tools/kvm/powerpc/spapr_hcall.c |  134 +++
 tools/kvm/powerpc/spapr_rtas.c  |  229 +++
 6 files changed, 495 insertions(+), 1 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 917fe97..f6a8ac2 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -134,6 +134,8 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm.o
OBJS+= powerpc/cpu_info.o
OBJS+= powerpc/kvm-cpu.o
+   OBJS+= powerpc/spapr_hcall.o
+   OBJS+= powerpc/spapr_rtas.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index a2beaac..51bb718 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -14,6 +14,8 @@
 #include kvm/util.h
 #include kvm/kvm.h
 
+#include spapr.h
+
 #include sys/ioctl.h
 #include sys/mman.h
 #include signal.h
@@ -169,6 +171,10 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
bool ret = true;
struct kvm_run *run = vcpu-kvm_run;
switch(run-exit_reason) {
+   case KVM_EXIT_PAPR_HCALL:
+   run-papr_hcall.ret = spapr_hypercall(vcpu, run-papr_hcall.nr,
+ 
(target_ulong*)run-papr_hcall.args);
+   break;
default:
ret = false;
}
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 842af37..891fa65 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -16,6 +16,8 @@
 #include libfdt.h
 #include cpu_info.h
 
+#include spapr.h
+
 #include linux/kvm.h
 
 #include sys/types.h
@@ -126,6 +128,11 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
if (cap_ppc_rma == 2)
die(Need contiguous RMA allocation on this hardware, 
which is not yet supported.);
+
+   /* Do these before FDT setup, IRQ setup, etc. */
+   /* FIXME: SPAPR-specific */
+   hypercall_init();
+   register_core_rtas();
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)
@@ -231,6 +238,20 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property_cell(fdt, #address-cells, 0x2));
_FDT(fdt_property_cell(fdt, #size-cells, 0x2));
 
+   /* RTAS */
+   _FDT(fdt_begin_node(fdt, rtas));
+   /* This is what the kernel uses to switch 'We're an LPAR'! */
+_FDT(fdt_property(fdt, ibm,hypertas-functions, hypertas_prop_kvm,
+   sizeof(hypertas_prop_kvm)));
+   _FDT(fdt_property_cell(fdt, linux,rtas-base, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, linux,rtas-entry, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, rtas-size, kvm-rtas_size));
+   /* Now add properties for all RTAS tokens: */
+   if (spapr_rtas_fdt_setup(kvm, fdt))
+   die(Couldn't create RTAS FDT properties\n);
+
+   _FDT(fdt_end_node(fdt));
+
/* /chosen */
_FDT(fdt_begin_node(fdt, chosen));
/* cmdline */
@@ -345,7 +366,25 @@ static void setup_fdt(struct kvm *kvm)
  */
 int kvm__arch_setup_firmware(struct kvm *kvm)
 {
-   /* Load RTAS */
+   /*
+* Set up RTAS stub.  All it is is a single hypercall:
+*  0:   7c 64 1b 78 mr  r4,r3
+*  4:   3c 60 00 00 lis r3,0
+*  8:   60 63 f0 00 ori r3,r3,61440
+*  c:   44 00 00 22 sc  1
+* 10:   4e 80 00 20 blr
+*/
+   uint32_t *rtas = guest_flat_to_host(kvm, kvm-rtas_gra);
+
+   rtas[0] = 0x7c641b78;
+   rtas[1] = 0x3c60;
+   rtas[2] = 0x6063f000;
+   rtas[3] = 0x4422;
+   rtas[4] = 0x4e800020;
+   kvm-rtas_size = 20;
+
+   pr_info(Set up %ld bytes of RTAS at 0x%lx\n,
+   kvm-rtas_size, kvm-rtas_gra);
 
/* Load SLOF */
 
diff --git a/tools/kvm/powerpc/spapr.h b/tools/kvm/powerpc/spapr.h
new file mode 100644
index 000..1271daa
--- /dev/null
+++ b/tools/kvm/powerpc/spapr.h
@@ -0,0 +1,84 @@
+/*
+ * SPAPR definitions and declarations
+ *
+ * Borrowed heavily from QEMU's spapr.h,
+ * Copyright (c) 2010 David Gibson, IBM Corporation.
+ *
+ * Modifications by Matt Evans m

[PATCH V4 6/7] kvm tools: Add PPC64 PCI Host Bridge

2012-01-30 Thread Matt Evans
This provides the PCI bridge, definitions for the address layout of the windows
and wires in IRQs.  Once PCI devices are all registered, they are enumerated and
DT nodes generated for each.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/powerpc/include/kvm/kvm-arch.h |3 +
 tools/kvm/powerpc/irq.c  |   18 ++-
 tools/kvm/powerpc/kvm.c  |   11 +
 tools/kvm/powerpc/spapr.h|9 +
 tools/kvm/powerpc/spapr_pci.c|  423 ++
 tools/kvm/powerpc/spapr_pci.h|   57 
 6 files changed, 519 insertions(+), 2 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h

diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 7235067..6dd7082 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -40,6 +40,8 @@
  */
 #define KVM_PCI_MMIO_AREA  0x100
 
+struct spapr_phb;
+
 struct kvm {
int sys_fd; /* For system ioctls(), i.e. 
/dev/kvm */
int vm_fd;  /* For VM ioctls() */
@@ -70,6 +72,7 @@ struct kvm {
const char  *name;
int vm_state;
struct icp_state*icp;
+   struct spapr_phb*phb;
 };
 
 /* Helper for the various bits of code that generate FDT nodes */
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index f8f12e5..7da4012 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -21,7 +21,10 @@
 #include stddef.h
 #include stdlib.h
 
+#include kvm/pci.h
+
 #include xics.h
+#include spapr_pci.h
 
 #define XICS_IRQS   1024
 
@@ -30,10 +33,21 @@
  * generic  cope with multiple PPC platform types.
  */
 
+static int pci_devs = 0;
+
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
-   fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
-   dev, *num, *pin, *line);
+   if (pci_devs = PCI_MAX_DEVICES)
+   die(Hit PCI device limit!\n);
+
+   *num = pci_devs++;
+
+   *pin = 1;
+   /*
+* Have I said how nasty I find this?  Line should be dontcare... PHB
+* should determine which CPU/XICS IRQ to fire.
+*/
+   *line = xics_alloc_irqnum();
return 0;
 }
 
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 815108c..cbc0d8f 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -18,6 +18,7 @@
 
 #include spapr.h
 #include spapr_hvcons.h
+#include spapr_pci.h
 
 #include linux/kvm.h
 
@@ -140,6 +141,11 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
register_core_rtas();
/* Now that hypercalls are initialised, register a couple for the 
console: */
spapr_hvcons_init();
+   spapr_create_phb(kvm, pci, SPAPR_PCI_BUID,
+SPAPR_PCI_MEM_WIN_ADDR,
+SPAPR_PCI_MEM_WIN_SIZE,
+SPAPR_PCI_IO_WIN_ADDR,
+SPAPR_PCI_IO_WIN_SIZE);
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)
@@ -406,6 +412,11 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_finish(fdt));
 
_FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE));
+
+   /* PCI */
+   if (spapr_populate_pci_devices(kvm, PHANDLE_XICP, fdt_dest))
+   die(Fail populating PCI device nodes);
+
_FDT(fdt_add_mem_rsv(fdt_dest, kvm-rtas_gra, kvm-rtas_size));
_FDT(fdt_pack(fdt_dest));
 }
diff --git a/tools/kvm/powerpc/spapr.h b/tools/kvm/powerpc/spapr.h
index 1271daa..0537f88 100644
--- a/tools/kvm/powerpc/spapr.h
+++ b/tools/kvm/powerpc/spapr.h
@@ -81,4 +81,13 @@ target_ulong spapr_rtas_call(struct kvm_cpu *vcpu,
  uint32_t token, uint32_t nargs, target_ulong args,
  uint32_t nret, target_ulong rets);
 
+#define SPAPR_PCI_BUID  0x8002001ULL
+#define SPAPR_PCI_MEM_WIN_ADDR  (KVM_MMIO_START + 0xA000)
+#define SPAPR_PCI_MEM_WIN_SIZE  0x2000
+#define SPAPR_PCI_IO_WIN_ADDR   (SPAPR_PCI_MEM_WIN_ADDR + 
SPAPR_PCI_MEM_WIN_SIZE)
+#define SPAPR_PCI_IO_WIN_SIZE  0x200
+
+#define SPAPR_PCI_WIN_STARTSPAPR_PCI_MEM_WIN_ADDR
+#define SPAPR_PCI_WIN_END  (SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)
+
 #endif /* !defined (__HW_SPAPR_H__) */
diff --git a/tools/kvm/powerpc/spapr_pci.c b/tools/kvm/powerpc/spapr_pci.c
new file mode 100644
index 000..f9d29f0
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_pci.c
@@ -0,0 +1,423 @@
+/*
+ * SPAPR PHB emulation, RTAS interface to PCI config space, device tree nodes
+ * for enumerated devices.
+ *
+ * Borrowed heavily from QEMU's spapr_pci.c,
+ * Copyright (c) 2011 Alexey Kardashevskiy, IBM Corporation.
+ * Copyright (c) 2011 David Gibson, IBM Corporation.
+ *
+ * Modifications copyright 2011 Matt

[PATCH V4 5/7] kvm tools: Add PPC64 XICS interrupt controller support

2012-01-30 Thread Matt Evans
This patch adds XICS emulation code (heavily borrowed from QEMU), and wires
this into kvm_cpu__irq() to fire a CPU IRQ via KVM.  A device tree entry is
also added.  IPIs work, xics_alloc_irqnum() is added to allocate an external
IRQ (which will later be used by the PHB PCI code) and finally, kvm__irq_line()
can be called to raise an IRQ on XICS.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |2 +
 tools/kvm/powerpc/irq.c  |   25 ++-
 tools/kvm/powerpc/kvm-cpu.c  |   11 +
 tools/kvm/powerpc/kvm.c  |   26 +-
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 8 files changed, 596 insertions(+), 7 deletions(-)
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 648550a..2d97b66 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/xics.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index ca15500..7235067 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -69,6 +69,7 @@ struct kvm {
unsigned long   initrd_size;
const char  *name;
int vm_state;
+   struct icp_state*icp;
 };
 
 /* Helper for the various bits of code that generate FDT nodes */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index 64e4510..c1c6539 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -36,6 +36,8 @@
 #define MSR_RI (1UL1)
 #define MSR_LE (1UL0)
 
+#define POWER7_EXT_IRQ 0
+
 struct kvm;
 
 struct kvm_cpu {
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index 46aa64f..f8f12e5 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -21,6 +21,15 @@
 #include stddef.h
 #include stdlib.h
 
+#include xics.h
+
+#define XICS_IRQS   1024
+
+/*
+ * FIXME: The code in this file assumes an SPAPR guest, using XICS.  Make
+ * generic  cope with multiple PPC platform types.
+ */
+
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
@@ -28,9 +37,21 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
return 0;
 }
 
-void irq__init(struct kvm *kvm)
+int irq__init(struct kvm *kvm)
 {
-   fprintf(stderr, __func__);
+   /*
+* kvm-nr_cpus is now valid; for /now/, pass
+* this to xics_system_init(), which assumes servers
+* are numbered 0..nrcpus.  This may not really be true,
+* but it is OK currently.
+*/
+   kvm-icp = xics_system_init(XICS_IRQS, kvm-nrcpus);
+   return 0;
+}
+
+int irq__exit(struct kvm *kvm)
+{
+   return 0;
 }
 
 int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 51bb718..7dd1679 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -15,6 +15,7 @@
 #include kvm/kvm.h
 
 #include spapr.h
+#include xics.h
 
 #include sys/ioctl.h
 #include sys/mman.h
@@ -90,6 +91,9 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long 
cpu_id)
 */
vcpu-is_running = true;
 
+   /* Register with IRQ controller (FIXME, assumes XICS) */
+   xics_cpu_register(vcpu);
+
return vcpu;
 }
 
@@ -160,6 +164,13 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)
 /* kvm_cpu__irq - set KVM's IRQ flag on this vcpu */
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level)
 {
+   unsigned int virq = level ? KVM_INTERRUPT_SET_LEVEL : 
KVM_INTERRUPT_UNSET;
+
+   /* FIXME: POWER-specific */
+   if (pin != POWER7_EXT_IRQ)
+   return;
+   if (ioctl(vcpu-vcpu_fd, KVM_INTERRUPT, virq)  0)
+   pr_warning(Could not KVM_INTERRUPT.);
 }
 
 void kvm_cpu__arch_nmi(struct kvm_cpu *cpu)
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index bb98c10..815108c 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -39,9 +39,13 @@
 
 #define HUGETLBFS_PATH /var/lib/hugetlbfs/global/pagesize-16MB/
 
+#define PHANDLE_XICP   0x
+
 static char kern_cmdline[2048];
 
 struct kvm_ext kvm_req_ext

[PATCH] KVM: PPC: Book3s: PR: Add SPAPR H_BULK_REMOVE support

2012-01-30 Thread Matt Evans
SPAPR support includes various in-kernel hypercalls, improving performance
by cutting out the exit to userspace.  H_BULK_REMOVE is implemented in this
patch.

Signed-off-by: Matt Evans m...@ozlabs.org
---

Alex, my zomg, ls SIGILLs! on IRC was due to a former broken version of
  this patch skipping an invalidation or two...  Works well now.  ;)

 arch/powerpc/kvm/book3s_pr_papr.c |   82 +++--
 1 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_pr_papr.c 
b/arch/powerpc/kvm/book3s_pr_papr.c
index b958932..6d1bfe2 100644
--- a/arch/powerpc/kvm/book3s_pr_papr.c
+++ b/arch/powerpc/kvm/book3s_pr_papr.c
@@ -98,6 +98,83 @@ static int kvmppc_h_pr_remove(struct kvm_vcpu *vcpu)
return EMULATE_DONE;
 }
 
+/* Request defs for kvmppc_h_pr_bulk_remove() */
+#define H_BULK_REMOVE_TYPE 0xc000ULL
+#define   H_BULK_REMOVE_REQUEST0x4000ULL
+#define   H_BULK_REMOVE_RESPONSE   0x8000ULL
+#define   H_BULK_REMOVE_END0xc000ULL
+#define H_BULK_REMOVE_CODE 0x3000ULL
+#define   H_BULK_REMOVE_SUCCESS0xULL
+#define   H_BULK_REMOVE_NOT_FOUND  0x1000ULL
+#define   H_BULK_REMOVE_PARM   0x2000ULL
+#define   H_BULK_REMOVE_HW 0x3000ULL
+#define H_BULK_REMOVE_RC   0x0c00ULL
+#define H_BULK_REMOVE_FLAGS0x0300ULL
+#define   H_BULK_REMOVE_ABSOLUTE   0xULL
+#define   H_BULK_REMOVE_ANDCOND0x0100ULL
+#define   H_BULK_REMOVE_AVPN   0x0200ULL
+#define H_BULK_REMOVE_PTEX 0x00ffULL
+#define H_BULK_REMOVE_MAX_BATCH4
+
+static int kvmppc_h_pr_bulk_remove(struct kvm_vcpu *vcpu)
+{
+   int i;
+   int paramnr = 4;
+   int ret = H_SUCCESS;
+
+   for (i = 0; i  H_BULK_REMOVE_MAX_BATCH; i++) {
+   unsigned long tsh = kvmppc_get_gpr(vcpu, paramnr+(2*i));
+   unsigned long tsl = kvmppc_get_gpr(vcpu, paramnr+(2*i)+1);
+   unsigned long pteg, rb, flags;
+   unsigned long pte[2];
+   unsigned long v = 0;
+
+   if ((tsh  H_BULK_REMOVE_TYPE) == H_BULK_REMOVE_END) {
+   break; /* Exit success */
+   } else if ((tsh  H_BULK_REMOVE_TYPE) !=
+  H_BULK_REMOVE_REQUEST) {
+   ret = H_PARAMETER;
+   break; /* Exit fail */
+   }
+
+   tsh = H_BULK_REMOVE_PTEX | H_BULK_REMOVE_FLAGS;
+   tsh |= H_BULK_REMOVE_RESPONSE;
+
+   if ((tsh  H_BULK_REMOVE_ANDCOND) 
+   (tsh  H_BULK_REMOVE_AVPN)) {
+   tsh |= H_BULK_REMOVE_PARM;
+   kvmppc_set_gpr(vcpu, paramnr+(2*i), tsh);
+   ret = H_PARAMETER;
+   break; /* Exit fail */
+   }
+
+   pteg = get_pteg_addr(vcpu, tsh  H_BULK_REMOVE_PTEX);
+   copy_from_user(pte, (void __user *)pteg, sizeof(pte));
+
+   /* tsl = AVPN */
+   flags = (tsh  H_BULK_REMOVE_FLAGS)  26;
+
+   if ((pte[0]  HPTE_V_VALID) == 0 ||
+   ((flags  H_AVPN)  (pte[0]  ~0x7fUL) != tsl) ||
+   ((flags  H_ANDCOND)  (pte[0]  tsl) != 0)) {
+   tsh |= H_BULK_REMOVE_NOT_FOUND;
+   } else {
+   /* Splat the pteg in (userland) hpt */
+   copy_to_user((void __user *)pteg, v, sizeof(v));
+
+   rb = compute_tlbie_rb(pte[0], pte[1],
+ tsh  H_BULK_REMOVE_PTEX);
+   vcpu-arch.mmu.tlbie(vcpu, rb, rb  1 ? true : false);
+   tsh |= H_BULK_REMOVE_SUCCESS;
+   tsh |= (pte[1]  (HPTE_R_C | HPTE_R_R))  43;
+   }
+   kvmppc_set_gpr(vcpu, paramnr+(2*i), tsh);
+   }
+   kvmppc_set_gpr(vcpu, 3, ret);
+
+   return EMULATE_DONE;
+}
+
 static int kvmppc_h_pr_protect(struct kvm_vcpu *vcpu)
 {
unsigned long flags = kvmppc_get_gpr(vcpu, 4);
@@ -144,10 +221,7 @@ int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd)
case H_PROTECT:
return kvmppc_h_pr_protect(vcpu);
case H_BULK_REMOVE:
-   /* We just flush all PTEs, so user space can
-  handle the HPT modifications */
-   kvmppc_mmu_pte_flush(vcpu, 0, 0);
-   break;
+   return kvmppc_h_pr_bulk_remove(vcpu);
case H_CEDE:
kvm_vcpu_block(vcpu);
vcpu-stat.halt_wakeup++;
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo

[PATCH V4 0/7] Add initial SPAPR PPC64 architecture support

2012-01-30 Thread Matt Evans
This series adds support for a PPC64 platform, SPAPR, on top of the previous
more general PPC64 CPU support.  This platform is paravirtualised, with most
of the MMU hypercalls being dealt with in the kernel.  Userland needs to
describe the environment to the machine with a device tree, cope with some
hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate
the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque
machine.

With this series, normal pSeries kernels boot fine (including RH kernels that
include virtio support out of the box).  There is no support for PPC32 or
'bare metal' PPC64 guests as yet.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

The kernels are loaded as flat binaries and booted directly.  The intention
is to later support loading firmware such as SLOF.

Some of the code within is borrowed/based upon code in QEMU, particularly
the XICS emulation, device tree construction and PCI setup.

-- Changes since V3:
   - Gained another patch to provide PPC KVM-PR support (widens userbase :p )
 This allocates a page table, sets up a few more regs etc.  Also,
 removes restriction that mandates use of hugepages.
 Requires KVM-PR to implement H_BULK_REMOVE (separate patch)
   - Cleaned up FDT generation to detect host CPU  generate based
 on its properties; now supports PPC970 as well as POWER7
   - Removed redefinition of hypercall #defines, using asm/hvcall.h instead
   - More sensible MMIO layering; CPU passes MMIO to PHB, PHB then decides
 which PCI window is accessed.
   - Die if kernel-handled hypercalls ever get to userland
   - Build in libfdt as sugggested -- it's small and present in our sourcetree,
 and removes external dependency on 64bit libfdt (which isn't in some
 distros).
   - Spit  polish

Thanks to David  Alex for the PPC-related reviews!

Matt Evans (7):
  kvm tools: PPC64, add HPT/SDR1 for -PR KVM
  kvm tools: Generate SPAPR PPC64 guest device tree
  kvm tools: Add SPAPR PPC64 hcall  rtascall structure
  kvm tools: Add SPAPR PPC64 HV console
  kvm tools: Add PPC64 XICS interrupt controller support
  kvm tools: Add PPC64 PCI Host Bridge
  kvm tools: Add PPC64 kvm_cpu__emulate_io()

 tools/kvm/Makefile   |   31 ++-
 tools/kvm/powerpc/cpu_info.c |   83 
 tools/kvm/powerpc/cpu_info.h |   43 +++
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   17 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   12 +-
 tools/kvm/powerpc/irq.c  |   43 ++-
 tools/kvm/powerpc/kvm-cpu.c  |   64 +++-
 tools/kvm/powerpc/kvm.c  |  290 ++-
 tools/kvm/powerpc/spapr.h|   93 +
 tools/kvm/powerpc/spapr_hcall.c  |  134 +++
 tools/kvm/powerpc/spapr_hvcons.c |  102 +
 tools/kvm/powerpc/spapr_hvcons.h |   19 +
 tools/kvm/powerpc/spapr_pci.c|  423 +
 tools/kvm/powerpc/spapr_pci.h|   57 +++
 tools/kvm/powerpc/spapr_rtas.c   |  229 
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 17 files changed, 2150 insertions(+), 27 deletions(-)
 create mode 100644 tools/kvm/powerpc/cpu_info.c
 create mode 100644 tools/kvm/powerpc/cpu_info.h
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V4 1/7] kvm tools: PPC64, add HPT/SDR1 for -PR KVM

2012-01-30 Thread Matt Evans
Allocate a page table and point SDR1 to it in order to support the -PR
PPC64 KVM mode.  (The alternative, -HV mode, is available only on a small
set of machines.)

This patch also removes the previous dependency on mapping guest RAM with
huge pages; PR KVM doesn't require them so the user isn't forced to use them.

A new option, '--hugetlbfs default', uses a default path for 16M pages for
HV mode, if required.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/powerpc/include/kvm/kvm-arch.h |2 ++
 tools/kvm/powerpc/kvm-cpu.c  |   24 +---
 tools/kvm/powerpc/kvm.c  |   25 ++---
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index c4b493c..8653871 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -52,6 +52,8 @@ struct kvm {
u64 ram_size;
void*ram_start;
 
+   u64 sdr1;
+
boolnmi_disabled;
 
boolsingle_step;
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index ea99666..60379d0 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -76,7 +76,8 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long 
cpu_id)
if (vcpu-kvm_run == MAP_FAILED)
die(unable to mmap vcpu fd);
 
-   ioctl(vcpu-vcpu_fd, KVM_ENABLE_CAP, papr_cap);
+   if (ioctl(vcpu-vcpu_fd, KVM_ENABLE_CAP, papr_cap)  0)
+   die(unable to enable PAPR capability);
 
/*
 * We start all CPUs, directing non-primary threads into the kernel's
@@ -121,9 +122,26 @@ static void kvm_cpu__setup_regs(struct kvm_cpu *vcpu)
 static void kvm_cpu__setup_sregs(struct kvm_cpu *vcpu)
 {
/*
-* No sregs setup is required on PPC64/SPAPR (but there may be setup
-* required for non-paravirtualised platforms, e.g. TLB/SLB setup).
+* Some sregs setup to initialise SDR1/PVR/HIOR on PPC64 SPAPR
+* platforms using PR KVM.  (Technically, this is all ignored on
+* SPAPR HV KVM.)  Different setup is required for non-PV non-SPAPR
+* platforms!  (FIXME.)
 */
+   struct kvm_sregs sregs;
+   struct kvm_one_reg reg = {};
+
+   if (ioctl(vcpu-vcpu_fd, KVM_GET_SREGS, sregs)  0)
+   die(KVM_GET_SREGS failed);
+
+   sregs.u.s.sdr1 = vcpu-kvm-sdr1;
+
+   if (ioctl(vcpu-vcpu_fd, KVM_SET_SREGS, sregs)  0)
+   die(KVM_SET_SREGS failed);
+
+   reg.id = KVM_ONE_REG_PPC_HIOR;
+   reg.u.reg64 = 0;
+   if (ioctl(vcpu-vcpu_fd, KVM_SET_ONE_REG, reg)  0)
+   die(KVM_SET_ONE_REG failed);
 }
 
 /**
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 58982ff..8bd1fe2 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -72,19 +72,24 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
 void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 {
int cap_ppc_rma;
+   unsigned long hpt;
 
kvm-ram_size   = ram_size;
 
/*
-* Currently, we must map from hugetlbfs; if --hugetlbfs not specified,
-* try a default path:
+* Currently, HV-mode PPC64 SPAPR requires that we map from hugetlfs.
+* Allow a 'default' option to assist.
+* PR-mode does not require this.
 */
-   if (!hugetlbfs_path) {
-   hugetlbfs_path = HUGETLBFS_PATH;
-   pr_info(Using default %s for memory, hugetlbfs_path);
+   if (hugetlbfs_path) {
+   if (!strcmp(hugetlbfs_path, default))
+   hugetlbfs_path = HUGETLBFS_PATH;
+   kvm-ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm-ram_size);
+   } else {
+   kvm-ram_start = mmap(0, kvm-ram_size, PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE,
+ -1, 0);
}
-
-   kvm-ram_start = mmap_hugetlbfs(hugetlbfs_path, kvm-ram_size);
if (kvm-ram_start == MAP_FAILED)
die(Couldn't map %lld bytes for RAM (%d)\n,
kvm-ram_size, errno);
@@ -95,6 +100,12 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
kvm-rtas_gra = kvm-fdt_gra - RTAS_MAX_SIZE;
madvise(kvm-ram_start, kvm-ram_size, MADV_MERGEABLE);
 
+   /* FIXME:  SPAPR-PR specific; allocate a guest HPT. */
+   if (posix_memalign((void **)hpt, (1HPT_ORDER), (1HPT_ORDER)))
+   die(Can't allocate %d bytes for HPT\n, (1HPT_ORDER));
+
+   kvm-sdr1 = ((hpt + 0x3ULL)  ~0x3ULL) | (HPT_ORDER-18);
+
/* FIXME: This is book3s-specific */
cap_ppc_rma = ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_PPC_RMA

[PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree

2012-01-30 Thread Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which
subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.

The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism
is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs.
Future support of more CPUs is possible.

libfdt is included from scripts/dtc/libfdt.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |   26 -
 tools/kvm/powerpc/cpu_info.c |   83 
 tools/kvm/powerpc/cpu_info.h |   43 
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   11 ++
 tools/kvm/powerpc/kvm-cpu.c  |1 +
 tools/kvm/powerpc/kvm.c  |  154 +-
 6 files changed, 312 insertions(+), 6 deletions(-)
 create mode 100644 tools/kvm/powerpc/cpu_info.c
 create mode 100644 tools/kvm/powerpc/cpu_info.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index e3250a9..917fe97 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -105,6 +105,8 @@ ifeq ($(uname_M),x86_64)
DEFINES  += -DCONFIG_X86_64
 endif
 
+LIBFDT_SRC = fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o
+LIBFDT_OBJS = $(patsubst %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC))
 
 ### Arch-specific stuff
 
@@ -130,9 +132,14 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
+   OBJS+= powerpc/cpu_info.o
OBJS+= powerpc/kvm-cpu.o
+# We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
+# so just build it in:
+   CFLAGS  += -I../../scripts/dtc/libfdt
+   OBJS+= $(LIBFDT_OBJS)
ARCH_INCLUDE := powerpc/include
-   CFLAGS += -m64
+   CFLAGS  += -m64
 endif
 
 ###
@@ -198,10 +205,6 @@ DEFINES+= -DBUILD_ARCH='$(ARCH)'
 KVM_INCLUDE := include
 CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 
-fno-strict-aliasing -g
 
-ifneq ($(WERROR),0)
-   WARNINGS += -Werror
-endif
-
 WARNINGS += -Wall
 WARNINGS += -Wcast-align
 WARNINGS += -Wformat=2
@@ -220,6 +223,13 @@ WARNINGS += -Wwrite-strings
 
 CFLAGS += $(WARNINGS)
 
+# Some targets may use 'external' sources that don't build totally cleanly.
+CFLAGS_EASYGOING := $(CFLAGS)
+
+ifneq ($(WERROR),0)
+   CFLAGS += -Werror
+endif
+
 all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) 
$(GUEST_INIT_S2)
 
 arch_support_check:
@@ -262,6 +272,12 @@ builtin-help.d: $(KVM_INCLUDE)/common-cmds.h
 
 $(OBJS):
 
+# This rule relaxes the -Werror on libfdt, since for now it still has
+# a bunch of warnings. :(
+../../scripts/dtc/libfdt/%.o: ../../scripts/dtc/libfdt/%.c
+   $(E)   CC   $@
+   $(Q) $(CC) -c $(CFLAGS_EASYGOING) $ -o $@
+
 util/rbtree.o: ../../lib/rbtree.c
$(E)   CC   $@
$(Q) $(CC) -c $(CFLAGS) $ -o $@
diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
new file mode 100644
index 000..c364b74
--- /dev/null
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -0,0 +1,83 @@
+/*
+ * PPC CPU identification
+ *
+ * This is a very simple host CPU info struct to get us going.
+ * For the little host information we need, I don't want to grub about
+ * parsing stuff in /proc/device-tree so just match host PVR to differentiate
+ * PPC970 and POWER7 (which is all that's currently supported).
+ *
+ * Qemu does something similar but this is MUCH simpler!
+ *
+ * Copyright 2012 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include cpu_info.h
+#include kvm/util.h
+
+/* POWER7 */
+
+/*
+ * Basic set of pages for POWER7.  It actually supports more but there were 
some
+ * limitations as to which may be advertised to the guest.  FIXME when this
+ * settles down -- for now use basic set:
+ */
+static u32 power7_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 
0x1, 0x18, 0x0};
+/* POWER7 has 1T segments, so advertise these */
+static u32 power7_segment_sizes_prop[] = {0x1c, 0x28, 0x, 0x};
+
+static struct cpu_info cpu_power7_info = {
+   POWER7,
+   power7_page_sizes_prop, sizeof(power7_page_sizes_prop),
+   power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop),
+   32, /* SLB size */
+   51200,  /* TB frequency */
+   128,/* d-cache block size */
+   128,/* i-cache block size */
+   CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX
+};
+
+/* PPC970/G5 */
+
+static u32 g5_page_sizes_prop[] = {0xc, 0x0, 0x1, 0xc, 0x0, 0x18, 0x100, 0x1, 
0x18, 0x0};
+
+static struct cpu_info cpu_970_info = {
+   G5,
+   g5_page_sizes_prop, sizeof(g5_page_sizes_prop

[PATCH V4 4/7] kvm tools: Add SPAPR PPC64 HV console

2012-01-30 Thread Matt Evans
This adds the console code, plus VIO HV terminal nodes are added to
the device tree so the guest kernel will pick it up.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/kvm.c  |   33 
 tools/kvm/powerpc/spapr_hvcons.c |  102 ++
 tools/kvm/powerpc/spapr_hvcons.h |   19 +++
 4 files changed, 155 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index f6a8ac2..648550a 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -136,6 +136,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm-cpu.o
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
+   OBJS+= powerpc/spapr_hvcons.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
CFLAGS  += -I../../scripts/dtc/libfdt
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 891fa65..bb98c10 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -17,6 +17,7 @@
 #include cpu_info.h
 
 #include spapr.h
+#include spapr_hvcons.h
 
 #include linux/kvm.h
 
@@ -133,6 +134,8 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
/* FIXME: SPAPR-specific */
hypercall_init();
register_core_rtas();
+   /* Now that hypercalls are initialised, register a couple for the 
console: */
+   spapr_hvcons_init();
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)
@@ -151,6 +154,12 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
kvm__irq_line(kvm, irq, 0);
 }
 
+void kvm__arch_periodic_poll(struct kvm *kvm)
+{
+   /* FIXME: Should register callbacks to platform-specific polls */
+   spapr_hvcons_poll(kvm);
+}
+
 int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline)
 {
void *p;
@@ -266,6 +275,13 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property(fdt, linux,initrd-end,
   ird_end_prop, sizeof(ird_end_prop)));
}
+
+   /*
+* stdout-path: This is assuming we're using the HV console.  Also, the
+* address is hardwired until we do a VIO bus.
+*/
+   _FDT(fdt_property_string(fdt, linux,stdout-path,
+/vdevice/vty@3000));
_FDT(fdt_end_node(fdt));
 
/*
@@ -352,6 +368,23 @@ static void setup_fdt(struct kvm *kvm)
}
_FDT(fdt_end_node(fdt));
 
+   /*
+* VIO: See comment in linux,stdout-path; we don't yet represent a VIO
+* bus/address allocation so addresses are hardwired here.
+*/
+   _FDT(fdt_begin_node(fdt, vdevice));
+   _FDT(fdt_property_cell(fdt, #address-cells, 0x1));
+   _FDT(fdt_property_cell(fdt, #size-cells, 0x0));
+   _FDT(fdt_property_string(fdt, device_type, vdevice));
+   _FDT(fdt_property_string(fdt, compatible, IBM,vdevice));
+   _FDT(fdt_begin_node(fdt, vty@3000));
+   _FDT(fdt_property_string(fdt, name, vty));
+   _FDT(fdt_property_string(fdt, device_type, serial));
+   _FDT(fdt_property_string(fdt, compatible, hvterm1));
+   _FDT(fdt_property_cell(fdt, reg, 0x3000));
+   _FDT(fdt_end_node(fdt));
+   _FDT(fdt_end_node(fdt));
+
/* Finalise: */
_FDT(fdt_end_node(fdt)); /* Root node */
_FDT(fdt_finish(fdt));
diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c
new file mode 100644
index 000..511dbe1
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_hvcons.c
@@ -0,0 +1,102 @@
+/*
+ * SPAPR HV console
+ *
+ * Borrowed lightly from QEMU's spapr_vty.c, Copyright (c) 2010 David Gibson,
+ * IBM Corporation.
+ *
+ * Copyright (c) 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include kvm/term.h
+#include kvm/kvm.h
+#include kvm/kvm-cpu.h
+#include kvm/util.h
+#include spapr.h
+#include spapr_hvcons.h
+
+#include stdio.h
+#include sys/uio.h
+#include errno.h
+
+#include linux/byteorder.h
+
+union hv_chario {
+   struct {
+   uint64_t char0_7;
+   uint64_t char8_15;
+   } a;
+   uint8_t buf[16];
+};
+
+static unsigned long h_put_term_char(struct kvm_cpu *vcpu, unsigned long 
opcode, unsigned long *args)
+{
+   /* To do: Read register from args[0], and check it. */
+   unsigned long len = args[1];
+   union hv_chario data;
+   struct iovec iov;
+
+   if (len  16) {
+   return H_PARAMETER;
+   }
+   data.a.char0_7 = cpu_to_be64(args[2]);
+   data.a.char8_15 = cpu_to_be64(args[3]);
+
+   iov.iov_base

[PATCH V4 7/7] kvm tools: Add PPC64 kvm_cpu__emulate_io()

2012-01-30 Thread Matt Evans
This is the final piece of the puzzle for PPC SPAPR PCI; this
function splits MMIO accesses into the two PHB windows  directs
things to MMIO/IO emulation as appropriate.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   10 +-
 tools/kvm/powerpc/kvm-cpu.c  |   22 ++
 3 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 2d97b66..332b374 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/spapr_pci.o
OBJS+= powerpc/xics.o
 # We use libfdt, but it's sometimes not packaged 64bit.  It's small too,
 # so just build it in:
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index c1c6539..7520c04 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -14,7 +14,7 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include stdbool.h
 #include pthread.h
 
 #define MSR_SF (1UL63)
@@ -65,4 +65,12 @@ struct kvm_cpu {
 
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level);
 
+/* This is never actually called on PPC. */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return false;
+}
+
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write);
+
 #endif /* KVM__KVM_CPU_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 7dd1679..2505c69 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -15,6 +15,7 @@
 #include kvm/kvm.h
 
 #include spapr.h
+#include spapr_pci.h
 #include xics.h
 
 #include sys/ioctl.h
@@ -24,6 +25,7 @@
 #include string.h
 #include errno.h
 #include stdio.h
+#include assert.h
 
 static int debug_fd;
 
@@ -192,6 +194,26 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
return ret;
 }
 
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write)
+{
+   /*
+* FIXME: This function will need to be split in order to support
+* various PowerPC platforms/PHB types, etc.  It currently assumes SPAPR
+* PPC64 guest.
+*/
+   bool ret = false;
+
+   if ((phys_addr = SPAPR_PCI_WIN_START) 
+   (phys_addr  SPAPR_PCI_WIN_END)) {
+   ret = spapr_phb_mmio(kvm, phys_addr, data, len, is_write);
+   } else {
+   pr_warning(MMIO %s unknown address %llx (size %d)!\n,
+  is_write ? write to : read from,
+  phys_addr, len);
+   }
+   return ret;
+}
+
 #define CONDSTR_BIT(m, b) (((m)  MSR_##b) ? #b  : )
 
 void kvm_cpu__show_registers(struct kvm_cpu *vcpu)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V4 6/7] kvm tools: Add PPC64 PCI Host Bridge

2012-01-30 Thread Matt Evans
This provides the PCI bridge, definitions for the address layout of the windows
and wires in IRQs.  Once PCI devices are all registered, they are enumerated and
DT nodes generated for each.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/powerpc/include/kvm/kvm-arch.h |3 +
 tools/kvm/powerpc/irq.c  |   18 ++-
 tools/kvm/powerpc/kvm.c  |   11 +
 tools/kvm/powerpc/spapr.h|9 +
 tools/kvm/powerpc/spapr_pci.c|  423 ++
 tools/kvm/powerpc/spapr_pci.h|   57 
 6 files changed, 519 insertions(+), 2 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h

diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 7235067..6dd7082 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -40,6 +40,8 @@
  */
 #define KVM_PCI_MMIO_AREA  0x100
 
+struct spapr_phb;
+
 struct kvm {
int sys_fd; /* For system ioctls(), i.e. 
/dev/kvm */
int vm_fd;  /* For VM ioctls() */
@@ -70,6 +72,7 @@ struct kvm {
const char  *name;
int vm_state;
struct icp_state*icp;
+   struct spapr_phb*phb;
 };
 
 /* Helper for the various bits of code that generate FDT nodes */
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index f8f12e5..7da4012 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -21,7 +21,10 @@
 #include stddef.h
 #include stdlib.h
 
+#include kvm/pci.h
+
 #include xics.h
+#include spapr_pci.h
 
 #define XICS_IRQS   1024
 
@@ -30,10 +33,21 @@
  * generic  cope with multiple PPC platform types.
  */
 
+static int pci_devs = 0;
+
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
-   fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
-   dev, *num, *pin, *line);
+   if (pci_devs = PCI_MAX_DEVICES)
+   die(Hit PCI device limit!\n);
+
+   *num = pci_devs++;
+
+   *pin = 1;
+   /*
+* Have I said how nasty I find this?  Line should be dontcare... PHB
+* should determine which CPU/XICS IRQ to fire.
+*/
+   *line = xics_alloc_irqnum();
return 0;
 }
 
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 815108c..cbc0d8f 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -18,6 +18,7 @@
 
 #include spapr.h
 #include spapr_hvcons.h
+#include spapr_pci.h
 
 #include linux/kvm.h
 
@@ -140,6 +141,11 @@ void kvm__arch_init(struct kvm *kvm, const char 
*hugetlbfs_path, u64 ram_size)
register_core_rtas();
/* Now that hypercalls are initialised, register a couple for the 
console: */
spapr_hvcons_init();
+   spapr_create_phb(kvm, pci, SPAPR_PCI_BUID,
+SPAPR_PCI_MEM_WIN_ADDR,
+SPAPR_PCI_MEM_WIN_SIZE,
+SPAPR_PCI_IO_WIN_ADDR,
+SPAPR_PCI_IO_WIN_SIZE);
 }
 
 void kvm__arch_delete_ram(struct kvm *kvm)
@@ -406,6 +412,11 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_finish(fdt));
 
_FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE));
+
+   /* PCI */
+   if (spapr_populate_pci_devices(kvm, PHANDLE_XICP, fdt_dest))
+   die(Fail populating PCI device nodes);
+
_FDT(fdt_add_mem_rsv(fdt_dest, kvm-rtas_gra, kvm-rtas_size));
_FDT(fdt_pack(fdt_dest));
 }
diff --git a/tools/kvm/powerpc/spapr.h b/tools/kvm/powerpc/spapr.h
index 1271daa..0537f88 100644
--- a/tools/kvm/powerpc/spapr.h
+++ b/tools/kvm/powerpc/spapr.h
@@ -81,4 +81,13 @@ target_ulong spapr_rtas_call(struct kvm_cpu *vcpu,
  uint32_t token, uint32_t nargs, target_ulong args,
  uint32_t nret, target_ulong rets);
 
+#define SPAPR_PCI_BUID  0x8002001ULL
+#define SPAPR_PCI_MEM_WIN_ADDR  (KVM_MMIO_START + 0xA000)
+#define SPAPR_PCI_MEM_WIN_SIZE  0x2000
+#define SPAPR_PCI_IO_WIN_ADDR   (SPAPR_PCI_MEM_WIN_ADDR + 
SPAPR_PCI_MEM_WIN_SIZE)
+#define SPAPR_PCI_IO_WIN_SIZE  0x200
+
+#define SPAPR_PCI_WIN_STARTSPAPR_PCI_MEM_WIN_ADDR
+#define SPAPR_PCI_WIN_END  (SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)
+
 #endif /* !defined (__HW_SPAPR_H__) */
diff --git a/tools/kvm/powerpc/spapr_pci.c b/tools/kvm/powerpc/spapr_pci.c
new file mode 100644
index 000..f9d29f0
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_pci.c
@@ -0,0 +1,423 @@
+/*
+ * SPAPR PHB emulation, RTAS interface to PCI config space, device tree nodes
+ * for enumerated devices.
+ *
+ * Borrowed heavily from QEMU's spapr_pci.c,
+ * Copyright (c) 2011 Alexey Kardashevskiy, IBM Corporation.
+ * Copyright (c) 2011 David Gibson, IBM Corporation.
+ *
+ * Modifications copyright 2011 Matt

Re: [PATCH V2] kvm tools: Add build target for statically-linked binary

2012-01-29 Thread Matt Evans
Hi Asias,


Remember this patch? :-)  I didn't... oops.

On 09/01/12 18:51, Asias He wrote:
 On 01/09/2012 02:45 PM, Matt Evans wrote:
 This commit adds a target for 'lkvm-static' which is linked -static.

 (This can be useful to construct kvmtool binaries for minimalist
 auto-test host filesystems.)
 
 This is useful. However, It fails to build for me. Some problem with
 sdl, bfd and vnc library. Log attached.

OK, so I've been building statically without the (autodetected) SDL/BFD/VNC
libraries, and this works fine on PPC64 and x86.

I'm not quite sure why the libSDL.a/libbfd.a etc. don't statically link.

Sasha's idea of disable things that don't link correctly is a good one, though
I'm not a Make guru and can't see how to retrospectively unset 'has_SDL',
'has_vncserver' etc. IFF the makefile target is lkvm-static :(

(I guess one way is to try to find every .o that depends on CONFIG_SDL, for
example, and add another target compiled without -DCONFIG_SDL :( Ew, and I don't
know how to do this.)

This would be easier if we had a proper config system..

In lieu of any good lightweight solutions, can we include this patch as it is
still useful for builds on systems without the offending optional libraries?


Cheers,


Matt


 

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---

 V2:  Argh!  Let's remove it on make clean, too...

  tools/kvm/Makefile |6 +-
  1 files changed, 5 insertions(+), 1 deletions(-)

 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index d54fa47..ebc0c7c 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -233,6 +233,10 @@ $(PROGRAM): $(DEPS) $(OBJS)
  $(E)   LINK $@
  $(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  
 +$(PROGRAM)-static: $(DEPS) $(OBJS)
 +$(E)   LINK $@
 +$(Q) $(CC) -static $(CFLAGS) $(OBJS) $(LIBS) -o $@
 +
  $(PROGRAM_ALIAS): $(PROGRAM)
  $(E)   LN   $@
  $(Q) ln -f $(PROGRAM) $@
 @@ -325,7 +329,7 @@ clean:
  $(Q) rm -f x86/bios/bios-rom.h
  $(Q) rm -f tests/boot/boot_test.iso
  $(Q) rm -rf tests/boot/rootfs/
 -$(Q) rm -f $(DEPS) $(OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) 
 $(GUEST_INIT_S2)
 +$(Q) rm -f $(DEPS) $(OBJS) $(PROGRAM) $(PROGRAM_ALIAS) 
 $(PROGRAM)-static $(GUEST_INIT) $(GUEST_INIT_S2)
  $(Q) rm -f cscope.*
  $(Q) rm -f $(KVM_INCLUDE)/common-cmds.h
  $(Q) rm -f KVMTOOLS-VERSION-FILE
 
 

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2] kvm tools: Add build target for statically-linked binary

2012-01-29 Thread Matt Evans
On 30/01/12 14:51, Sasha Levin wrote:
 On Mon, 2012-01-30 at 14:18 +1100, Matt Evans wrote:
 In lieu of any good lightweight solutions, can we include this patch as it is
 still useful for builds on systems without the offending optional libraries? 
 
 How about we do it as a 'make static' target which will generate a
 static binary without optional libraries (or just libs that don't link
 statically)?

Sure, but that was my question: how?  That 'make static' target can drop -lbfd,
-lSDL etc. from the link line but all of the '.o's that we've already built
either may depend on one of those libs or may do something different because
CONFIG_HAS_SDL (or similar) was set.  The only way I can think of doing this is
to have 'make static' depend on a second set of
$(all_objects_except_without_optional_libs) which are built without
CONFIG_HAS_SDL etc., but that'd make Makefile fugly IMHO.

Unless, that is, CFLAGS (and thus CONFIG_HAS_SDL, has_SDL probing, etc.) can
somehow change depending on the make target.

Matt


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Add build target for statically-linked binary

2012-01-08 Thread Matt Evans
This commit adds a target for 'lkvm-static' which is linked -static.

(This can be useful to construct kvmtool binaries for minimalist
auto-test host filesystems.)

Signed-off-by: Matt Evans m...@ozlabs.org
---

Pekka, I found this useful in one of our test setups, hopefully 
others will too.

Cheers, Matt


 tools/kvm/Makefile |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index ce3df65..309cc6b 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -233,6 +233,10 @@ $(PROGRAM): $(DEPS) $(OBJS)
$(E)   LINK $@
$(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
 
+$(PROGRAM)-static: $(DEPS) $(OBJS)
+   $(E)   LINK $@
+   $(Q) $(CC) -static $(CFLAGS) $(OBJS) $(LIBS) -o $@
+
 $(PROGRAM_ALIAS): $(PROGRAM)
$(E)   LN   $@
$(Q) ln -f $(PROGRAM) $@
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2] kvm tools: Add build target for statically-linked binary

2012-01-08 Thread Matt Evans
This commit adds a target for 'lkvm-static' which is linked -static.

(This can be useful to construct kvmtool binaries for minimalist
auto-test host filesystems.)

Signed-off-by: Matt Evans m...@ozlabs.org
---

V2:  Argh!  Let's remove it on make clean, too...

 tools/kvm/Makefile |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index d54fa47..ebc0c7c 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -233,6 +233,10 @@ $(PROGRAM): $(DEPS) $(OBJS)
$(E)   LINK $@
$(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
 
+$(PROGRAM)-static: $(DEPS) $(OBJS)
+   $(E)   LINK $@
+   $(Q) $(CC) -static $(CFLAGS) $(OBJS) $(LIBS) -o $@
+
 $(PROGRAM_ALIAS): $(PROGRAM)
$(E)   LN   $@
$(Q) ln -f $(PROGRAM) $@
@@ -325,7 +329,7 @@ clean:
$(Q) rm -f x86/bios/bios-rom.h
$(Q) rm -f tests/boot/boot_test.iso
$(Q) rm -rf tests/boot/rootfs/
-   $(Q) rm -f $(DEPS) $(OBJS) $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) 
$(GUEST_INIT_S2)
+   $(Q) rm -f $(DEPS) $(OBJS) $(PROGRAM) $(PROGRAM_ALIAS) 
$(PROGRAM)-static $(GUEST_INIT) $(GUEST_INIT_S2)
$(Q) rm -f cscope.*
$(Q) rm -f $(KVM_INCLUDE)/common-cmds.h
$(Q) rm -f KVMTOOLS-VERSION-FILE
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2012-01-05 Thread Matt Evans
Hey Alex,

On 24/12/11 00:39, Alexander Graf wrote:
 
 On 23.12.2011, at 14:26, Matt Evans wrote:
 

 On 23/12/2011, at 11:58 PM, Alexander Graf wrote:


 On 13.12.2011, at 07:21, Matt Evans wrote:

 Different architectures will deal with MMIO exits differently.  For 
 example,
 KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by 
 steering
 into windows in PCI bridges on other architectures.

 This patch calls arch-specific kvm_cpu__emulate_io() and 
 kvm_cpu__emulate_mmio()
 from the main runloop's IO and MMIO exit handlers.  For x86, these directly
 call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
 perform some address munging before passing on the call.

 Why do you need address munging? PIO is simply not there and MMIO always 
 goes to the physical address the CPU sees, so I don't see what you want to 
 munge. The way the memory bus is attached to the CPU should certainly not 
 be modeled differently for PPC and x86.

 PIO not there?  PIO is used heavily in kvmtool.  So, I made a window in a 
 similar way to how a real PHB has PIO-window-in-MMIO.

 PCI BARs are currently 32-bit.  I don't want to limit the guest RAM to 4G
 nor puncture holes in it just to make it look like x86... PCI bus addresses
 == CPU addresses is a bit of an x86ism.  So, I just used another PHB window
 to offset 32bit PCI MMIO up somewhere else.  We can then use all 4G of PCI
 MMIO space without putting that at addr 0 and RAM starting 4G.  (And then,
 exception vectors where?)

 The PCI/BARs/MMIO code could really support 64bit addresses though that's a
 bit of an orthogonal bit of work.  Why should PPC have an MMIO hole in the
 middle of RAM?
 

Sooo.. call it post-holiday bliss but I don't understand what you're saying
here. :)

 I fully agree with what you're saying, but the layering seems off. If the CPU
 gets an MMIO request, it gets that on a physical address from the view of the
   produces?

 CPU. Why would you want to have manual munging there to get to whatever window
 you have? Just map the MMIO regions to the higher addresses and expose
 whatever different representation you have to the device, not to the CPU
 layer.

What do you mean here by map and representation?  The only way I can parse
this is as though you're describing PCI devices seeing PCI bus addresses which
CPU MMIOs are converted to by the window offset, i.e. what already exists
i.e. what you're disagreeing with :-)

Sorry.. please explain some more.  Is your suggestion to make CPU phys addresses
and PCI bus addresses 1:1?  (Hole in RAM..)


Thanks!


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2012-01-05 Thread Matt Evans
Hey Alex,

On 24/12/11 00:39, Alexander Graf wrote:
 
 On 23.12.2011, at 14:26, Matt Evans wrote:
 

 On 23/12/2011, at 11:58 PM, Alexander Graf wrote:


 On 13.12.2011, at 07:21, Matt Evans wrote:

 Different architectures will deal with MMIO exits differently.  For 
 example,
 KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by 
 steering
 into windows in PCI bridges on other architectures.

 This patch calls arch-specific kvm_cpu__emulate_io() and 
 kvm_cpu__emulate_mmio()
 from the main runloop's IO and MMIO exit handlers.  For x86, these directly
 call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
 perform some address munging before passing on the call.

 Why do you need address munging? PIO is simply not there and MMIO always 
 goes to the physical address the CPU sees, so I don't see what you want to 
 munge. The way the memory bus is attached to the CPU should certainly not 
 be modeled differently for PPC and x86.

 PIO not there?  PIO is used heavily in kvmtool.  So, I made a window in a 
 similar way to how a real PHB has PIO-window-in-MMIO.

 PCI BARs are currently 32-bit.  I don't want to limit the guest RAM to 4G
 nor puncture holes in it just to make it look like x86... PCI bus addresses
 == CPU addresses is a bit of an x86ism.  So, I just used another PHB window
 to offset 32bit PCI MMIO up somewhere else.  We can then use all 4G of PCI
 MMIO space without putting that at addr 0 and RAM starting 4G.  (And then,
 exception vectors where?)

 The PCI/BARs/MMIO code could really support 64bit addresses though that's a
 bit of an orthogonal bit of work.  Why should PPC have an MMIO hole in the
 middle of RAM?
 

Sooo.. call it post-holiday bliss but I don't understand what you're saying
here. :)

 I fully agree with what you're saying, but the layering seems off. If the CPU
 gets an MMIO request, it gets that on a physical address from the view of the
   produces?

 CPU. Why would you want to have manual munging there to get to whatever window
 you have? Just map the MMIO regions to the higher addresses and expose
 whatever different representation you have to the device, not to the CPU
 layer.

What do you mean here by map and representation?  The only way I can parse
this is as though you're describing PCI devices seeing PCI bus addresses which
CPU MMIOs are converted to by the window offset, i.e. what already exists
i.e. what you're disagreeing with :-)

Sorry.. please explain some more.  Is your suggestion to make CPU phys addresses
and PCI bus addresses 1:1?  (Hole in RAM..)


Thanks!


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2011-12-23 Thread Matt Evans

On 23/12/2011, at 11:58 PM, Alexander Graf wrote:

 
 On 13.12.2011, at 07:21, Matt Evans wrote:
 
 Different architectures will deal with MMIO exits differently.  For example,
 KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
 into windows in PCI bridges on other architectures.
 
 This patch calls arch-specific kvm_cpu__emulate_io() and 
 kvm_cpu__emulate_mmio()
 from the main runloop's IO and MMIO exit handlers.  For x86, these directly
 call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
 perform some address munging before passing on the call.
 
 Why do you need address munging? PIO is simply not there and MMIO always goes 
 to the physical address the CPU sees, so I don't see what you want to munge. 
 The way the memory bus is attached to the CPU should certainly not be modeled 
 differently for PPC and x86.

PIO not there?  PIO is used heavily in kvmtool.  So, I made a window in a 
similar way to how a real PHB has PIO-window-in-MMIO.

PCI BARs are currently 32-bit.  I don't want to limit the guest RAM to 4G nor 
puncture holes in it just to make it look like x86... PCI bus addresses == CPU 
addresses is a bit of an x86ism.  So, I just used another PHB window to offset 
32bit PCI MMIO up somewhere else.  We can then use all 4G of PCI MMIO space 
without putting that at addr 0 and RAM starting 4G.  (And then, exception 
vectors where?)

The PCI/BARs/MMIO code could really support 64bit addresses though that's a bit 
of an orthogonal bit of work.  Why should PPC have an MMIO hole in the middle 
of RAM?


Cheers!


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 4/6] kvm tools: Add PPC64 XICS interrupt controller support

2011-12-19 Thread Matt Evans
Hi David,

On 14/12/11 13:35, David Gibson wrote:
 On Tue, Dec 13, 2011 at 06:10:48PM +1100, Matt Evans wrote:
 This patch adds XICS emulation code (heavily borrowed from QEMU), and wires
 this into kvm_cpu__irq() to fire a CPU IRQ via KVM.  A device tree entry is
 also added.  IPIs work, xics_alloc_irqnum() is added to allocate an external
 IRQ (which will later be used by the PHB PCI code) and finally, 
 kvm__irq_line()
 can be called to raise an IRQ on XICS.\
 
 Hrm, looks like you took a somewhat old version of xics.c from qemu.
 It dangerously uses the same variable names for global irq numbers and
 numbers local to one ics unit.  It used to have at least one bug
 caused by confusing the two, which I'm not sure if you've also copied.

Just had a look at the diffs between this and hw/xics.c from the master branch
in your qemu-impreza.git (which I based the kvmtool stuff on) and I can't see
anything standing out.

Is there a particular commit/patch/variable name you have in mind that I can
search for?


Thanks!


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Clean up LINT assignment code

2011-12-14 Thread Matt Evans
On 14 Dec 2011, at 17:13, Sasha Levin levinsasha...@gmail.com wrote:

 On Wed, 2011-12-14 at 13:06 +1100, Matt Evans wrote:
 Hi Sasha,
 
 On 12/12/11 06:50, Sasha Levin wrote:
 Just set delivery mode directly without going through ugly casting.
 
 This cleans up and simplifies the code.
 
 Signed-off-by: Sasha Levin levinsasha...@gmail.com
 ---
 tools/kvm/x86/kvm-cpu.c |   10 ++
 1 files changed, 2 insertions(+), 8 deletions(-)
 
 diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
 index 27b7a8f..cc1f560 100644
 --- a/tools/kvm/x86/kvm-cpu.c
 +++ b/tools/kvm/x86/kvm-cpu.c
 @@ -81,18 +81,12 @@ static int kvm_cpu__set_lint(struct kvm_cpu *vcpu)
 {
struct kvm_lapic_state klapic;
struct local_apic *lapic = (void *)klapic;
 -u32 lvt;
 
if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, klapic))
return -1;
 
 -lvt = *(u32 *)lapic-lvt_lint0;
 -lvt = SET_APIC_DELIVERY_MODE(lvt, APIC_MODE_EXTINT);
 -*(u32 *)lapic-lvt_lint0 = lvt;
 -
 -lvt = *(u32 *)lapic-lvt_lint1;
 -lvt = SET_APIC_DELIVERY_MODE(lvt, APIC_MODE_NMI);
 -*(u32 *)lapic-lvt_lint1 = lvt;
 +lapic-lvt_lint0.delivery_mode = APIC_MODE_EXTINT;
 +lapic-lvt_lint1.delivery_mode = APIC_MODE_NMI;
 
return ioctl(vcpu-vcpu_fd, KVM_SET_LAPIC, klapic);
 }
 
 I'm getting this on x86-32, gcc 4.4.3:
 
  CC   x86/kvm-cpu.o
 cc1: warnings being treated as errors
 x86/kvm-cpu.c: In function ‘kvm_cpu__set_lint’:
 x86/kvm-cpu.c:89: error: dereferencing pointer ‘lapic’ does break 
 strict-aliasing rules
 x86/kvm-cpu.c:88: error: dereferencing pointer ‘lapic’ does break 
 strict-aliasing rules
 x86/kvm-cpu.c:83: note: initialized from here
 make: *** [x86/kvm-cpu.o] Error 1
 
 Removing the nasty aliasing (patch below) seems to be a good way to go.  
 What do
 you think?
 
 
 Cheers,
 
 
 Matt
 
 ---
 
 diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
 index cc1f560..30f1ad6 100644
 --- a/tools/kvm/x86/kvm-cpu.c
 +++ b/tools/kvm/x86/kvm-cpu.c
 @@ -79,16 +79,15 @@ void kvm_cpu__delete(struct kvm_cpu *vcpu)
 
 static int kvm_cpu__set_lint(struct kvm_cpu *vcpu)
 {
 -struct kvm_lapic_state klapic;
 -struct local_apic *lapic = (void *)klapic;
 +struct local_apic lapic;
 
 -if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, klapic))
 +if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, lapic))
return -1;
 
 It felt a bit wrong to me getting the ioctl to assign it directly to
 local_apic since api.txt says it should be returning a kvm_lapic_state.
 But on the other hand, api.txt also says The data format and layout are
 the same as documented in the architecture manual. so I guess we can go
 with that.
 
Acked-by: Sasha Levin levinsasha...@gmail.com

Pekka, as I forgot the SOB:

Signed-off-by: Matt Evans m...@ozlabs.org

(Or would you prefer a repost so it's all in one?)

Matt--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: can kvm tool load vmlinux?

2011-12-14 Thread Matt Evans
On 15/12/11 08:24, David Evensky wrote:
 
 I've been trying see if I can use a vmlinux kernel binary image with kvm tool.
 If use a bzImage as
 
 lkvm run -k .../bzImage --console serial -d /dev/null
 
 which runs until it expectedly dies since I didn't give it an initramfs or 
 disk.
 However, when I try:
 
 lkvm run -k .../bzImage --console serial -d /dev/null
 
 I get the following printed and then nothing:
 
   # kvm run -k .../vmlinux -m 448 -c 4 --name guest-12289
   Warning: .../vmlinux is not a bzImage. Trying to load it as a flat binary...
 
 
 Is this supposed to work?

Hi David,


Currently there are loaders for bzImages and flat binaries only.  Since your
vmlinux is not detected as a bzImage (it's a plain ELF), kvmtool will assume
it's a flat binary (which it isn't)  try that.  Boom!

An ELF loader would be cool though.  (Maybe if I find time...)


Cheers,


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD

2011-12-14 Thread Matt Evans
On 14/12/11 17:37, Sasha Levin wrote:
 Check KVM_CAP_IOEVENTFD before using ioeventfds.
 
 Signed-off-by: Sasha Levin levinsasha...@gmail.com

A much nicer solution than my [PATCH V2 2/2] kvm tools: Make virtio-pci's
ioeventfd__add_event() fall back gracefully if ioeventfds unavailable.

 matt.nastyhacks--;

Acked-by: Matt Evans m...@ozlabs.org

 ---
  tools/kvm/builtin-run.c   |2 +-
  tools/kvm/include/kvm/ioeventfd.h |2 +-
  tools/kvm/ioeventfd.c |   16 +++-
  3 files changed, 17 insertions(+), 3 deletions(-)
 
 diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
 index 76f1a8c..47e4ea8 100644
 --- a/tools/kvm/builtin-run.c
 +++ b/tools/kvm/builtin-run.c
 @@ -932,7 +932,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
 *prefix)
  
   kvm-single_step = single_step;
  
 - ioeventfd__init();
 + ioeventfd__init(kvm);
  
   max_cpus = kvm__max_cpus(kvm);
   recommended_cpus = kvm__recommended_cpus(kvm);
 diff --git a/tools/kvm/include/kvm/ioeventfd.h 
 b/tools/kvm/include/kvm/ioeventfd.h
 index df01750..3a95788 100644
 --- a/tools/kvm/include/kvm/ioeventfd.h
 +++ b/tools/kvm/include/kvm/ioeventfd.h
 @@ -19,7 +19,7 @@ struct ioevent {
   struct list_headlist;
  };
  
 -void ioeventfd__init(void);
 +void ioeventfd__init(struct kvm *kvm);
  void ioeventfd__start(void);
  void ioeventfd__add_event(struct ioevent *ioevent);
  void ioeventfd__del_event(u64 addr, u64 datamatch);
 diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
 index 3a240e4..75dd3f2 100644
 --- a/tools/kvm/ioeventfd.c
 +++ b/tools/kvm/ioeventfd.c
 @@ -18,9 +18,14 @@
  static structepoll_event events[IOEVENTFD_MAX_EVENTS];
  static int   epoll_fd;
  static LIST_HEAD(used_ioevents);
 +static bool  ioeventfd_avail;
  
 -void ioeventfd__init(void)
 +void ioeventfd__init(struct kvm *kvm)
  {
 + ioeventfd_avail = kvm__has_cap(kvm, KVM_CAP_IOEVENTFD);
 + if (!ioeventfd_avail)
 + return;
 +
   epoll_fd = epoll_create(IOEVENTFD_MAX_EVENTS);
   if (epoll_fd  0)
   die(Failed creating epoll fd);
 @@ -33,6 +38,9 @@ void ioeventfd__add_event(struct ioevent *ioevent)
   struct ioevent *new_ioevent;
   int event;
  
 + if (!ioeventfd_avail)
 + return;
 +
   new_ioevent = malloc(sizeof(*new_ioevent));
   if (new_ioevent == NULL)
   die(Failed allocating memory for new ioevent);
 @@ -68,6 +76,9 @@ void ioeventfd__del_event(u64 addr, u64 datamatch)
   struct ioevent *ioevent;
   u8 found = 0;
  
 + if (!ioeventfd_avail)
 + return;
 +
   list_for_each_entry(ioevent, used_ioevents, list) {
   if (ioevent-io_addr == addr) {
   found = 1;
 @@ -123,6 +134,9 @@ void ioeventfd__start(void)
  {
   pthread_t thread;
  
 + if (!ioeventfd_avail)
 + return;
 +
   if (pthread_create(thread, NULL, ioeventfd__thread, NULL) != 0)
   die(Failed starting ioeventfd thread);
  }

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-14 Thread Matt Evans
Heya Alex,

On 13/12/11 19:23, Alexander Graf wrote:
 
 On 13.12.2011, at 08:00, Matt Evans m...@ozlabs.org wrote:
 
 This patch adds a new arch directory, powerpc, basic file structure, register
 setup and where necessary stubs out arch-specific functions (e.g. interrupts,
 runloop exits) that later patches will provide.  The target is an
 SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 
 or
 'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls 
 and
 RTAS required to boot SPAPR pSeries kernels.

 Memory is mapped from hugetlbfs (as that is currently required by upstream 
 PPC64
 HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this is
 only necessary on processors that don't support VRMA, e.g. = P6.  Work is
 therefore needed to get this going on pre-P7 CPUs.

 Processor state is set up as a guest kernel would expect (both primary and
 secondaries), and SMP is fully supported.

 Finally, support is added for simply loading flat binary kernels (plus 
 initrd).
 (bzImages are not used on PPC, and this series does not add zImage support 
 or an
 ELF loader.)  The intention is to later support loading firmware such as 
 SLOF.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 
 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 2bf70c9..3f1e84a 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
OTHEROBJS+= x86/bios/bios-rom.o
ARCH_INCLUDE := x86/include
 endif
 +# POWER/ppc:  Actually only support ppc64 currently.
 
 Why? I usually run ppc32 user land. Doesn't that expose 'ppc' here?

Not quite sure what you mean here; do you mean 32bit distro?  (Will still get 
'ppc64' from a 64-bit kernel.)

There is clearly some work required here to determine what to build for when we
eventually support PPC32 guests/hosts though I'm not sure how that will look
yet.  This is designed to break if you build on a 32bit kernel, as if it DID
build, it wouldn't run anyway.  (It's building -m64 too...

 +ifeq ($(uname_M), ppc64)
 +DEFINES += -DCONFIG_PPC
 +OBJS+= powerpc/ioport.o
 +OBJS+= powerpc/irq.o
 +OBJS+= powerpc/kvm.o
 +OBJS+= powerpc/kvm-cpu.o
 +ARCH_INCLUDE := powerpc/include
 +CFLAGS += -m64

...here.)

 +endif

 ###

 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index 35ca2c5..3fb46f6 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
 +#ifdef CONFIG_PPC64
 +DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
 +#endif
 };

 extern struct kvm *kvm;
 diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
 b/tools/kvm/powerpc/include/kvm/barrier.h
 new file mode 100644
 index 000..bc7d179
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/barrier.h
 @@ -0,0 +1,6 @@
 +#ifndef _KVM_BARRIER_H_
 +#define _KVM_BARRIER_H_
 +
 +#include asm/system.h
 +
 +#endif /* _KVM_BARRIER_H_ */
 diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
 b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 new file mode 100644
 index 000..da61774
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 @@ -0,0 +1,72 @@
 +/*
 + * PPC64 architecture-specific definitions
 + *
 + * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms of the GNU General Public License version 2 as published
 + * by the Free Software Foundation.
 + */
 +
 +#ifndef KVM__KVM_ARCH_H
 +#define KVM__KVM_ARCH_H
 +
 +#include stdbool.h
 +#include linux/types.h
 +#include time.h
 +
 +#define KVM_NR_CPUS(255)
 
 Why?

Good question; that's arbitrary  cut-paste I missed. :-)

I'll make this 1024, to match the max sensible NR_CPUS in the PPC64 kernel
(which in turn limits KVM_MAX_VCPUS).

 +
 +/*
 + * MMIO lives after

Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-14 Thread Matt Evans
On 15/12/11 12:37, Alexander Graf wrote:
 
 On 15.12.2011, at 02:27, Matt Evans wrote:
 
 Heya Alex,

 On 13/12/11 19:23, Alexander Graf wrote:

 On 13.12.2011, at 08:00, Matt Evans m...@ozlabs.org wrote:

 This patch adds a new arch directory, powerpc, basic file structure, 
 register
 setup and where necessary stubs out arch-specific functions (e.g. 
 interrupts,
 runloop exits) that later patches will provide.  The target is an
 SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for 
 PPC32 or
 'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls 
 and
 RTAS required to boot SPAPR pSeries kernels.

 Memory is mapped from hugetlbfs (as that is currently required by upstream 
 PPC64
 HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this 
 is
 only necessary on processors that don't support VRMA, e.g. = P6.  Work is
 therefore needed to get this going on pre-P7 CPUs.

 Processor state is set up as a guest kernel would expect (both primary and
 secondaries), and SMP is fully supported.

 Finally, support is added for simply loading flat binary kernels (plus 
 initrd).
 (bzImages are not used on PPC, and this series does not add zImage support 
 or an
 ELF loader.)  The intention is to later support loading firmware such as 
 SLOF.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 
 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 2bf70c9..3f1e84a 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
   OTHEROBJS+= x86/bios/bios-rom.o
   ARCH_INCLUDE := x86/include
 endif
 +# POWER/ppc:  Actually only support ppc64 currently.

 Why? I usually run ppc32 user land. Doesn't that expose 'ppc' here?

 Not quite sure what you mean here; do you mean 32bit distro?  (Will still 
 get 'ppc64' from a 64-bit kernel.)
 
 Eh. Yes. Sorry, my bad.
 
 There is clearly some work required here to determine what to build for when 
 we
 eventually support PPC32 guests/hosts though I'm not sure how that will look
 yet.  This is designed to break if you build on a 32bit kernel, as if it DID
 build, it wouldn't run anyway.  (It's building -m64 too...
 
 Yeah, running -M pseries on PPC32 hosts doesn't make sense really.
 

 +ifeq ($(uname_M), ppc64)
 +DEFINES += -DCONFIG_PPC
 +OBJS+= powerpc/ioport.o
 +OBJS+= powerpc/irq.o
 +OBJS+= powerpc/kvm.o
 +OBJS+= powerpc/kvm-cpu.o
 +ARCH_INCLUDE := powerpc/include
 +CFLAGS += -m64

 ...here.)

 +endif

 ###

 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index 35ca2c5..3fb46f6 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
 +#ifdef CONFIG_PPC64
 +DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
 +#endif
 };

 extern struct kvm *kvm;
 diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
 b/tools/kvm/powerpc/include/kvm/barrier.h
 new file mode 100644
 index 000..bc7d179
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/barrier.h
 @@ -0,0 +1,6 @@
 +#ifndef _KVM_BARRIER_H_
 +#define _KVM_BARRIER_H_
 +
 +#include asm/system.h
 +
 +#endif /* _KVM_BARRIER_H_ */
 diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
 b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 new file mode 100644
 index 000..da61774
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 @@ -0,0 +1,72 @@
 +/*
 + * PPC64 architecture-specific definitions
 + *
 + * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms of the GNU General Public License version 2 as 
 published
 + * by the Free Software Foundation.
 + */
 +
 +#ifndef KVM__KVM_ARCH_H
 +#define KVM__KVM_ARCH_H
 +
 +#include stdbool.h
 +#include linux/types.h
 +#include time.h
 +
 +#define KVM_NR_CPUS(255)

 Why

Re: [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host

2011-12-14 Thread Matt Evans
On 14/12/11 17:37, Sasha Levin wrote:
 Signed-off-by: Sasha Levin levinsasha...@gmail.com
 ---
  tools/kvm/include/kvm/kvm.h |2 ++
  tools/kvm/kvm.c |5 +
  2 files changed, 7 insertions(+), 0 deletions(-)
 
 diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
 index 7159952..d24b70a 100644
 --- a/tools/kvm/include/kvm/kvm.h
 +++ b/tools/kvm/include/kvm/kvm.h
 @@ -79,4 +79,6 @@ static inline void *guest_flat_to_host(struct kvm *kvm, 
 unsigned long offset)
   return kvm-ram_start + offset;
  }
  
 +bool kvm__has_cap(struct kvm *kvm, u32 cap);
 +
  #endif /* KVM__KVM_H */
 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index 35ca2c5..a2f7a89 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -517,3 +517,8 @@ void kvm__notify_paused(void)
   mutex_lock(pause_lock);
   mutex_unlock(pause_lock);
  }
 +
 +bool kvm__has_cap(struct kvm *kvm, u32 cap)
 +{
 + return ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, cap) == 0;
 +}


D'oh, this needs to be != 0, not == 0.


Cheers,


Matt

---

From: Matt Evans m...@ozlabs.org
Date: Thu, 15 Dec 2011 15:19:47 +1100
Subject: [PATCH] kvm tools: Fix inverted logic bug in kvm__has_cap

Commit 42efb1abf4ebebeedd14af34c073e673923e2898 compared KVM_CHECK_EXTENSION's
result wrong, stating 'has cap' true if 0.  Invert the comparison.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 9583ab2..25f1419 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -523,5 +523,5 @@ void kvm__notify_paused(void)
 
 bool kvm__has_cap(struct kvm *kvm, u32 cap)
 {
-   return ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, cap) == 0;
+   return ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, cap) != 0;
 }
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Remove KVM_NR_CPUS

2011-12-14 Thread Matt Evans
The KVM_NR_CPUS define is only really used to statically size the global
kvm_cpus array, which can just as easily be allocated on startup.  There is
some checking of the -c nr cpus value given against NR_CPUs but this is
later again checked against a dynamically-determined limit from
KVM_CAP_MAX_VCPUS anyway.  The hardwired limit is arbitrary and not strictly
necessary.

This patch removes the #define, replacing the statically-sized array with
a malloc; the array is kvm-nrcpus+1 in size so that any iterator can halt
at the end (this is done in kvm_cpu__reboot, which doesn't have access to
a struct kvm* and therefore kvm-nrcpus).

An unused #define in x86/mptable.c is also removed.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c  |9 ++---
 tools/kvm/kvm-cpu.c  |8 ++--
 tools/kvm/kvm.c  |2 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |2 --
 tools/kvm/x86/include/kvm/kvm-arch.h |2 --
 tools/kvm/x86/mptable.c  |8 
 6 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 47e4ea8..0879ab9 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -64,7 +64,7 @@ const char *DEFAULT_SANDBOX_FILENAME = guest/sandbox.sh;
 #define MIN_RAM_SIZE_BYTE  (MIN_RAM_SIZE_MB  MB_SHIFT)
 
 struct kvm *kvm;
-struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
+struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static u64 ram_size;
@@ -875,8 +875,6 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
if (nrcpus == 0)
nrcpus = nr_online_cpus;
-   else if (nrcpus  1 || nrcpus  KVM_NR_CPUS)
-   die(Number of CPUs %d is out of [1;%d] range, nrcpus, 
KVM_NR_CPUS);
 
if (!ram_size)
ram_size= get_ram_size(nrcpus);
@@ -947,6 +945,11 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
kvm-nrcpus = nrcpus;
 
+   /* Alloc one pointer too many, so array ends up 0-terminated */
+   kvm_cpus = calloc(nrcpus + 1, sizeof(void *));
+   if (!kvm_cpus)
+   die(Couldn't allocate array for %d CPUs, nrcpus);
+
irq__init(kvm);
 
pci__init();
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index a0f330f..52db84a 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -12,7 +12,7 @@
 #include errno.h
 #include stdio.h
 
-extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
+extern struct kvm_cpu **kvm_cpus;
 extern __thread struct kvm_cpu *current_kvm_cpu;
 
 void kvm_cpu__enable_singlestep(struct kvm_cpu *vcpu)
@@ -66,9 +66,13 @@ void kvm_cpu__reboot(void)
 {
int i;
 
-   for (i = 0; i  KVM_NR_CPUS; i++)
+   /* The kvm_cpus array contains a null pointer in the last location */
+   for (i = 0; ; i++) {
if (kvm_cpus[i])
pthread_kill(kvm_cpus[i]-thread, SIGKVMEXIT);
+   else
+   break;
+   }
 }
 
 int kvm_cpu__start(struct kvm_cpu *cpu)
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 25f1419..6b220c6 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -55,7 +55,7 @@ const char *kvm_exit_reasons[] = {
 };
 
 extern struct kvm *kvm;
-extern struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
+extern struct kvm_cpu **kvm_cpus;
 static int pause_event;
 static DEFINE_MUTEX(pause_lock);
 extern struct kvm_ext kvm_req_ext[];
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index da61774..10aa2d9 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -15,8 +15,6 @@
 #include linux/types.h
 #include time.h
 
-#define KVM_NR_CPUS(255)
-
 /*
  * MMIO lives after RAM, but it'd be nice if it didn't constantly move.
  * Choose a suitably high address, e.g. 63T...  This limits RAM size.
diff --git a/tools/kvm/x86/include/kvm/kvm-arch.h 
b/tools/kvm/x86/include/kvm/kvm-arch.h
index 686b1b8..1ce3d31 100644
--- a/tools/kvm/x86/include/kvm/kvm-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-arch.h
@@ -8,8 +8,6 @@
 #include linux/types.h
 #include time.h
 
-#define KVM_NR_CPUS(255)
-
 /*
  * The hole includes VESA framebuffer and PCI memory.
  */
diff --git a/tools/kvm/x86/mptable.c b/tools/kvm/x86/mptable.c
index cfc7d79..701605a 100644
--- a/tools/kvm/x86/mptable.c
+++ b/tools/kvm/x86/mptable.c
@@ -8,14 +8,6 @@
 #include linux/kernel.h
 #include string.h
 
-/*
- * If kernel is not configured yet this macro
- * might not be defined, fix it by own definition
- */
-#ifndef NR_CPUS
-#define NR_CPUS KVM_NR_CPUS
-#endif
-
 #include asm/mpspec_def.h
 #include linux/types.h
 
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm tools: Fix running with --initrd and no real discs/rootfs

2011-12-14 Thread Matt Evans
It's useful to boot with no -d and no implicit 9p root, with --initrd.
Since commit eaf720b285947a6f4e29174d0eba1899de31d8ab, we die() failing
to create the 2nd stage custom rootfs.  This patch doesn't try to set up
a custom rootfs by default if user specifies an initrd on the commandline.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 0879ab9..c4329ea 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -973,7 +973,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
if (kernel_cmdline)
strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
 
-   if (!using_rootfs  !image_filename[0]) {
+   if (!using_rootfs  !image_filename[0]  !initrd_filename) {
char tmp[PATH_MAX];
 
kvm_setup_create_new(default);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-14 Thread Matt Evans
Heya Alex,

On 13/12/11 19:23, Alexander Graf wrote:
 
 On 13.12.2011, at 08:00, Matt Evans m...@ozlabs.org wrote:
 
 This patch adds a new arch directory, powerpc, basic file structure, register
 setup and where necessary stubs out arch-specific functions (e.g. interrupts,
 runloop exits) that later patches will provide.  The target is an
 SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 
 or
 'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls 
 and
 RTAS required to boot SPAPR pSeries kernels.

 Memory is mapped from hugetlbfs (as that is currently required by upstream 
 PPC64
 HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this is
 only necessary on processors that don't support VRMA, e.g. = P6.  Work is
 therefore needed to get this going on pre-P7 CPUs.

 Processor state is set up as a guest kernel would expect (both primary and
 secondaries), and SMP is fully supported.

 Finally, support is added for simply loading flat binary kernels (plus 
 initrd).
 (bzImages are not used on PPC, and this series does not add zImage support 
 or an
 ELF loader.)  The intention is to later support loading firmware such as 
 SLOF.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 
 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 2bf70c9..3f1e84a 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
OTHEROBJS+= x86/bios/bios-rom.o
ARCH_INCLUDE := x86/include
 endif
 +# POWER/ppc:  Actually only support ppc64 currently.
 
 Why? I usually run ppc32 user land. Doesn't that expose 'ppc' here?

Not quite sure what you mean here; do you mean 32bit distro?  (Will still get 
'ppc64' from a 64-bit kernel.)

There is clearly some work required here to determine what to build for when we
eventually support PPC32 guests/hosts though I'm not sure how that will look
yet.  This is designed to break if you build on a 32bit kernel, as if it DID
build, it wouldn't run anyway.  (It's building -m64 too...

 +ifeq ($(uname_M), ppc64)
 +DEFINES += -DCONFIG_PPC
 +OBJS+= powerpc/ioport.o
 +OBJS+= powerpc/irq.o
 +OBJS+= powerpc/kvm.o
 +OBJS+= powerpc/kvm-cpu.o
 +ARCH_INCLUDE := powerpc/include
 +CFLAGS += -m64

...here.)

 +endif

 ###

 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index 35ca2c5..3fb46f6 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
 +#ifdef CONFIG_PPC64
 +DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
 +#endif
 };

 extern struct kvm *kvm;
 diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
 b/tools/kvm/powerpc/include/kvm/barrier.h
 new file mode 100644
 index 000..bc7d179
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/barrier.h
 @@ -0,0 +1,6 @@
 +#ifndef _KVM_BARRIER_H_
 +#define _KVM_BARRIER_H_
 +
 +#include asm/system.h
 +
 +#endif /* _KVM_BARRIER_H_ */
 diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
 b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 new file mode 100644
 index 000..da61774
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 @@ -0,0 +1,72 @@
 +/*
 + * PPC64 architecture-specific definitions
 + *
 + * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms of the GNU General Public License version 2 as published
 + * by the Free Software Foundation.
 + */
 +
 +#ifndef KVM__KVM_ARCH_H
 +#define KVM__KVM_ARCH_H
 +
 +#include stdbool.h
 +#include linux/types.h
 +#include time.h
 +
 +#define KVM_NR_CPUS(255)
 
 Why?

Good question; that's arbitrary  cut-paste I missed. :-)

I'll make this 1024, to match the max sensible NR_CPUS in the PPC64 kernel
(which in turn limits KVM_MAX_VCPUS).

 +
 +/*
 + * MMIO lives after

Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-14 Thread Matt Evans
On 15/12/11 12:37, Alexander Graf wrote:
 
 On 15.12.2011, at 02:27, Matt Evans wrote:
 
 Heya Alex,

 On 13/12/11 19:23, Alexander Graf wrote:

 On 13.12.2011, at 08:00, Matt Evans m...@ozlabs.org wrote:

 This patch adds a new arch directory, powerpc, basic file structure, 
 register
 setup and where necessary stubs out arch-specific functions (e.g. 
 interrupts,
 runloop exits) that later patches will provide.  The target is an
 SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for 
 PPC32 or
 'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls 
 and
 RTAS required to boot SPAPR pSeries kernels.

 Memory is mapped from hugetlbfs (as that is currently required by upstream 
 PPC64
 HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this 
 is
 only necessary on processors that don't support VRMA, e.g. = P6.  Work is
 therefore needed to get this going on pre-P7 CPUs.

 Processor state is set up as a guest kernel would expect (both primary and
 secondaries), and SMP is fully supported.

 Finally, support is added for simply loading flat binary kernels (plus 
 initrd).
 (bzImages are not used on PPC, and this series does not add zImage support 
 or an
 ELF loader.)  The intention is to later support loading firmware such as 
 SLOF.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 
 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 2bf70c9..3f1e84a 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
   OTHEROBJS+= x86/bios/bios-rom.o
   ARCH_INCLUDE := x86/include
 endif
 +# POWER/ppc:  Actually only support ppc64 currently.

 Why? I usually run ppc32 user land. Doesn't that expose 'ppc' here?

 Not quite sure what you mean here; do you mean 32bit distro?  (Will still 
 get 'ppc64' from a 64-bit kernel.)
 
 Eh. Yes. Sorry, my bad.
 
 There is clearly some work required here to determine what to build for when 
 we
 eventually support PPC32 guests/hosts though I'm not sure how that will look
 yet.  This is designed to break if you build on a 32bit kernel, as if it DID
 build, it wouldn't run anyway.  (It's building -m64 too...
 
 Yeah, running -M pseries on PPC32 hosts doesn't make sense really.
 

 +ifeq ($(uname_M), ppc64)
 +DEFINES += -DCONFIG_PPC
 +OBJS+= powerpc/ioport.o
 +OBJS+= powerpc/irq.o
 +OBJS+= powerpc/kvm.o
 +OBJS+= powerpc/kvm-cpu.o
 +ARCH_INCLUDE := powerpc/include
 +CFLAGS += -m64

 ...here.)

 +endif

 ###

 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index 35ca2c5..3fb46f6 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
   DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
 +#ifdef CONFIG_PPC64
 +DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
 +#endif
 };

 extern struct kvm *kvm;
 diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
 b/tools/kvm/powerpc/include/kvm/barrier.h
 new file mode 100644
 index 000..bc7d179
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/barrier.h
 @@ -0,0 +1,6 @@
 +#ifndef _KVM_BARRIER_H_
 +#define _KVM_BARRIER_H_
 +
 +#include asm/system.h
 +
 +#endif /* _KVM_BARRIER_H_ */
 diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
 b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 new file mode 100644
 index 000..da61774
 --- /dev/null
 +++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
 @@ -0,0 +1,72 @@
 +/*
 + * PPC64 architecture-specific definitions
 + *
 + * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms of the GNU General Public License version 2 as 
 published
 + * by the Free Software Foundation.
 + */
 +
 +#ifndef KVM__KVM_ARCH_H
 +#define KVM__KVM_ARCH_H
 +
 +#include stdbool.h
 +#include linux/types.h
 +#include time.h
 +
 +#define KVM_NR_CPUS(255)

 Why

Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-13 Thread Matt Evans


On 14 Dec 2011, at 04:43, Pekka Enberg penb...@kernel.org wrote:

 On Tue, Dec 13, 2011 at 9:00 AM, Matt Evans m...@ozlabs.org wrote:
 +int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 +{
 +   fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
 +   dev, *num, *pin, *line);
 +   return 0;
 +}
 +
 +void irq__init(struct kvm *kvm)
 +{
 +   fprintf(stderr, __func__);
 +}
 +
 +int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
 +{
 +   die(__FUNCTION__);
 +   return 0;
 +}
 
 +void kvm__irq_line(struct kvm *kvm, int irq, int level)
 +{
 +   fprintf(stderr, irq_line(%d, %d)\n, irq, level);
 +}
 
 What's the plan with these functions? Will you need these on PPC? If
 yes, why not implement them properly now? If not, we need to drop them
 from PPC arch.

Yes, they're filled in in the later XICS patch.

Cheers,

Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 0/2] kvm tools: PPC64 basic support

2011-12-13 Thread Matt Evans
On 13/12/11 21:23, Sasha Levin wrote:
 On Tue, 2011-12-13 at 18:00 +1100, Matt Evans wrote:
 The second patch is a small fix for generic virtio code (now that we have a
 PPC build) which removes reliance on ioeventfds for PPC, which doesn't 
 provide
 them. 
 
 Hm... ioeventfds are located in the generic code and should be available
 on all archs (it doesn't use any arch specific code at all afaik).
 
 Why don't they work on ppc?
 

Well, there are two problems: you're right that it's generic code, but it's
configurable and CONFIG_HAVE_KVM_EVENTFD isn't set for PPC KVM (thus the ioctl
fails).  That's probably off because ioevents won't work anyway-- the in-kernel
MMIO exit route isn't wired up to kvm_io_bus_read/write() yet.  (It looks like
KVM_IRQFD will also fail, which virtio-pci /would/ use if I supported MSIs,
which I currently don't.)

Yes, this can be fixed, but relying on it means that virtio on kvmtool/PPC won't
work on today's kernels. :(


Cheers,


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V3 1/2] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-13 Thread Matt Evans
On 14/12/11 11:03, David Evensky wrote:
 
 
 On an x86 32bit system (and using the 32bit CodeSourcery toolchain on a 
 x86_64 system) I get:
 
 evensky@machine:~/.../linux-kvm/tools/kvm$ make
   CC   util/util.o
 util/util.c: In function 'mmap_hugetlbfs':
 util/util.c:93:17: error: comparison between signed and unsigned integer 
 expressions [-Werror=sign-compare]
 util/util.c:99:7: error: format '%ld' expects argument of type 'long int', 
 but argument 2 has type 'int' [-Werror=format]
 cc1: all warnings being treated as errors
 
 make: *** [util/util.o] Error 1

Hi David,


Argh!  I didn't catch this as it compiles fine on my x86_64 box (with 64bit
toolchain) :( So, struct statfs's f_type and f_blocks are __SWORD_TYPE which is
either an int or a long (if on 64bit) so identical to if it were simply a
long, nice.

Pekka, a re-jiggle fix attached.


Thanks,


Matt


---
From: Matt Evans m...@ozlabs.org
Date: Wed, 14 Dec 2011 12:10:03 +1100
Subject: [PATCH] kvm tools: Fix build of util.c on 32bit machines

commit 378ee7e6dd301347c6bf2c740cb1fb40174bcb8b broke the -Werror build
on 32bit targets due to some variable typing in struct statfs.

Fixes the build.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/util/util.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index ad5418e..00f7315 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -86,17 +86,19 @@ void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
int fd;
struct statfs sfs;
void *addr;
+   unsigned long blk_size;
 
if (statfs(htlbfs_path, sfs)  0)
die(Can't stat %s\n, htlbfs_path);
 
-   if (sfs.f_type != HUGETLBFS_MAGIC) {
+   if ((unsigned int)sfs.f_type != HUGETLBFS_MAGIC) {
die(%s is not hugetlbfs!\n, htlbfs_path);
}
 
-   if (sfs.f_bsize == 0 || (unsigned long)sfs.f_bsize  size) {
+   blk_size = (unsigned long)sfs.f_bsize;
+   if (sfs.f_bsize == 0 || blk_size  size) {
die(Can't use hugetlbfs pagesize %ld for mem size %lld\n,
-   sfs.f_bsize, size);
+   blk_size, size);
}
 
snprintf(mpath, PATH_MAX, %s/kvmtoolXX, htlbfs_path);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm tools: Clean up LINT assignment code

2011-12-13 Thread Matt Evans
Hi Sasha,

On 12/12/11 06:50, Sasha Levin wrote:
 Just set delivery mode directly without going through ugly casting.
 
 This cleans up and simplifies the code.
 
 Signed-off-by: Sasha Levin levinsasha...@gmail.com
 ---
  tools/kvm/x86/kvm-cpu.c |   10 ++
  1 files changed, 2 insertions(+), 8 deletions(-)
 
 diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
 index 27b7a8f..cc1f560 100644
 --- a/tools/kvm/x86/kvm-cpu.c
 +++ b/tools/kvm/x86/kvm-cpu.c
 @@ -81,18 +81,12 @@ static int kvm_cpu__set_lint(struct kvm_cpu *vcpu)
  {
   struct kvm_lapic_state klapic;
   struct local_apic *lapic = (void *)klapic;
 - u32 lvt;
  
   if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, klapic))
   return -1;
  
 - lvt = *(u32 *)lapic-lvt_lint0;
 - lvt = SET_APIC_DELIVERY_MODE(lvt, APIC_MODE_EXTINT);
 - *(u32 *)lapic-lvt_lint0 = lvt;
 -
 - lvt = *(u32 *)lapic-lvt_lint1;
 - lvt = SET_APIC_DELIVERY_MODE(lvt, APIC_MODE_NMI);
 - *(u32 *)lapic-lvt_lint1 = lvt;
 + lapic-lvt_lint0.delivery_mode = APIC_MODE_EXTINT;
 + lapic-lvt_lint1.delivery_mode = APIC_MODE_NMI;
  
   return ioctl(vcpu-vcpu_fd, KVM_SET_LAPIC, klapic);
  }

I'm getting this on x86-32, gcc 4.4.3:

  CC   x86/kvm-cpu.o
cc1: warnings being treated as errors
x86/kvm-cpu.c: In function ‘kvm_cpu__set_lint’:
x86/kvm-cpu.c:89: error: dereferencing pointer ‘lapic’ does break 
strict-aliasing rules
x86/kvm-cpu.c:88: error: dereferencing pointer ‘lapic’ does break 
strict-aliasing rules
x86/kvm-cpu.c:83: note: initialized from here
make: *** [x86/kvm-cpu.o] Error 1

Removing the nasty aliasing (patch below) seems to be a good way to go.  What do
you think?


Cheers,


Matt

---

diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
index cc1f560..30f1ad6 100644
--- a/tools/kvm/x86/kvm-cpu.c
+++ b/tools/kvm/x86/kvm-cpu.c
@@ -79,16 +79,15 @@ void kvm_cpu__delete(struct kvm_cpu *vcpu)
 
 static int kvm_cpu__set_lint(struct kvm_cpu *vcpu)
 {
-   struct kvm_lapic_state klapic;
-   struct local_apic *lapic = (void *)klapic;
+   struct local_apic lapic;
 
-   if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, klapic))
+   if (ioctl(vcpu-vcpu_fd, KVM_GET_LAPIC, lapic))
return -1;
 
-   lapic-lvt_lint0.delivery_mode = APIC_MODE_EXTINT;
-   lapic-lvt_lint1.delivery_mode = APIC_MODE_NMI;
+   lapic.lvt_lint0.delivery_mode = APIC_MODE_EXTINT;
+   lapic.lvt_lint1.delivery_mode = APIC_MODE_NMI;
 
-   return ioctl(vcpu-vcpu_fd, KVM_SET_LAPIC, klapic);
+   return ioctl(vcpu-vcpu_fd, KVM_SET_LAPIC, lapic);
 }
 
 struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-13 Thread Matt Evans


On 14 Dec 2011, at 04:43, Pekka Enberg penb...@kernel.org wrote:

 On Tue, Dec 13, 2011 at 9:00 AM, Matt Evans m...@ozlabs.org wrote:
 +int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 +{
 +   fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
 +   dev, *num, *pin, *line);
 +   return 0;
 +}
 +
 +void irq__init(struct kvm *kvm)
 +{
 +   fprintf(stderr, __func__);
 +}
 +
 +int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
 +{
 +   die(__FUNCTION__);
 +   return 0;
 +}
 
 +void kvm__irq_line(struct kvm *kvm, int irq, int level)
 +{
 +   fprintf(stderr, irq_line(%d, %d)\n, irq, level);
 +}
 
 What's the plan with these functions? Will you need these on PPC? If
 yes, why not implement them properly now? If not, we need to drop them
 from PPC arch.

Yes, they're filled in in the later XICS patch.

Cheers,

Matt
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 0/2] kvm tools: PPC64 basic support

2011-12-13 Thread Matt Evans
On 13/12/11 21:23, Sasha Levin wrote:
 On Tue, 2011-12-13 at 18:00 +1100, Matt Evans wrote:
 The second patch is a small fix for generic virtio code (now that we have a
 PPC build) which removes reliance on ioeventfds for PPC, which doesn't 
 provide
 them. 
 
 Hm... ioeventfds are located in the generic code and should be available
 on all archs (it doesn't use any arch specific code at all afaik).
 
 Why don't they work on ppc?
 

Well, there are two problems: you're right that it's generic code, but it's
configurable and CONFIG_HAVE_KVM_EVENTFD isn't set for PPC KVM (thus the ioctl
fails).  That's probably off because ioevents won't work anyway-- the in-kernel
MMIO exit route isn't wired up to kvm_io_bus_read/write() yet.  (It looks like
KVM_IRQFD will also fail, which virtio-pci /would/ use if I supported MSIs,
which I currently don't.)

Yes, this can be fixed, but relying on it means that virtio on kvmtool/PPC won't
work on today's kernels. :(


Cheers,


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V3 0/2] kvm tools: Prepare kvmtool for another architecture

2011-12-12 Thread Matt Evans
The last remaining patches from the preparation series, with changes:
- Map from hugetlbfs does plain statfs (without odd error checking),
  checks result of ftruncate()
- Remove typo whereby kvm_cpu__emulate_mmio() calls self.

Cheers,


Matt

Matt Evans (2):
  kvm tools: Add ability to map guest RAM from hugetlbfs
  kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

 tools/kvm/builtin-run.c  |4 ++-
 tools/kvm/include/kvm/kvm.h  |4 +-
 tools/kvm/include/kvm/util.h |4 +++
 tools/kvm/kvm-cpu.c  |   34 +-
 tools/kvm/kvm.c  |4 +-
 tools/kvm/util.c |   38 ++
 tools/kvm/x86/include/kvm/kvm-cpu-arch.h |   17 -
 tools/kvm/x86/kvm.c  |   20 +--
 8 files changed, 99 insertions(+), 26 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V3 1/2] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-12 Thread Matt Evans
Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
memory (down in kvm__arch_init()).  For x86, guest memory is a normal
ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

This maps directly from a hugetlbfs temp file rather than using something
like MADV_HUGEPAGES so that, if the user asks for hugepages, we definitely
are using hugepages.  (This is particularly useful for architectures that
don't yet support KVM without hugepages, so we definitely need to use
them for the whole of guest RAM.)

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c  |4 +++-
 tools/kvm/include/kvm/kvm.h  |4 ++--
 tools/kvm/include/kvm/util.h |4 
 tools/kvm/kvm.c  |4 ++--
 tools/kvm/util.c |   38 ++
 tools/kvm/x86/kvm.c  |   20 +---
 6 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 4411c9e..ab05f8c 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -85,6 +85,7 @@ static const char *host_mac;
 static const char *script;
 static const char *guest_name;
 static const char *sandbox;
+static const char *hugetlbfs_path;
 static struct virtio_net_params *net_params;
 static bool single_step;
 static bool readonly_image[MAX_DISK_IMAGES];
@@ -437,6 +438,7 @@ static const struct option options[] = {
 tty_parser),
OPT_STRING('\0', sandbox, sandbox, script,
Run this script when booting into custom rootfs),
+   OPT_STRING('\0', hugetlbfs, hugetlbfs_path, path, Hugetlbfs 
path),
 
OPT_GROUP(Kernel options:),
OPT_STRING('k', kernel, kernel_filename, kernel,
@@ -924,7 +926,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
guest_name = default_name;
}
 
-   kvm = kvm__init(dev, ram_size, guest_name);
+   kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
 
kvm-single_step = single_step;
 
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 5fe6e75..7159952 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -30,7 +30,7 @@ struct kvm_ext {
 void kvm__set_dir(const char *fmt, ...);
 const char *kvm__get_dir(void);
 
-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name);
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
ram_size, const char *name);
 int kvm__recommended_cpus(struct kvm *kvm);
 int kvm__max_cpus(struct kvm *kvm);
 void kvm__init_ram(struct kvm *kvm);
@@ -54,7 +54,7 @@ int kvm__enumerate_instances(int (*callback)(const char 
*name, int pid));
 void kvm__remove_socket(const char *name);
 
 void kvm__arch_set_cmdline(char *cmdline, bool video);
-void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const 
char *name);
+void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char 
*hugetlbfs_path, u64 ram_size, const char *name);
 void kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
 void kvm__arch_periodic_poll(struct kvm *kvm);
diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index dc2e0b9..1f6fbbd 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -20,6 +20,7 @@
 #include limits.h
 #include sys/param.h
 #include sys/types.h
+#include linux/types.h
 
 #ifdef __GNUC__
 #define NORETURN __attribute__((__noreturn__))
@@ -75,4 +76,7 @@ static inline void msleep(unsigned int msecs)
 {
usleep(MSECS_TO_USECS(msecs));
 }
+
+void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
+
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index c54f886..35ca2c5 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -306,7 +306,7 @@ int kvm__max_cpus(struct kvm *kvm)
return ret;
 }
 
-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
ram_size, const char *name)
 {
struct kvm *kvm;
int ret;
@@ -339,7 +339,7 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, 
const char *name)
if (kvm__check_extensions(kvm))
die(A required KVM extention is not supported by OS);
 
-   kvm__arch_init(kvm, kvm_dev, ram_size, name);
+   kvm__arch_init(kvm, kvm_dev, hugetlbfs_path, ram_size, name);
 
kvm-name = name;
 
diff --git a/tools/kvm/util.c b/tools/kvm/util.c
index 4efbce9..f0a4bf7 100644
--- a/tools/kvm/util.c
+++ b/tools/kvm/util.c
@@ -4,6 +4,11 @@
 
 #include kvm/util.h
 
+#include linux/magic.h   /* For HUGETLBFS_MAGIC */
+#include sys/mman.h
+#include sys/stat.h
+#include sys/statfs.h
+
 static void report(const char *prefix, const char *err, va_list params)
 {
char msg[1024];
@@ -99,3 +104,36 @@ size_t strlcat(char *dest, const char *src

[PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2011-12-12 Thread Matt Evans
Different architectures will deal with MMIO exits differently.  For example,
KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
into windows in PCI bridges on other architectures.

This patch calls arch-specific kvm_cpu__emulate_io() and kvm_cpu__emulate_mmio()
from the main runloop's IO and MMIO exit handlers.  For x86, these directly
call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
perform some address munging before passing on the call.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm-cpu.c  |   34 +++---
 tools/kvm/x86/include/kvm/kvm-cpu-arch.h |   17 ++-
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 8ec4efa..b7ae3d3 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -52,11 +52,11 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu 
*cpu)
while (cpu-ring-first != cpu-ring-last) {
struct kvm_coalesced_mmio *m;
m = cpu-ring-coalesced_mmio[cpu-ring-first];
-   kvm__emulate_mmio(cpu-kvm,
-   m-phys_addr,
-   m-data,
-   m-len,
-   1);
+   kvm_cpu__emulate_mmio(cpu-kvm,
+ m-phys_addr,
+ m-data,
+ m-len,
+ 1);
cpu-ring-first = (cpu-ring-first + 1) % 
KVM_COALESCED_MMIO_MAX;
}
}
@@ -111,13 +111,13 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_IO: {
bool ret;
 
-   ret = kvm__emulate_io(cpu-kvm,
-   cpu-kvm_run-io.port,
-   (u8 *)cpu-kvm_run +
-   cpu-kvm_run-io.data_offset,
-   cpu-kvm_run-io.direction,
-   cpu-kvm_run-io.size,
-   cpu-kvm_run-io.count);
+   ret = kvm_cpu__emulate_io(cpu-kvm,
+ cpu-kvm_run-io.port,
+ (u8 *)cpu-kvm_run +
+ cpu-kvm_run-io.data_offset,
+ cpu-kvm_run-io.direction,
+ cpu-kvm_run-io.size,
+ cpu-kvm_run-io.count);
 
if (!ret)
goto panic_kvm;
@@ -126,11 +126,11 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_MMIO: {
bool ret;
 
-   ret = kvm__emulate_mmio(cpu-kvm,
-   cpu-kvm_run-mmio.phys_addr,
-   cpu-kvm_run-mmio.data,
-   cpu-kvm_run-mmio.len,
-   cpu-kvm_run-mmio.is_write);
+   ret = kvm_cpu__emulate_mmio(cpu-kvm,
+   
cpu-kvm_run-mmio.phys_addr,
+   cpu-kvm_run-mmio.data,
+   cpu-kvm_run-mmio.len,
+   
cpu-kvm_run-mmio.is_write);
 
if (!ret)
goto panic_kvm;
diff --git a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
index 822d966..198efe6 100644
--- a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
@@ -4,7 +4,8 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include kvm/kvm.h   /* for kvm__emulate_{mm}io() */
+#include stdbool.h
 #include pthread.h
 
 struct kvm;
@@ -31,4 +32,18 @@ struct kvm_cpu {
struct kvm_coalesced_mmio_ring  *ring;
 };
 
+/*
+ * As these are such simple wrappers, let's have them in the header so they'll
+ * be cheaper to call:
+ */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return kvm__emulate_io(kvm, port, data, direction, size, count);
+}
+
+static inline bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 
*data, u32 len, u8 is_write)
+{
+   return kvm__emulate_mmio(kvm, phys_addr, data, len, is_write);
+}
+
 #endif /* KVM__KVM_CPU_ARCH_H */
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body

Re: [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and link appropriately

2011-12-12 Thread Matt Evans
Hi Pekka,

On 09/12/11 17:53, Matt Evans wrote:
 kvmtool's types.h includes asm/types.h, which by default on PPC64 brings in
 int-l64.h; define __SANE_USERSPACE_TYPES__ to get LL64 types.
 
 This patch also adds CFLAGS to the final link, so that any -m64 is obeyed
 when linking, too.

Just noticed this patch wasn't included in what you committed from this series,
but is required for the PPC64 series to build.

I'm waiting on an ack on the /other/ patch (that adds SANE_USERSPACE_TYPES to
PPC64 headers); I have a verbal one, but on-list is better :-)  But, /this/ 
patch
is somewhat independent from that.

If you're waiting so they can both go in together, then that's fine too.  Just
a reminder.


Cheers,


Matt


 
 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
  tools/kvm/Makefile  |2 +-
  tools/kvm/include/linux/types.h |1 +
  2 files changed, 2 insertions(+), 1 deletions(-)
 
 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 009a6ba..57dc521 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -218,7 +218,7 @@ KVMTOOLS-VERSION-FILE:
  
  $(PROGRAM): $(DEPS) $(OBJS)
   $(E)   LINK $@
 - $(Q) $(CC) $(OBJS) $(LIBS) -o $@
 + $(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  
  $(GUEST_INIT): guest/init.c
   $(E)   LINK $@
 diff --git a/tools/kvm/include/linux/types.h b/tools/kvm/include/linux/types.h
 index 357799c..5e20f10 100644
 --- a/tools/kvm/include/linux/types.h
 +++ b/tools/kvm/include/linux/types.h
 @@ -2,6 +2,7 @@
  #define LINUX_TYPES_H
  
  #include kvm/compiler.h
 +#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
  #include asm/types.h
  
  typedef __u64 u64;
 --
 To unsubscribe from this list: send the line unsubscribe kvm in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 0/2] kvm tools: PPC64 basic support

2011-12-12 Thread Matt Evans
These two patches build on the previous split out arch-specific work.  The
first adds a PPC64 build, basic CPU support, guest RAM mapping (using 
hugepages),
flat kernel loading and all required arch-specific definitions  structures.

With patches to date, this should build PPC but not necessarily run much.
Subsequent patches add support to emulate an SPAPR-esque machine.

This patch does not include any code borrowed from outside kvmtool.

The second patch is a small fix for generic virtio code (now that we have a
PPC build) which removes reliance on ioeventfds for PPC, which doesn't provide
them.

Matt Evans (2):
  kvm tools: Add initial SPAPR PPC64 architecture support
  kvm tools: Make virtio-pci's ioeventfd__add_event() fall back
gracefully if ioeventfds unavailable

 tools/kvm/Makefile   |   10 +
 tools/kvm/include/kvm/ioeventfd.h|3 +-
 tools/kvm/ioeventfd.c|   12 +-
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 tools/kvm/virtio/pci.c   |   13 ++-
 12 files changed, 658 insertions(+), 5 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 2/2] kvm tools: Make virtio-pci's ioeventfd__add_event() fall back gracefully if ioeventfds unavailable

2011-12-12 Thread Matt Evans
Some KVM implementations (e.g. PPC) don't yet support ioeventfds, so don't
bomb out/die.  virtio-pci is able to function if it instead uses normal IO
port notification.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile|2 +-
 tools/kvm/include/kvm/ioeventfd.h |3 ++-
 tools/kvm/ioeventfd.c |   12 +---
 tools/kvm/virtio/pci.c|   13 -
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 3f1e84a..5bb3f08 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -126,7 +126,7 @@ ifeq ($(ARCH),x86)
 endif
 # POWER/ppc:  Actually only support ppc64 currently.
 ifeq ($(uname_M), ppc64)
-   DEFINES += -DCONFIG_PPC
+   DEFINES += -DCONFIG_PPC -DCONFIG_NO_IOEVENTFDS
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
diff --git a/tools/kvm/include/kvm/ioeventfd.h 
b/tools/kvm/include/kvm/ioeventfd.h
index df01750..5e458be 100644
--- a/tools/kvm/include/kvm/ioeventfd.h
+++ b/tools/kvm/include/kvm/ioeventfd.h
@@ -4,6 +4,7 @@
 #include linux/types.h
 #include linux/list.h
 #include sys/eventfd.h
+#include stdbool.h
 
 struct kvm;
 
@@ -21,7 +22,7 @@ struct ioevent {
 
 void ioeventfd__init(void);
 void ioeventfd__start(void);
-void ioeventfd__add_event(struct ioevent *ioevent);
+bool ioeventfd__add_event(struct ioevent *ioevent);
 void ioeventfd__del_event(u64 addr, u64 datamatch);
 
 #endif
diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 3a240e4..37f9a63 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/ioeventfd.c
@@ -26,7 +26,7 @@ void ioeventfd__init(void)
die(Failed creating epoll fd);
 }
 
-void ioeventfd__add_event(struct ioevent *ioevent)
+bool ioeventfd__add_event(struct ioevent *ioevent)
 {
struct kvm_ioeventfd kvm_ioevent;
struct epoll_event epoll_event;
@@ -48,8 +48,13 @@ void ioeventfd__add_event(struct ioevent *ioevent)
.flags  = KVM_IOEVENTFD_FLAG_PIO | 
KVM_IOEVENTFD_FLAG_DATAMATCH,
};
 
-   if (ioctl(ioevent-fn_kvm-vm_fd, KVM_IOEVENTFD, kvm_ioevent) != 0)
-   die(Failed creating new ioeventfd);
+   if (ioctl(ioevent-fn_kvm-vm_fd, KVM_IOEVENTFD, kvm_ioevent) != 0) {
+   /* Not all KVM implementations may support KVM_IOEVENTFD,
+* so be graceful.
+*/
+   free(new_ioevent);
+   return false;
+   }
 
epoll_event = (struct epoll_event) {
.events = EPOLLIN,
@@ -60,6 +65,7 @@ void ioeventfd__add_event(struct ioevent *ioevent)
die(Failed assigning new event to the epoll fd);
 
list_add_tail(new_ioevent-list, used_ioevents);
+   return true;
 }
 
 void ioeventfd__del_event(u64 addr, u64 datamatch)
diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c
index a7da8e8..56fa4ad 100644
--- a/tools/kvm/virtio/pci.c
+++ b/tools/kvm/virtio/pci.c
@@ -7,6 +7,7 @@
 #include kvm/virtio.h
 #include kvm/ioeventfd.h
 #include kvm/virtio-trans.h
+#include kvm/util.h
 
 #include linux/virtio_pci.h
 #include linux/byteorder.h
@@ -50,7 +51,17 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, 
struct virtio_trans *vtra
.fd = eventfd(0, 0),
};
 
-   ioeventfd__add_event(ioevent);
+   if (!ioeventfd__add_event(ioevent)) {
+#ifndef CONFIG_NO_IOEVENTFDS
+   /*
+* ioevents aren't supported on all KVM implementations, so we
+* expect this to fail -- don't need to be verbose about it!
+* For virtio-pci, this is fine.  It catches the IO accesses
+* anyway, so still works (but slower).
+*/
+   pr_warning(Failed creating new ioeventfd);
+#endif
+   }
 
if (vtrans-virtio_ops-notify_vq_eventfd)
vtrans-virtio_ops-notify_vq_eventfd(kvm, vpci-dev, vq, 
ioevent.fd);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-12 Thread Matt Evans
This patch adds a new arch directory, powerpc, basic file structure, register
setup and where necessary stubs out arch-specific functions (e.g. interrupts,
runloop exits) that later patches will provide.  The target is an
SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 or
'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls and
RTAS required to boot SPAPR pSeries kernels.

Memory is mapped from hugetlbfs (as that is currently required by upstream PPC64
HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this is
only necessary on processors that don't support VRMA, e.g. = P6.  Work is
therefore needed to get this going on pre-P7 CPUs.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

Finally, support is added for simply loading flat binary kernels (plus initrd).
(bzImages are not used on PPC, and this series does not add zImage support or an
ELF loader.)  The intention is to later support loading firmware such as SLOF.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 2bf70c9..3f1e84a 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
OTHEROBJS   += x86/bios/bios-rom.o
ARCH_INCLUDE := x86/include
 endif
+# POWER/ppc:  Actually only support ppc64 currently.
+ifeq ($(uname_M), ppc64)
+   DEFINES += -DCONFIG_PPC
+   OBJS+= powerpc/ioport.o
+   OBJS+= powerpc/irq.o
+   OBJS+= powerpc/kvm.o
+   OBJS+= powerpc/kvm-cpu.o
+   ARCH_INCLUDE := powerpc/include
+   CFLAGS += -m64
+endif
 
 ###
 
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 35ca2c5..3fb46f6 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
+#ifdef CONFIG_PPC64
+   DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
+#endif
 };
 
 extern struct kvm *kvm;
diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
b/tools/kvm/powerpc/include/kvm/barrier.h
new file mode 100644
index 000..bc7d179
--- /dev/null
+++ b/tools/kvm/powerpc/include/kvm/barrier.h
@@ -0,0 +1,6 @@
+#ifndef _KVM_BARRIER_H_
+#define _KVM_BARRIER_H_
+
+#include asm/system.h
+
+#endif /* _KVM_BARRIER_H_ */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
new file mode 100644
index 000..da61774
--- /dev/null
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -0,0 +1,72 @@
+/*
+ * PPC64 architecture-specific definitions
+ *
+ * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#ifndef KVM__KVM_ARCH_H
+#define KVM__KVM_ARCH_H
+
+#include stdbool.h
+#include linux/types.h
+#include time.h
+
+#define KVM_NR_CPUS(255)
+
+/*
+ * MMIO lives after RAM, but it'd be nice if it didn't constantly move.
+ * Choose a suitably high address, e.g. 63T...  This limits RAM size.
+ */
+#define PPC_MMIO_START 0x3F00UL
+#define PPC_MMIO_SIZE  0x0100UL
+
+#define KERNEL_LOAD_ADDR   0x
+#define KERNEL_START_ADDR  0x
+#define KERNEL_SECONDARY_START_ADDR 0x0060
+#define INITRD_LOAD_ADDR   0x0280
+
+#define FDT_MAX_SIZE   0x1
+#define RTAS_MAX_SIZE  0x1
+
+#define TIMEBASE_FREQ  51200ULL
+
+#define KVM_MMIO_START PPC_MMIO_START
+
+/*
+ * This is the address that pci_get_io_space_block() starts allocating
+ * from.  Note that this is a PCI bus address

[PATCH V2 0/6] Add initial SPAPR PPC64 architecture support

2011-12-12 Thread Matt Evans
This series adds support for a PPC64 platform, SPAPR, on top of the previous
more general PPC64 CPU support.  This platform is paravirtualised, with most
of the MMU hypercalls being dealt with in the kernel.  Userland needs to
describe the environment to the machine with a device tree, cope with some
hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate
the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque
machine.

With this series, normal pSeries kernels boot fine (including RH kernels that
include virtio support out of the box).  There is no support for PPC32 or
'bare metal' PPC64 guests as yet.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

The kernels are loaded as flat binaries and booted directly.  The intention
is to later support loading firmware such as SLOF.

Some of the code within is borrowed/based upon code in QEMU, particularly
the XICS emulation, device tree construction and PCI setup.


Matt Evans (6):
  kvm tools: Generate SPAPR PPC64 guest device tree
  kvm tools: Add SPAPR PPC64 hcall  rtascall structure
  kvm tools: Add SPAPR PPC64 HV console
  kvm tools: Add PPC64 XICS interrupt controller support
  kvm tools: Add PPC64 PCI Host Bridge
  kvm tools: Add PPC64 kvm_cpu__emulate_io()

 tools/kvm/Makefile   |8 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   14 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   12 +-
 tools/kvm/powerpc/irq.c  |   35 ++-
 tools/kvm/powerpc/kvm-cpu.c  |   46 +++
 tools/kvm/powerpc/kvm.c  |  255 +-
 tools/kvm/powerpc/spapr.h|  111 ++
 tools/kvm/powerpc/spapr_hcall.c  |  132 +++
 tools/kvm/powerpc/spapr_hvcons.c |  102 +
 tools/kvm/powerpc/spapr_hvcons.h |   19 +
 tools/kvm/powerpc/spapr_pci.c|  423 +
 tools/kvm/powerpc/spapr_pci.h|   38 ++
 tools/kvm/powerpc/spapr_rtas.c   |  230 
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 15 files changed, 1952 insertions(+), 10 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 1/6] kvm tools: Generate SPAPR PPC64 guest device tree

2011-12-12 Thread Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which
subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.

Some aspects are currently hardwired for simplicity, for example advertised
page sizes, HPT size, SLB size, VMX/DFP, etc.  Future support of a variety
of POWER CPUs should acquire this info from the host and encode appropriately.

This requires a 64-bit libfdt.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |3 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   10 ++
 tools/kvm/powerpc/kvm.c  |  141 ++
 3 files changed, 153 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 5bb3f08..4ee4805 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -132,7 +132,8 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm.o
OBJS+= powerpc/kvm-cpu.o
ARCH_INCLUDE := powerpc/include
-   CFLAGS += -m64
+   CFLAGS  += -m64
+   LIBS+= -lfdt
 endif
 
 ###
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index da61774..33a3827 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -69,4 +69,14 @@ struct kvm {
const char  *name;
 };
 
+/* Helper for the various bits of code that generate FDT nodes */
+#define _FDT(exp)  \
+   do {\
+   int ret = (exp);\
+   if (ret  0) {  \
+   die(Error creating device tree: %s: %s\n, \
+   #exp, fdt_strerror(ret));   \
+   }   \
+   } while (0)
+
 #endif /* KVM__KVM_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index f838a8f..95ed1cc 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
  *
+ * Portions of FDT setup borrowed from QEMU, copyright 2010 David Gibson, IBM
+ * Corporation.
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
  * by the Free Software Foundation.
@@ -29,6 +32,8 @@
 #include linux/byteorder.h
 #include libfdt.h
 
+#define HPT_ORDER 24
+
 #define HUGETLBFS_PATH /var/lib/hugetlbfs/global/pagesize-16MB/
 
 static char kern_cmdline[2048];
@@ -168,9 +173,145 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
return false;
 }
 
+#define SMT_THREADS 4
+
+static uint32_t mfpvr(void)
+{
+   uint32_t r;
+   asm volatile (mfpvr %0 : =r(r));
+   return r;
+}
+
 static void setup_fdt(struct kvm *kvm)
 {
+   uint64_tmem_reg_property[] = { 0, cpu_to_be64(kvm-ram_size) };
+   int smp_cpus = kvm-nrcpus;
+   charhypertas_prop_kvm[] = hcall-pft\0hcall-term\0
+   hcall-dabr\0hcall-interrupt\0hcall-tce\0hcall-vio\0
+   hcall-splpar\0hcall-bulk;
+   int i, j;
+   charcpu_name[30];
+   u8  staging_fdt[FDT_MAX_SIZE];
+   uint32_tpvr = mfpvr();
+
+   /* Generate an appropriate DT at kvm-fdt_gra */
+   void *fdt_dest = guest_flat_to_host(kvm, kvm-fdt_gra);
+   void *fdt = staging_fdt;
+
+   _FDT(fdt_create(fdt, FDT_MAX_SIZE));
+   _FDT(fdt_finish_reservemap(fdt));
+
+   _FDT(fdt_begin_node(fdt, ));
+
+   _FDT(fdt_property_string(fdt, device_type, chrp));
+   _FDT(fdt_property_string(fdt, model, IBM pSeries (kvmtool)));
+   _FDT(fdt_property_cell(fdt, #address-cells, 0x2));
+   _FDT(fdt_property_cell(fdt, #size-cells, 0x2));
+
+   /* /chosen */
+   _FDT(fdt_begin_node(fdt, chosen));
+   /* cmdline */
+   _FDT(fdt_property_string(fdt, bootargs, kern_cmdline));
+   /* Initrd */
+   if (kvm-initrd_size != 0) {
+   uint32_t ird_st_prop = cpu_to_be32(kvm-initrd_gra);
+   uint32_t ird_end_prop = cpu_to_be32(kvm-initrd_gra +
+   kvm-initrd_size);
+   _FDT(fdt_property(fdt, linux,initrd-start,
+  ird_st_prop, sizeof(ird_st_prop)));
+   _FDT(fdt_property(fdt, linux,initrd-end,
+  ird_end_prop, sizeof(ird_end_prop)));
+   }
+   _FDT(fdt_end_node(fdt));
+
+   /*
+* Memory: We don't alloc. a separate RMA yet.  If we ever need to
+* (CAP_PPC_RMA == 2) then have one memory node for 0-RMAsize, and
+* another RMAsize-endOfMem.
+*/
+   _FDT(fdt_begin_node(fdt, memory@0));
+   _FDT

[PATCH V2 2/6] kvm tools: Add SPAPR PPC64 hcall rtascall structure

2011-12-12 Thread Matt Evans
This patch adds the basic structure for HV calls, their registration and some of
the simpler calls.  A similar layout for RTAS calls is also added, again with
some of the simpler RTAS calls used by the guest.  The SPAPR RTAS stub is
generated inline.  Also, nodes for RTAS are added to the device tree.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile  |2 +
 tools/kvm/powerpc/kvm-cpu.c |6 +
 tools/kvm/powerpc/kvm.c |   46 -
 tools/kvm/powerpc/spapr.h   |  105 ++
 tools/kvm/powerpc/spapr_hcall.c |  132 ++
 tools/kvm/powerpc/spapr_rtas.c  |  230 +++
 6 files changed, 520 insertions(+), 1 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 4ee4805..e2a7190 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -131,6 +131,8 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
OBJS+= powerpc/kvm-cpu.o
+   OBJS+= powerpc/spapr_hcall.o
+   OBJS+= powerpc/spapr_rtas.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
LIBS+= -lfdt
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index ea99666..ef3db4d 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -14,6 +14,8 @@
 #include kvm/util.h
 #include kvm/kvm.h
 
+#include spapr.h
+
 #include sys/ioctl.h
 #include sys/mman.h
 #include signal.h
@@ -150,6 +152,10 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
bool ret = true;
struct kvm_run *run = vcpu-kvm_run;
switch(run-exit_reason) {
+   case KVM_EXIT_PAPR_HCALL:
+   run-papr_hcall.ret = spapr_hypercall(vcpu, run-papr_hcall.nr,
+ 
(target_ulong*)run-papr_hcall.args);
+   break;
default:
ret = false;
}
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 95ed1cc..b3570a9 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -14,6 +14,8 @@
 #include kvm/kvm.h
 #include kvm/util.h
 
+#include spapr.h
+
 #include linux/kvm.h
 
 #include sys/types.h
@@ -106,6 +108,11 @@ void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, 
const char *hugetlbfs_
if (cap_ppc_rma == 2)
die(Need contiguous RMA allocation on this hardware, 
which is not yet supported.);
+
+   /* Do these before FDT setup, IRQ setup, etc. */
+   /* FIXME: SPAPR-specific */
+   hypercall_init();
+   register_core_rtas();
 }
 
 void kvm__irq_line(struct kvm *kvm, int irq, int level)
@@ -182,6 +189,11 @@ static uint32_t mfpvr(void)
return r;
 }
 
+/*
+ * Set up the FDT for the kernel: This function is currently fairly 
SPAPR-heavy,
+ * and whilst most PPC targets will require CPU/memory nodes, others like RTAS
+ * should eventually be added separately.
+ */
 static void setup_fdt(struct kvm *kvm)
 {
uint64_tmem_reg_property[] = { 0, cpu_to_be64(kvm-ram_size) };
@@ -208,6 +220,20 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property_cell(fdt, #address-cells, 0x2));
_FDT(fdt_property_cell(fdt, #size-cells, 0x2));
 
+   /* RTAS */
+   _FDT(fdt_begin_node(fdt, rtas));
+   /* This is what the kernel uses to switch 'We're an LPAR'! */
+_FDT(fdt_property(fdt, ibm,hypertas-functions, hypertas_prop_kvm,
+   sizeof(hypertas_prop_kvm)));
+   _FDT(fdt_property_cell(fdt, linux,rtas-base, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, linux,rtas-entry, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, rtas-size, kvm-rtas_size));
+   /* Now add properties for all RTAS tokens: */
+   if (spapr_rtas_fdt_setup(kvm, fdt))
+   die(Couldn't create RTAS FDT properties\n);
+
+   _FDT(fdt_end_node(fdt));
+
/* /chosen */
_FDT(fdt_begin_node(fdt, chosen));
/* cmdline */
@@ -319,7 +345,25 @@ static void setup_fdt(struct kvm *kvm)
  */
 void kvm__arch_setup_firmware(struct kvm *kvm)
 {
-   /* Load RTAS */
+   /*
+* Set up RTAS stub.  All it is is a single hypercall:
+*  0:   7c 64 1b 78 mr  r4,r3
+*  4:   3c 60 00 00 lis r3,0
+*  8:   60 63 f0 00 ori r3,r3,61440
+*  c:   44 00 00 22 sc  1
+* 10:   4e 80 00 20 blr
+*/
+   uint32_t *rtas = guest_flat_to_host(kvm, kvm-rtas_gra);
+
+   rtas[0] = 0x7c641b78;
+   rtas[1] = 0x3c60;
+   rtas[2] = 0x6063f000;
+   rtas[3] = 0x4422;
+   rtas[4] = 0x4e800020;
+   kvm-rtas_size = 20;
+
+   pr_info(Set up %ld bytes of RTAS at 0x%lx\n,
+   kvm-rtas_size, kvm-rtas_gra

[PATCH V2 6/6] kvm tools: Add PPC64 kvm_cpu__emulate_io()

2011-12-12 Thread Matt Evans
This is the final piece of the puzzle for PPC SPAPR PCI; this
function splits MMIO accesses into the two PHB windows  directs
things to MMIO/IO emulation as appropriate.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   10 -
 tools/kvm/powerpc/kvm-cpu.c  |   29 ++
 3 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 0d42acf..6f3485b 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -134,6 +134,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/spapr_pci.o
OBJS+= powerpc/xics.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index c1c6539..7520c04 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -14,7 +14,7 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include stdbool.h
 #include pthread.h
 
 #define MSR_SF (1UL63)
@@ -65,4 +65,12 @@ struct kvm_cpu {
 
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level);
 
+/* This is never actually called on PPC. */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return false;
+}
+
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write);
+
 #endif /* KVM__KVM_CPU_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 5ef1cbf..4da4990 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -24,6 +24,7 @@
 #include string.h
 #include errno.h
 #include stdio.h
+#include assert.h
 
 static int debug_fd;
 
@@ -173,6 +174,34 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
return ret;
 }
 
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write)
+{
+   /*
+* FIXME: This function will need to be split in order to support
+* various PowerPC platforms/PHB types, etc.  It currently assumes SPAPR
+* PPC64 guest.
+*/
+   bool ret = false;
+
+   if ((phys_addr = SPAPR_PCI_IO_WIN_ADDR) 
+   (phys_addr  SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)) {
+   ret = kvm__emulate_io(kvm, phys_addr - SPAPR_PCI_IO_WIN_ADDR,
+ data, is_write ? KVM_EXIT_IO_OUT :
+ KVM_EXIT_IO_IN,
+ len, 1);
+   } else if ((phys_addr = SPAPR_PCI_MEM_WIN_ADDR) 
+  (phys_addr  SPAPR_PCI_MEM_WIN_ADDR +
+   SPAPR_PCI_MEM_WIN_SIZE)) {
+   ret = kvm__emulate_mmio(kvm, phys_addr - SPAPR_PCI_MEM_WIN_ADDR,
+   data, len, is_write);
+   } else {
+   pr_warning(MMIO %s unknown address %llx (size %d)!\n,
+  is_write ? write to : read from,
+  phys_addr, len);
+   }
+   return ret;
+}
+
 #define CONDSTR_BIT(m, b) (((m)  MSR_##b) ? #b  : )
 
 void kvm_cpu__show_registers(struct kvm_cpu *vcpu)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 5/6] kvm tools: Add PPC64 PCI Host Bridge

2011-12-12 Thread Matt Evans
This provides the PCI bridge, definitions for the address layout of the windows
and wires in IRQs.  Once PCI devices are all registered, they are enumerated and
DT nodes generated for each.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/powerpc/include/kvm/kvm-arch.h |3 +
 tools/kvm/powerpc/irq.c  |   18 ++-
 tools/kvm/powerpc/kvm.c  |   11 +
 tools/kvm/powerpc/spapr.h|6 +
 tools/kvm/powerpc/spapr_pci.c|  423 ++
 tools/kvm/powerpc/spapr_pci.h|   38 +++
 6 files changed, 497 insertions(+), 2 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h

diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index e070c3f..26e3231 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -42,6 +42,8 @@
  */
 #define KVM_PCI_MMIO_AREA  0x100
 
+struct spapr_phb;
+
 struct kvm {
int sys_fd; /* For system ioctls(), i.e. 
/dev/kvm */
int vm_fd;  /* For VM ioctls() */
@@ -68,6 +70,7 @@ struct kvm {
unsigned long   initrd_size;
const char  *name;
struct icp_state*icp;
+   struct spapr_phb*phb;
 };
 
 /* Helper for the various bits of code that generate FDT nodes */
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index a1047d4..dbe1ad2 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -21,7 +21,10 @@
 #include stddef.h
 #include stdlib.h
 
+#include kvm/pci.h
+
 #include xics.h
+#include spapr_pci.h
 
 #define XICS_IRQS   1024
 
@@ -30,10 +33,21 @@
  * generic  cope with multiple PPC platform types.
  */
 
+static int pci_devs = 0;
+
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
-   fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
-   dev, *num, *pin, *line);
+   if (pci_devs = PCI_MAX_DEVICES)
+   die(Hit PCI device limit!\n);
+
+   *num = pci_devs++;
+
+   *pin = 1;
+   /*
+* Have I said how nasty I find this?  Line should be dontcare... PHB
+* should determine which CPU/XICS IRQ to fire.
+*/
+   *line = xics_alloc_irqnum();
return 0;
 }
 
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 30443c7..ebd1845 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -16,6 +16,7 @@
 
 #include spapr.h
 #include spapr_hvcons.h
+#include spapr_pci.h
 
 #include linux/kvm.h
 
@@ -120,6 +121,11 @@ void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, 
const char *hugetlbfs_
register_core_rtas();
/* Now that hypercalls are initialised, register a couple for the 
console: */
spapr_hvcons_init();
+   spapr_create_phb(kvm, pci, SPAPR_PCI_BUID,
+SPAPR_PCI_MEM_WIN_ADDR,
+SPAPR_PCI_MEM_WIN_SIZE,
+SPAPR_PCI_IO_WIN_ADDR,
+SPAPR_PCI_IO_WIN_SIZE);
 }
 
 void kvm__irq_trigger(struct kvm *kvm, int irq)
@@ -385,6 +391,11 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_finish(fdt));
 
_FDT(fdt_open_into(fdt, fdt_dest, FDT_MAX_SIZE));
+
+   /* PCI */
+   if (spapr_populate_pci_devices(kvm, PHANDLE_XICP, fdt_dest))
+   die(Fail populating PCI device nodes);
+
_FDT(fdt_add_mem_rsv(fdt_dest, kvm-rtas_gra, kvm-rtas_size));
_FDT(fdt_pack(fdt_dest));
 }
diff --git a/tools/kvm/powerpc/spapr.h b/tools/kvm/powerpc/spapr.h
index 57cece1..731668c 100644
--- a/tools/kvm/powerpc/spapr.h
+++ b/tools/kvm/powerpc/spapr.h
@@ -102,4 +102,10 @@ target_ulong spapr_rtas_call(struct kvm_cpu *vcpu,
  uint32_t token, uint32_t nargs, target_ulong args,
  uint32_t nret, target_ulong rets);
 
+#define SPAPR_PCI_BUID  0x8002001ULL
+#define SPAPR_PCI_MEM_WIN_ADDR  (KVM_MMIO_START + 0xA000)
+#define SPAPR_PCI_MEM_WIN_SIZE  0x2000
+#define SPAPR_PCI_IO_WIN_ADDR   (KVM_MMIO_START + 0x8000)
+#define SPAPR_PCI_IO_WIN_SIZE  0x200
+
 #endif /* !defined (__HW_SPAPR_H__) */
diff --git a/tools/kvm/powerpc/spapr_pci.c b/tools/kvm/powerpc/spapr_pci.c
new file mode 100644
index 000..445a02a
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_pci.c
@@ -0,0 +1,423 @@
+/*
+ * SPAPR PHB emulation, RTAS interface to PCI config space, device tree nodes
+ * for enumerated devices.
+ *
+ * Borrowed heavily from QEMU's spapr_pci.c,
+ * Copyright (c) 2011 Alexey Kardashevskiy, IBM Corporation.
+ * Copyright (c) 2011 David Gibson, IBM Corporation.
+ *
+ * Modifications copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU

[PATCH V2 4/6] kvm tools: Add PPC64 XICS interrupt controller support

2011-12-12 Thread Matt Evans
This patch adds XICS emulation code (heavily borrowed from QEMU), and wires
this into kvm_cpu__irq() to fire a CPU IRQ via KVM.  A device tree entry is
also added.  IPIs work, xics_alloc_irqnum() is added to allocate an external
IRQ (which will later be used by the PHB PCI code) and finally, kvm__irq_line()
can be called to raise an IRQ on XICS.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |2 +
 tools/kvm/powerpc/irq.c  |   17 +-
 tools/kvm/powerpc/kvm-cpu.c  |   11 +
 tools/kvm/powerpc/kvm.c  |   26 +-
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 8 files changed, 589 insertions(+), 6 deletions(-)
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 0a576be..0d42acf 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -134,6 +134,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/xics.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
LIBS+= -lfdt
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 33a3827..e070c3f 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -67,6 +67,7 @@ struct kvm {
unsigned long   initrd_gra;
unsigned long   initrd_size;
const char  *name;
+   struct icp_state*icp;
 };
 
 /* Helper for the various bits of code that generate FDT nodes */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index 64e4510..c1c6539 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -36,6 +36,8 @@
 #define MSR_RI (1UL1)
 #define MSR_LE (1UL0)
 
+#define POWER7_EXT_IRQ 0
+
 struct kvm;
 
 struct kvm_cpu {
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index 46aa64f..a1047d4 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -21,6 +21,15 @@
 #include stddef.h
 #include stdlib.h
 
+#include xics.h
+
+#define XICS_IRQS   1024
+
+/*
+ * FIXME: The code in this file assumes an SPAPR guest, using XICS.  Make
+ * generic  cope with multiple PPC platform types.
+ */
+
 int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 {
fprintf(stderr, irq__register_device(%d, [%d], [%d], [%d]\n,
@@ -30,7 +39,13 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)
 
 void irq__init(struct kvm *kvm)
 {
-   fprintf(stderr, __func__);
+   /*
+* kvm-nr_cpus is now valid; for /now/, pass
+* this to xics_system_init(), which assumes servers
+* are numbered 0..nrcpus.  This may not really be true,
+* but it is OK currently.
+*/
+   kvm-icp = xics_system_init(XICS_IRQS, kvm-nrcpus);
 }
 
 int irq__add_msix_route(struct kvm *kvm, struct msi_msg *msg)
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index ef3db4d..5ef1cbf 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -15,6 +15,7 @@
 #include kvm/kvm.h
 
 #include spapr.h
+#include xics.h
 
 #include sys/ioctl.h
 #include sys/mman.h
@@ -89,6 +90,9 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long 
cpu_id)
 */
vcpu-is_running = true;
 
+   /* Register with IRQ controller (FIXME, assumes XICS) */
+   xics_cpu_register(vcpu);
+
return vcpu;
 }
 
@@ -141,6 +145,13 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)
 /* kvm_cpu__irq - set KVM's IRQ flag on this vcpu */
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level)
 {
+   unsigned int virq = level ? KVM_INTERRUPT_SET_LEVEL : 
KVM_INTERRUPT_UNSET;
+
+   /* FIXME: POWER-specific */
+   if (pin != POWER7_EXT_IRQ)
+   return;
+   if (ioctl(vcpu-vcpu_fd, KVM_INTERRUPT, virq)  0)
+   pr_warning(Could not KVM_INTERRUPT.);
 }
 
 void kvm_cpu__arch_nmi(struct kvm_cpu *cpu)
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 06fccef..30443c7 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -39,9 +39,13 @@
 
 #define HUGETLBFS_PATH /var/lib/hugetlbfs/global/pagesize-16MB/
 
+#define PHANDLE_XICP   0x
+
 static char kern_cmdline[2048];
 
 struct kvm_ext kvm_req_ext[] = {
+   { DEFINE_KVM_EXT(KVM_CAP_PPC_UNSET_IRQ) },
+   { DEFINE_KVM_EXT(KVM_CAP_PPC_IRQ_LEVEL) },
{ 0, 0 }
 };
 
@@ -118,11 +122,6 @@ void kvm__arch_init(struct kvm *kvm, const char

[PATCH V2 3/6] kvm tools: Add SPAPR PPC64 HV console

2011-12-12 Thread Matt Evans
This adds the console code, plus VIO HV terminal nodes are added to
the device tree so the guest kernel will pick it up.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/kvm.c  |   33 
 tools/kvm/powerpc/spapr_hvcons.c |  102 ++
 tools/kvm/powerpc/spapr_hvcons.h |   19 +++
 4 files changed, 155 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index e2a7190..0a576be 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -133,6 +133,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm-cpu.o
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
+   OBJS+= powerpc/spapr_hvcons.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
LIBS+= -lfdt
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index b3570a9..06fccef 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -15,6 +15,7 @@
 #include kvm/util.h
 
 #include spapr.h
+#include spapr_hvcons.h
 
 #include linux/kvm.h
 
@@ -113,6 +114,8 @@ void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, 
const char *hugetlbfs_
/* FIXME: SPAPR-specific */
hypercall_init();
register_core_rtas();
+   /* Now that hypercalls are initialised, register a couple for the 
console: */
+   spapr_hvcons_init();
 }
 
 void kvm__irq_line(struct kvm *kvm, int irq, int level)
@@ -126,6 +129,12 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
kvm__irq_line(kvm, irq, 0);
 }
 
+void kvm__arch_periodic_poll(struct kvm *kvm)
+{
+   /* FIXME: Should register callbacks to platform-specific polls */
+   spapr_hvcons_poll(kvm);
+}
+
 int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline)
 {
void *p;
@@ -248,6 +257,13 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property(fdt, linux,initrd-end,
   ird_end_prop, sizeof(ird_end_prop)));
}
+
+   /*
+* stdout-path: This is assuming we're using the HV console.  Also, the
+* address is hardwired until we do a VIO bus.
+*/
+   _FDT(fdt_property_string(fdt, linux,stdout-path,
+/vdevice/vty@3000));
_FDT(fdt_end_node(fdt));
 
/*
@@ -331,6 +347,23 @@ static void setup_fdt(struct kvm *kvm)
}
_FDT(fdt_end_node(fdt));
 
+   /*
+* VIO: See comment in linux,stdout-path; we don't yet represent a VIO
+* bus/address allocation so addresses are hardwired here.
+*/
+   _FDT(fdt_begin_node(fdt, vdevice));
+   _FDT(fdt_property_cell(fdt, #address-cells, 0x1));
+   _FDT(fdt_property_cell(fdt, #size-cells, 0x0));
+   _FDT(fdt_property_string(fdt, device_type, vdevice));
+   _FDT(fdt_property_string(fdt, compatible, IBM,vdevice));
+   _FDT(fdt_begin_node(fdt, vty@3000));
+   _FDT(fdt_property_string(fdt, name, vty));
+   _FDT(fdt_property_string(fdt, device_type, serial));
+   _FDT(fdt_property_string(fdt, compatible, hvterm1));
+   _FDT(fdt_property_cell(fdt, reg, 0x3000));
+   _FDT(fdt_end_node(fdt));
+   _FDT(fdt_end_node(fdt));
+
/* Finalise: */
_FDT(fdt_end_node(fdt)); /* Root node */
_FDT(fdt_finish(fdt));
diff --git a/tools/kvm/powerpc/spapr_hvcons.c b/tools/kvm/powerpc/spapr_hvcons.c
new file mode 100644
index 000..511dbe1
--- /dev/null
+++ b/tools/kvm/powerpc/spapr_hvcons.c
@@ -0,0 +1,102 @@
+/*
+ * SPAPR HV console
+ *
+ * Borrowed lightly from QEMU's spapr_vty.c, Copyright (c) 2010 David Gibson,
+ * IBM Corporation.
+ *
+ * Copyright (c) 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include kvm/term.h
+#include kvm/kvm.h
+#include kvm/kvm-cpu.h
+#include kvm/util.h
+#include spapr.h
+#include spapr_hvcons.h
+
+#include stdio.h
+#include sys/uio.h
+#include errno.h
+
+#include linux/byteorder.h
+
+union hv_chario {
+   struct {
+   uint64_t char0_7;
+   uint64_t char8_15;
+   } a;
+   uint8_t buf[16];
+};
+
+static unsigned long h_put_term_char(struct kvm_cpu *vcpu, unsigned long 
opcode, unsigned long *args)
+{
+   /* To do: Read register from args[0], and check it. */
+   unsigned long len = args[1];
+   union hv_chario data;
+   struct iovec iov;
+
+   if (len  16) {
+   return H_PARAMETER;
+   }
+   data.a.char0_7 = cpu_to_be64(args[2]);
+   data.a.char8_15 = cpu_to_be64(args[3]);
+
+   iov.iov_base = data.buf;
+   iov.iov_len = len

[PATCH V3 0/2] kvm tools: Prepare kvmtool for another architecture

2011-12-12 Thread Matt Evans
The last remaining patches from the preparation series, with changes:
- Map from hugetlbfs does plain statfs (without odd error checking),
  checks result of ftruncate()
- Remove typo whereby kvm_cpu__emulate_mmio() calls self.

Cheers,


Matt

Matt Evans (2):
  kvm tools: Add ability to map guest RAM from hugetlbfs
  kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

 tools/kvm/builtin-run.c  |4 ++-
 tools/kvm/include/kvm/kvm.h  |4 +-
 tools/kvm/include/kvm/util.h |4 +++
 tools/kvm/kvm-cpu.c  |   34 +-
 tools/kvm/kvm.c  |4 +-
 tools/kvm/util.c |   38 ++
 tools/kvm/x86/include/kvm/kvm-cpu-arch.h |   17 -
 tools/kvm/x86/kvm.c  |   20 +--
 8 files changed, 99 insertions(+), 26 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V3 1/2] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-12 Thread Matt Evans
Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
memory (down in kvm__arch_init()).  For x86, guest memory is a normal
ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

This maps directly from a hugetlbfs temp file rather than using something
like MADV_HUGEPAGES so that, if the user asks for hugepages, we definitely
are using hugepages.  (This is particularly useful for architectures that
don't yet support KVM without hugepages, so we definitely need to use
them for the whole of guest RAM.)

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c  |4 +++-
 tools/kvm/include/kvm/kvm.h  |4 ++--
 tools/kvm/include/kvm/util.h |4 
 tools/kvm/kvm.c  |4 ++--
 tools/kvm/util.c |   38 ++
 tools/kvm/x86/kvm.c  |   20 +---
 6 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 4411c9e..ab05f8c 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -85,6 +85,7 @@ static const char *host_mac;
 static const char *script;
 static const char *guest_name;
 static const char *sandbox;
+static const char *hugetlbfs_path;
 static struct virtio_net_params *net_params;
 static bool single_step;
 static bool readonly_image[MAX_DISK_IMAGES];
@@ -437,6 +438,7 @@ static const struct option options[] = {
 tty_parser),
OPT_STRING('\0', sandbox, sandbox, script,
Run this script when booting into custom rootfs),
+   OPT_STRING('\0', hugetlbfs, hugetlbfs_path, path, Hugetlbfs 
path),
 
OPT_GROUP(Kernel options:),
OPT_STRING('k', kernel, kernel_filename, kernel,
@@ -924,7 +926,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
guest_name = default_name;
}
 
-   kvm = kvm__init(dev, ram_size, guest_name);
+   kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
 
kvm-single_step = single_step;
 
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 5fe6e75..7159952 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -30,7 +30,7 @@ struct kvm_ext {
 void kvm__set_dir(const char *fmt, ...);
 const char *kvm__get_dir(void);
 
-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name);
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
ram_size, const char *name);
 int kvm__recommended_cpus(struct kvm *kvm);
 int kvm__max_cpus(struct kvm *kvm);
 void kvm__init_ram(struct kvm *kvm);
@@ -54,7 +54,7 @@ int kvm__enumerate_instances(int (*callback)(const char 
*name, int pid));
 void kvm__remove_socket(const char *name);
 
 void kvm__arch_set_cmdline(char *cmdline, bool video);
-void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const 
char *name);
+void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char 
*hugetlbfs_path, u64 ram_size, const char *name);
 void kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
 void kvm__arch_periodic_poll(struct kvm *kvm);
diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index dc2e0b9..1f6fbbd 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -20,6 +20,7 @@
 #include limits.h
 #include sys/param.h
 #include sys/types.h
+#include linux/types.h
 
 #ifdef __GNUC__
 #define NORETURN __attribute__((__noreturn__))
@@ -75,4 +76,7 @@ static inline void msleep(unsigned int msecs)
 {
usleep(MSECS_TO_USECS(msecs));
 }
+
+void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
+
 #endif /* KVM__UTIL_H */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index c54f886..35ca2c5 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -306,7 +306,7 @@ int kvm__max_cpus(struct kvm *kvm)
return ret;
 }
 
-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
ram_size, const char *name)
 {
struct kvm *kvm;
int ret;
@@ -339,7 +339,7 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, 
const char *name)
if (kvm__check_extensions(kvm))
die(A required KVM extention is not supported by OS);
 
-   kvm__arch_init(kvm, kvm_dev, ram_size, name);
+   kvm__arch_init(kvm, kvm_dev, hugetlbfs_path, ram_size, name);
 
kvm-name = name;
 
diff --git a/tools/kvm/util.c b/tools/kvm/util.c
index 4efbce9..f0a4bf7 100644
--- a/tools/kvm/util.c
+++ b/tools/kvm/util.c
@@ -4,6 +4,11 @@
 
 #include kvm/util.h
 
+#include linux/magic.h   /* For HUGETLBFS_MAGIC */
+#include sys/mman.h
+#include sys/stat.h
+#include sys/statfs.h
+
 static void report(const char *prefix, const char *err, va_list params)
 {
char msg[1024];
@@ -99,3 +104,36 @@ size_t strlcat(char *dest, const char *src

[PATCH V3 2/2] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2011-12-12 Thread Matt Evans
Different architectures will deal with MMIO exits differently.  For example,
KVM_EXIT_IO is x86-specific, and I/O cycles are often synthesised by steering
into windows in PCI bridges on other architectures.

This patch calls arch-specific kvm_cpu__emulate_io() and kvm_cpu__emulate_mmio()
from the main runloop's IO and MMIO exit handlers.  For x86, these directly
call kvm__emulate_io() and kvm__emulate_mmio() but other architectures will
perform some address munging before passing on the call.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm-cpu.c  |   34 +++---
 tools/kvm/x86/include/kvm/kvm-cpu-arch.h |   17 ++-
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 8ec4efa..b7ae3d3 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -52,11 +52,11 @@ static void kvm_cpu__handle_coalesced_mmio(struct kvm_cpu 
*cpu)
while (cpu-ring-first != cpu-ring-last) {
struct kvm_coalesced_mmio *m;
m = cpu-ring-coalesced_mmio[cpu-ring-first];
-   kvm__emulate_mmio(cpu-kvm,
-   m-phys_addr,
-   m-data,
-   m-len,
-   1);
+   kvm_cpu__emulate_mmio(cpu-kvm,
+ m-phys_addr,
+ m-data,
+ m-len,
+ 1);
cpu-ring-first = (cpu-ring-first + 1) % 
KVM_COALESCED_MMIO_MAX;
}
}
@@ -111,13 +111,13 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_IO: {
bool ret;
 
-   ret = kvm__emulate_io(cpu-kvm,
-   cpu-kvm_run-io.port,
-   (u8 *)cpu-kvm_run +
-   cpu-kvm_run-io.data_offset,
-   cpu-kvm_run-io.direction,
-   cpu-kvm_run-io.size,
-   cpu-kvm_run-io.count);
+   ret = kvm_cpu__emulate_io(cpu-kvm,
+ cpu-kvm_run-io.port,
+ (u8 *)cpu-kvm_run +
+ cpu-kvm_run-io.data_offset,
+ cpu-kvm_run-io.direction,
+ cpu-kvm_run-io.size,
+ cpu-kvm_run-io.count);
 
if (!ret)
goto panic_kvm;
@@ -126,11 +126,11 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
case KVM_EXIT_MMIO: {
bool ret;
 
-   ret = kvm__emulate_mmio(cpu-kvm,
-   cpu-kvm_run-mmio.phys_addr,
-   cpu-kvm_run-mmio.data,
-   cpu-kvm_run-mmio.len,
-   cpu-kvm_run-mmio.is_write);
+   ret = kvm_cpu__emulate_mmio(cpu-kvm,
+   
cpu-kvm_run-mmio.phys_addr,
+   cpu-kvm_run-mmio.data,
+   cpu-kvm_run-mmio.len,
+   
cpu-kvm_run-mmio.is_write);
 
if (!ret)
goto panic_kvm;
diff --git a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
index 822d966..198efe6 100644
--- a/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/x86/include/kvm/kvm-cpu-arch.h
@@ -4,7 +4,8 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include kvm/kvm.h   /* for kvm__emulate_{mm}io() */
+#include stdbool.h
 #include pthread.h
 
 struct kvm;
@@ -31,4 +32,18 @@ struct kvm_cpu {
struct kvm_coalesced_mmio_ring  *ring;
 };
 
+/*
+ * As these are such simple wrappers, let's have them in the header so they'll
+ * be cheaper to call:
+ */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return kvm__emulate_io(kvm, port, data, direction, size, count);
+}
+
+static inline bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 
*data, u32 len, u8 is_write)
+{
+   return kvm__emulate_mmio(kvm, phys_addr, data, len, is_write);
+}
+
 #endif /* KVM__KVM_CPU_ARCH_H */
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body

Re: [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and link appropriately

2011-12-12 Thread Matt Evans
Hi Pekka,

On 09/12/11 17:53, Matt Evans wrote:
 kvmtool's types.h includes asm/types.h, which by default on PPC64 brings in
 int-l64.h; define __SANE_USERSPACE_TYPES__ to get LL64 types.
 
 This patch also adds CFLAGS to the final link, so that any -m64 is obeyed
 when linking, too.

Just noticed this patch wasn't included in what you committed from this series,
but is required for the PPC64 series to build.

I'm waiting on an ack on the /other/ patch (that adds SANE_USERSPACE_TYPES to
PPC64 headers); I have a verbal one, but on-list is better :-)  But, /this/ 
patch
is somewhat independent from that.

If you're waiting so they can both go in together, then that's fine too.  Just
a reminder.


Cheers,


Matt


 
 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
  tools/kvm/Makefile  |2 +-
  tools/kvm/include/linux/types.h |1 +
  2 files changed, 2 insertions(+), 1 deletions(-)
 
 diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
 index 009a6ba..57dc521 100644
 --- a/tools/kvm/Makefile
 +++ b/tools/kvm/Makefile
 @@ -218,7 +218,7 @@ KVMTOOLS-VERSION-FILE:
  
  $(PROGRAM): $(DEPS) $(OBJS)
   $(E)   LINK $@
 - $(Q) $(CC) $(OBJS) $(LIBS) -o $@
 + $(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
  
  $(GUEST_INIT): guest/init.c
   $(E)   LINK $@
 diff --git a/tools/kvm/include/linux/types.h b/tools/kvm/include/linux/types.h
 index 357799c..5e20f10 100644
 --- a/tools/kvm/include/linux/types.h
 +++ b/tools/kvm/include/linux/types.h
 @@ -2,6 +2,7 @@
  #define LINUX_TYPES_H
  
  #include kvm/compiler.h
 +#define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
  #include asm/types.h
  
  typedef __u64 u64;
 --
 To unsubscribe from this list: send the line unsubscribe kvm in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 0/2] kvm tools: PPC64 basic support

2011-12-12 Thread Matt Evans
These two patches build on the previous split out arch-specific work.  The
first adds a PPC64 build, basic CPU support, guest RAM mapping (using 
hugepages),
flat kernel loading and all required arch-specific definitions  structures.

With patches to date, this should build PPC but not necessarily run much.
Subsequent patches add support to emulate an SPAPR-esque machine.

This patch does not include any code borrowed from outside kvmtool.

The second patch is a small fix for generic virtio code (now that we have a
PPC build) which removes reliance on ioeventfds for PPC, which doesn't provide
them.

Matt Evans (2):
  kvm tools: Add initial SPAPR PPC64 architecture support
  kvm tools: Make virtio-pci's ioeventfd__add_event() fall back
gracefully if ioeventfds unavailable

 tools/kvm/Makefile   |   10 +
 tools/kvm/include/kvm/ioeventfd.h|3 +-
 tools/kvm/ioeventfd.c|   12 +-
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 tools/kvm/virtio/pci.c   |   13 ++-
 12 files changed, 658 insertions(+), 5 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 1/2] kvm tools: Add initial SPAPR PPC64 architecture support

2011-12-12 Thread Matt Evans
This patch adds a new arch directory, powerpc, basic file structure, register
setup and where necessary stubs out arch-specific functions (e.g. interrupts,
runloop exits) that later patches will provide.  The target is an
SPAPR-compliant PPC64 machine (i.e. pSeries); there is no support for PPC32 or
'bare metal' PPC64 guests as yet.  Subsequent patches implement the hcalls and
RTAS required to boot SPAPR pSeries kernels.

Memory is mapped from hugetlbfs (as that is currently required by upstream PPC64
HV-mode KVM).  The mapping of a VRMA region is yet to be implemented; this is
only necessary on processors that don't support VRMA, e.g. = P6.  Work is
therefore needed to get this going on pre-P7 CPUs.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

Finally, support is added for simply loading flat binary kernels (plus initrd).
(bzImages are not used on PPC, and this series does not add zImage support or an
ELF loader.)  The intention is to later support loading firmware such as SLOF.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |   10 +
 tools/kvm/kvm.c  |3 +
 tools/kvm/powerpc/include/kvm/barrier.h  |6 +
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   72 
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   66 
 tools/kvm/powerpc/ioport.c   |   18 ++
 tools/kvm/powerpc/irq.c  |   40 +
 tools/kvm/powerpc/kvm-cpu.c  |  233 ++
 tools/kvm/powerpc/kvm.c  |  187 +
 9 files changed, 635 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/powerpc/include/kvm/barrier.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
 create mode 100644 tools/kvm/powerpc/ioport.c
 create mode 100644 tools/kvm/powerpc/irq.c
 create mode 100644 tools/kvm/powerpc/kvm-cpu.c
 create mode 100644 tools/kvm/powerpc/kvm.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 2bf70c9..3f1e84a 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -124,6 +124,16 @@ ifeq ($(ARCH),x86)
OTHEROBJS   += x86/bios/bios-rom.o
ARCH_INCLUDE := x86/include
 endif
+# POWER/ppc:  Actually only support ppc64 currently.
+ifeq ($(uname_M), ppc64)
+   DEFINES += -DCONFIG_PPC
+   OBJS+= powerpc/ioport.o
+   OBJS+= powerpc/irq.o
+   OBJS+= powerpc/kvm.o
+   OBJS+= powerpc/kvm-cpu.o
+   ARCH_INCLUDE := powerpc/include
+   CFLAGS += -m64
+endif
 
 ###
 
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 35ca2c5..3fb46f6 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -49,6 +49,9 @@ const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_DCR),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_NMI),
DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
+#ifdef CONFIG_PPC64
+   DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL),
+#endif
 };
 
 extern struct kvm *kvm;
diff --git a/tools/kvm/powerpc/include/kvm/barrier.h 
b/tools/kvm/powerpc/include/kvm/barrier.h
new file mode 100644
index 000..bc7d179
--- /dev/null
+++ b/tools/kvm/powerpc/include/kvm/barrier.h
@@ -0,0 +1,6 @@
+#ifndef _KVM_BARRIER_H_
+#define _KVM_BARRIER_H_
+
+#include asm/system.h
+
+#endif /* _KVM_BARRIER_H_ */
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
new file mode 100644
index 000..da61774
--- /dev/null
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -0,0 +1,72 @@
+/*
+ * PPC64 architecture-specific definitions
+ *
+ * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#ifndef KVM__KVM_ARCH_H
+#define KVM__KVM_ARCH_H
+
+#include stdbool.h
+#include linux/types.h
+#include time.h
+
+#define KVM_NR_CPUS(255)
+
+/*
+ * MMIO lives after RAM, but it'd be nice if it didn't constantly move.
+ * Choose a suitably high address, e.g. 63T...  This limits RAM size.
+ */
+#define PPC_MMIO_START 0x3F00UL
+#define PPC_MMIO_SIZE  0x0100UL
+
+#define KERNEL_LOAD_ADDR   0x
+#define KERNEL_START_ADDR  0x
+#define KERNEL_SECONDARY_START_ADDR 0x0060
+#define INITRD_LOAD_ADDR   0x0280
+
+#define FDT_MAX_SIZE   0x1
+#define RTAS_MAX_SIZE  0x1
+
+#define TIMEBASE_FREQ  51200ULL
+
+#define KVM_MMIO_START PPC_MMIO_START
+
+/*
+ * This is the address that pci_get_io_space_block() starts allocating
+ * from.  Note that this is a PCI bus address

[PATCH V2 2/2] kvm tools: Make virtio-pci's ioeventfd__add_event() fall back gracefully if ioeventfds unavailable

2011-12-12 Thread Matt Evans
Some KVM implementations (e.g. PPC) don't yet support ioeventfds, so don't
bomb out/die.  virtio-pci is able to function if it instead uses normal IO
port notification.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile|2 +-
 tools/kvm/include/kvm/ioeventfd.h |3 ++-
 tools/kvm/ioeventfd.c |   12 +---
 tools/kvm/virtio/pci.c|   13 -
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 3f1e84a..5bb3f08 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -126,7 +126,7 @@ ifeq ($(ARCH),x86)
 endif
 # POWER/ppc:  Actually only support ppc64 currently.
 ifeq ($(uname_M), ppc64)
-   DEFINES += -DCONFIG_PPC
+   DEFINES += -DCONFIG_PPC -DCONFIG_NO_IOEVENTFDS
OBJS+= powerpc/ioport.o
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
diff --git a/tools/kvm/include/kvm/ioeventfd.h 
b/tools/kvm/include/kvm/ioeventfd.h
index df01750..5e458be 100644
--- a/tools/kvm/include/kvm/ioeventfd.h
+++ b/tools/kvm/include/kvm/ioeventfd.h
@@ -4,6 +4,7 @@
 #include linux/types.h
 #include linux/list.h
 #include sys/eventfd.h
+#include stdbool.h
 
 struct kvm;
 
@@ -21,7 +22,7 @@ struct ioevent {
 
 void ioeventfd__init(void);
 void ioeventfd__start(void);
-void ioeventfd__add_event(struct ioevent *ioevent);
+bool ioeventfd__add_event(struct ioevent *ioevent);
 void ioeventfd__del_event(u64 addr, u64 datamatch);
 
 #endif
diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 3a240e4..37f9a63 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/ioeventfd.c
@@ -26,7 +26,7 @@ void ioeventfd__init(void)
die(Failed creating epoll fd);
 }
 
-void ioeventfd__add_event(struct ioevent *ioevent)
+bool ioeventfd__add_event(struct ioevent *ioevent)
 {
struct kvm_ioeventfd kvm_ioevent;
struct epoll_event epoll_event;
@@ -48,8 +48,13 @@ void ioeventfd__add_event(struct ioevent *ioevent)
.flags  = KVM_IOEVENTFD_FLAG_PIO | 
KVM_IOEVENTFD_FLAG_DATAMATCH,
};
 
-   if (ioctl(ioevent-fn_kvm-vm_fd, KVM_IOEVENTFD, kvm_ioevent) != 0)
-   die(Failed creating new ioeventfd);
+   if (ioctl(ioevent-fn_kvm-vm_fd, KVM_IOEVENTFD, kvm_ioevent) != 0) {
+   /* Not all KVM implementations may support KVM_IOEVENTFD,
+* so be graceful.
+*/
+   free(new_ioevent);
+   return false;
+   }
 
epoll_event = (struct epoll_event) {
.events = EPOLLIN,
@@ -60,6 +65,7 @@ void ioeventfd__add_event(struct ioevent *ioevent)
die(Failed assigning new event to the epoll fd);
 
list_add_tail(new_ioevent-list, used_ioevents);
+   return true;
 }
 
 void ioeventfd__del_event(u64 addr, u64 datamatch)
diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c
index a7da8e8..56fa4ad 100644
--- a/tools/kvm/virtio/pci.c
+++ b/tools/kvm/virtio/pci.c
@@ -7,6 +7,7 @@
 #include kvm/virtio.h
 #include kvm/ioeventfd.h
 #include kvm/virtio-trans.h
+#include kvm/util.h
 
 #include linux/virtio_pci.h
 #include linux/byteorder.h
@@ -50,7 +51,17 @@ static int virtio_pci__init_ioeventfd(struct kvm *kvm, 
struct virtio_trans *vtra
.fd = eventfd(0, 0),
};
 
-   ioeventfd__add_event(ioevent);
+   if (!ioeventfd__add_event(ioevent)) {
+#ifndef CONFIG_NO_IOEVENTFDS
+   /*
+* ioevents aren't supported on all KVM implementations, so we
+* expect this to fail -- don't need to be verbose about it!
+* For virtio-pci, this is fine.  It catches the IO accesses
+* anyway, so still works (but slower).
+*/
+   pr_warning(Failed creating new ioeventfd);
+#endif
+   }
 
if (vtrans-virtio_ops-notify_vq_eventfd)
vtrans-virtio_ops-notify_vq_eventfd(kvm, vpci-dev, vq, 
ioevent.fd);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 0/6] Add initial SPAPR PPC64 architecture support

2011-12-12 Thread Matt Evans
This series adds support for a PPC64 platform, SPAPR, on top of the previous
more general PPC64 CPU support.  This platform is paravirtualised, with most
of the MMU hypercalls being dealt with in the kernel.  Userland needs to
describe the environment to the machine with a device tree, cope with some
hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate
the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque
machine.

With this series, normal pSeries kernels boot fine (including RH kernels that
include virtio support out of the box).  There is no support for PPC32 or
'bare metal' PPC64 guests as yet.

Processor state is set up as a guest kernel would expect (both primary and
secondaries), and SMP is fully supported.

The kernels are loaded as flat binaries and booted directly.  The intention
is to later support loading firmware such as SLOF.

Some of the code within is borrowed/based upon code in QEMU, particularly
the XICS emulation, device tree construction and PCI setup.


Matt Evans (6):
  kvm tools: Generate SPAPR PPC64 guest device tree
  kvm tools: Add SPAPR PPC64 hcall  rtascall structure
  kvm tools: Add SPAPR PPC64 HV console
  kvm tools: Add PPC64 XICS interrupt controller support
  kvm tools: Add PPC64 PCI Host Bridge
  kvm tools: Add PPC64 kvm_cpu__emulate_io()

 tools/kvm/Makefile   |8 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   14 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   12 +-
 tools/kvm/powerpc/irq.c  |   35 ++-
 tools/kvm/powerpc/kvm-cpu.c  |   46 +++
 tools/kvm/powerpc/kvm.c  |  255 +-
 tools/kvm/powerpc/spapr.h|  111 ++
 tools/kvm/powerpc/spapr_hcall.c  |  132 +++
 tools/kvm/powerpc/spapr_hvcons.c |  102 +
 tools/kvm/powerpc/spapr_hvcons.h |   19 +
 tools/kvm/powerpc/spapr_pci.c|  423 +
 tools/kvm/powerpc/spapr_pci.h|   38 ++
 tools/kvm/powerpc/spapr_rtas.c   |  230 
 tools/kvm/powerpc/xics.c |  514 ++
 tools/kvm/powerpc/xics.h |   23 ++
 15 files changed, 1952 insertions(+), 10 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.c
 create mode 100644 tools/kvm/powerpc/spapr_hvcons.h
 create mode 100644 tools/kvm/powerpc/spapr_pci.c
 create mode 100644 tools/kvm/powerpc/spapr_pci.h
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c
 create mode 100644 tools/kvm/powerpc/xics.c
 create mode 100644 tools/kvm/powerpc/xics.h

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 1/6] kvm tools: Generate SPAPR PPC64 guest device tree

2011-12-12 Thread Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which
subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.

Some aspects are currently hardwired for simplicity, for example advertised
page sizes, HPT size, SLB size, VMX/DFP, etc.  Future support of a variety
of POWER CPUs should acquire this info from the host and encode appropriately.

This requires a 64-bit libfdt.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |3 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   10 ++
 tools/kvm/powerpc/kvm.c  |  141 ++
 3 files changed, 153 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 5bb3f08..4ee4805 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -132,7 +132,8 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/kvm.o
OBJS+= powerpc/kvm-cpu.o
ARCH_INCLUDE := powerpc/include
-   CFLAGS += -m64
+   CFLAGS  += -m64
+   LIBS+= -lfdt
 endif
 
 ###
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index da61774..33a3827 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -69,4 +69,14 @@ struct kvm {
const char  *name;
 };
 
+/* Helper for the various bits of code that generate FDT nodes */
+#define _FDT(exp)  \
+   do {\
+   int ret = (exp);\
+   if (ret  0) {  \
+   die(Error creating device tree: %s: %s\n, \
+   #exp, fdt_strerror(ret));   \
+   }   \
+   } while (0)
+
 #endif /* KVM__KVM_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index f838a8f..95ed1cc 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -3,6 +3,9 @@
  *
  * Copyright 2011 Matt Evans m...@ozlabs.org, IBM Corporation.
  *
+ * Portions of FDT setup borrowed from QEMU, copyright 2010 David Gibson, IBM
+ * Corporation.
+ *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
  * by the Free Software Foundation.
@@ -29,6 +32,8 @@
 #include linux/byteorder.h
 #include libfdt.h
 
+#define HPT_ORDER 24
+
 #define HUGETLBFS_PATH /var/lib/hugetlbfs/global/pagesize-16MB/
 
 static char kern_cmdline[2048];
@@ -168,9 +173,145 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
return false;
 }
 
+#define SMT_THREADS 4
+
+static uint32_t mfpvr(void)
+{
+   uint32_t r;
+   asm volatile (mfpvr %0 : =r(r));
+   return r;
+}
+
 static void setup_fdt(struct kvm *kvm)
 {
+   uint64_tmem_reg_property[] = { 0, cpu_to_be64(kvm-ram_size) };
+   int smp_cpus = kvm-nrcpus;
+   charhypertas_prop_kvm[] = hcall-pft\0hcall-term\0
+   hcall-dabr\0hcall-interrupt\0hcall-tce\0hcall-vio\0
+   hcall-splpar\0hcall-bulk;
+   int i, j;
+   charcpu_name[30];
+   u8  staging_fdt[FDT_MAX_SIZE];
+   uint32_tpvr = mfpvr();
+
+   /* Generate an appropriate DT at kvm-fdt_gra */
+   void *fdt_dest = guest_flat_to_host(kvm, kvm-fdt_gra);
+   void *fdt = staging_fdt;
+
+   _FDT(fdt_create(fdt, FDT_MAX_SIZE));
+   _FDT(fdt_finish_reservemap(fdt));
+
+   _FDT(fdt_begin_node(fdt, ));
+
+   _FDT(fdt_property_string(fdt, device_type, chrp));
+   _FDT(fdt_property_string(fdt, model, IBM pSeries (kvmtool)));
+   _FDT(fdt_property_cell(fdt, #address-cells, 0x2));
+   _FDT(fdt_property_cell(fdt, #size-cells, 0x2));
+
+   /* /chosen */
+   _FDT(fdt_begin_node(fdt, chosen));
+   /* cmdline */
+   _FDT(fdt_property_string(fdt, bootargs, kern_cmdline));
+   /* Initrd */
+   if (kvm-initrd_size != 0) {
+   uint32_t ird_st_prop = cpu_to_be32(kvm-initrd_gra);
+   uint32_t ird_end_prop = cpu_to_be32(kvm-initrd_gra +
+   kvm-initrd_size);
+   _FDT(fdt_property(fdt, linux,initrd-start,
+  ird_st_prop, sizeof(ird_st_prop)));
+   _FDT(fdt_property(fdt, linux,initrd-end,
+  ird_end_prop, sizeof(ird_end_prop)));
+   }
+   _FDT(fdt_end_node(fdt));
+
+   /*
+* Memory: We don't alloc. a separate RMA yet.  If we ever need to
+* (CAP_PPC_RMA == 2) then have one memory node for 0-RMAsize, and
+* another RMAsize-endOfMem.
+*/
+   _FDT(fdt_begin_node(fdt, memory@0));
+   _FDT

[PATCH V2 2/6] kvm tools: Add SPAPR PPC64 hcall rtascall structure

2011-12-12 Thread Matt Evans
This patch adds the basic structure for HV calls, their registration and some of
the simpler calls.  A similar layout for RTAS calls is also added, again with
some of the simpler RTAS calls used by the guest.  The SPAPR RTAS stub is
generated inline.  Also, nodes for RTAS are added to the device tree.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile  |2 +
 tools/kvm/powerpc/kvm-cpu.c |6 +
 tools/kvm/powerpc/kvm.c |   46 -
 tools/kvm/powerpc/spapr.h   |  105 ++
 tools/kvm/powerpc/spapr_hcall.c |  132 ++
 tools/kvm/powerpc/spapr_rtas.c  |  230 +++
 6 files changed, 520 insertions(+), 1 deletions(-)
 create mode 100644 tools/kvm/powerpc/spapr.h
 create mode 100644 tools/kvm/powerpc/spapr_hcall.c
 create mode 100644 tools/kvm/powerpc/spapr_rtas.c

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 4ee4805..e2a7190 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -131,6 +131,8 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/irq.o
OBJS+= powerpc/kvm.o
OBJS+= powerpc/kvm-cpu.o
+   OBJS+= powerpc/spapr_hcall.o
+   OBJS+= powerpc/spapr_rtas.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
LIBS+= -lfdt
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index ea99666..ef3db4d 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -14,6 +14,8 @@
 #include kvm/util.h
 #include kvm/kvm.h
 
+#include spapr.h
+
 #include sys/ioctl.h
 #include sys/mman.h
 #include signal.h
@@ -150,6 +152,10 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
bool ret = true;
struct kvm_run *run = vcpu-kvm_run;
switch(run-exit_reason) {
+   case KVM_EXIT_PAPR_HCALL:
+   run-papr_hcall.ret = spapr_hypercall(vcpu, run-papr_hcall.nr,
+ 
(target_ulong*)run-papr_hcall.args);
+   break;
default:
ret = false;
}
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index 95ed1cc..b3570a9 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -14,6 +14,8 @@
 #include kvm/kvm.h
 #include kvm/util.h
 
+#include spapr.h
+
 #include linux/kvm.h
 
 #include sys/types.h
@@ -106,6 +108,11 @@ void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, 
const char *hugetlbfs_
if (cap_ppc_rma == 2)
die(Need contiguous RMA allocation on this hardware, 
which is not yet supported.);
+
+   /* Do these before FDT setup, IRQ setup, etc. */
+   /* FIXME: SPAPR-specific */
+   hypercall_init();
+   register_core_rtas();
 }
 
 void kvm__irq_line(struct kvm *kvm, int irq, int level)
@@ -182,6 +189,11 @@ static uint32_t mfpvr(void)
return r;
 }
 
+/*
+ * Set up the FDT for the kernel: This function is currently fairly 
SPAPR-heavy,
+ * and whilst most PPC targets will require CPU/memory nodes, others like RTAS
+ * should eventually be added separately.
+ */
 static void setup_fdt(struct kvm *kvm)
 {
uint64_tmem_reg_property[] = { 0, cpu_to_be64(kvm-ram_size) };
@@ -208,6 +220,20 @@ static void setup_fdt(struct kvm *kvm)
_FDT(fdt_property_cell(fdt, #address-cells, 0x2));
_FDT(fdt_property_cell(fdt, #size-cells, 0x2));
 
+   /* RTAS */
+   _FDT(fdt_begin_node(fdt, rtas));
+   /* This is what the kernel uses to switch 'We're an LPAR'! */
+_FDT(fdt_property(fdt, ibm,hypertas-functions, hypertas_prop_kvm,
+   sizeof(hypertas_prop_kvm)));
+   _FDT(fdt_property_cell(fdt, linux,rtas-base, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, linux,rtas-entry, kvm-rtas_gra));
+   _FDT(fdt_property_cell(fdt, rtas-size, kvm-rtas_size));
+   /* Now add properties for all RTAS tokens: */
+   if (spapr_rtas_fdt_setup(kvm, fdt))
+   die(Couldn't create RTAS FDT properties\n);
+
+   _FDT(fdt_end_node(fdt));
+
/* /chosen */
_FDT(fdt_begin_node(fdt, chosen));
/* cmdline */
@@ -319,7 +345,25 @@ static void setup_fdt(struct kvm *kvm)
  */
 void kvm__arch_setup_firmware(struct kvm *kvm)
 {
-   /* Load RTAS */
+   /*
+* Set up RTAS stub.  All it is is a single hypercall:
+*  0:   7c 64 1b 78 mr  r4,r3
+*  4:   3c 60 00 00 lis r3,0
+*  8:   60 63 f0 00 ori r3,r3,61440
+*  c:   44 00 00 22 sc  1
+* 10:   4e 80 00 20 blr
+*/
+   uint32_t *rtas = guest_flat_to_host(kvm, kvm-rtas_gra);
+
+   rtas[0] = 0x7c641b78;
+   rtas[1] = 0x3c60;
+   rtas[2] = 0x6063f000;
+   rtas[3] = 0x4422;
+   rtas[4] = 0x4e800020;
+   kvm-rtas_size = 20;
+
+   pr_info(Set up %ld bytes of RTAS at 0x%lx\n,
+   kvm-rtas_size, kvm-rtas_gra

[PATCH V2 6/6] kvm tools: Add PPC64 kvm_cpu__emulate_io()

2011-12-12 Thread Matt Evans
This is the final piece of the puzzle for PPC SPAPR PCI; this
function splits MMIO accesses into the two PHB windows  directs
things to MMIO/IO emulation as appropriate.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile   |1 +
 tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h |   10 -
 tools/kvm/powerpc/kvm-cpu.c  |   29 ++
 3 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 0d42acf..6f3485b 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -134,6 +134,7 @@ ifeq ($(uname_M), ppc64)
OBJS+= powerpc/spapr_hcall.o
OBJS+= powerpc/spapr_rtas.o
OBJS+= powerpc/spapr_hvcons.o
+   OBJS+= powerpc/spapr_pci.o
OBJS+= powerpc/xics.o
ARCH_INCLUDE := powerpc/include
CFLAGS  += -m64
diff --git a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
index c1c6539..7520c04 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h
@@ -14,7 +14,7 @@
 /* Architecture-specific kvm_cpu definitions. */
 
 #include linux/kvm.h /* for struct kvm_regs */
-
+#include stdbool.h
 #include pthread.h
 
 #define MSR_SF (1UL63)
@@ -65,4 +65,12 @@ struct kvm_cpu {
 
 void kvm_cpu__irq(struct kvm_cpu *vcpu, int pin, int level);
 
+/* This is never actually called on PPC. */
+static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void *data, 
int direction, int size, u32 count)
+{
+   return false;
+}
+
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write);
+
 #endif /* KVM__KVM_CPU_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 5ef1cbf..4da4990 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -24,6 +24,7 @@
 #include string.h
 #include errno.h
 #include stdio.h
+#include assert.h
 
 static int debug_fd;
 
@@ -173,6 +174,34 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
return ret;
 }
 
+bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, 
u8 is_write)
+{
+   /*
+* FIXME: This function will need to be split in order to support
+* various PowerPC platforms/PHB types, etc.  It currently assumes SPAPR
+* PPC64 guest.
+*/
+   bool ret = false;
+
+   if ((phys_addr = SPAPR_PCI_IO_WIN_ADDR) 
+   (phys_addr  SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)) {
+   ret = kvm__emulate_io(kvm, phys_addr - SPAPR_PCI_IO_WIN_ADDR,
+ data, is_write ? KVM_EXIT_IO_OUT :
+ KVM_EXIT_IO_IN,
+ len, 1);
+   } else if ((phys_addr = SPAPR_PCI_MEM_WIN_ADDR) 
+  (phys_addr  SPAPR_PCI_MEM_WIN_ADDR +
+   SPAPR_PCI_MEM_WIN_SIZE)) {
+   ret = kvm__emulate_mmio(kvm, phys_addr - SPAPR_PCI_MEM_WIN_ADDR,
+   data, len, is_write);
+   } else {
+   pr_warning(MMIO %s unknown address %llx (size %d)!\n,
+  is_write ? write to : read from,
+  phys_addr, len);
+   }
+   return ret;
+}
+
 #define CONDSTR_BIT(m, b) (((m)  MSR_##b) ? #b  : )
 
 void kvm_cpu__show_registers(struct kvm_cpu *vcpu)
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and link appropriately

2011-12-11 Thread Matt Evans
On 09/12/11 19:29, Pekka Enberg wrote:
 On Fri, Dec 9, 2011 at 10:24 AM, Sasha Levin levinsasha...@gmail.com wrote:
 If you also got kernel patches that add __SANE_USERSPACE_TYPES__ to the
 headers, and KVM_CAP_NR_VCPUS to KVM PPC, we can carry them in the KVM
 tools tree as well.
 
 Yup, all we need is ACKs from PPC maintainers.

Cool, I've pinged them re. __SANE_USERSPACE_TYPES__, and that would be useful to
carry in your tree.  But, IMHO, the patch I sent to Alex ([PATCH] KVM: PPC: Add
KVM_CAP_NR_VCPUS and KVM_CAP_MAX_VCPUS) should go in via his tree.  The
KVM/PPC-HV kernel folk will get it quicker in their trees (pulled from Alex) and
it's not a build problem, only a limit of SMP CPU numbers.  That is, if you're
building a kernel for PPC KVM today you'll probably use something more similar
to Alex's tree than mainline/kvm tools tree.


Cheers,


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 23/23] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

2011-12-11 Thread Matt Evans
On 09/12/11 18:53, Sasha Levin wrote:
 On Fri, 2011-12-09 at 17:56 +1100, Matt Evans wrote:
 @@ -30,4 +31,18 @@ struct kvm_cpu {
 struct kvm_coalesced_mmio_ring  *ring;
  };
  
 +/*
 + * As these are such simple wrappers, let's have them in the header so 
 they'll
 + * be cheaper to call:
 + */
 +static inline bool kvm_cpu__emulate_io(struct kvm *kvm, u16 port, void 
 *data, int direction, int size, u32 count)
 +{
 +   return kvm__emulate_io(kvm, port, data, direction, size, count);
 +}
 +
 +static inline bool kvm_cpu__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 
 *data, u32 len, u8 is_write)
 +{
 +   return kvm_cpu__emulate_mmio(kvm, phys_addr, data, len, is_write);
 
 This is probably wrong. kvm_cpu__emulate_mmio just calls itself over and
 over.

Urgh, not just probably -- CP strikes again.  Consider it fixed.

Thanks!


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-11 Thread Matt Evans
On 09/12/11 18:39, Sasha Levin wrote:
 On Fri, 2011-12-09 at 17:55 +1100, Matt Evans wrote:
 Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
 memory (down in kvm__arch_init()).  For x86, guest memory is a normal
 ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
  tools/kvm/builtin-run.c  |4 ++-
  tools/kvm/include/kvm/kvm.h  |4 +-
  tools/kvm/include/kvm/util.h |4 +++
  tools/kvm/kvm.c  |4 +-
  tools/kvm/util.c |   45 
 ++
  tools/kvm/x86/kvm.c  |   20 +++--
  6 files changed, 73 insertions(+), 8 deletions(-)

 diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
 index 7969901..0acfe81 100644
 --- a/tools/kvm/builtin-run.c
 +++ b/tools/kvm/builtin-run.c
 @@ -82,6 +82,7 @@ static const char *guest_mac;
  static const char *host_mac;
  static const char *script;
  static const char *guest_name;
 +static const char *hugetlbfs_path;
  static struct virtio_net_params *net_params;
  static bool single_step;
  static bool readonly_image[MAX_DISK_IMAGES];
 @@ -422,6 +423,7 @@ static const struct option options[] = {
  OPT_CALLBACK('\0', tty, NULL, tty id,
   Remap guest TTY into a pty on the host,
   tty_parser),
 +OPT_STRING('\0', hugetlbfs, hugetlbfs_path, path, Hugetlbfs 
 path),
  
  OPT_GROUP(Kernel options:),
  OPT_STRING('k', kernel, kernel_filename, kernel,
 @@ -807,7 +809,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
 *prefix)
  guest_name = default_name;
  }
  
 -kvm = kvm__init(dev, ram_size, guest_name);
 +kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
  
  kvm-single_step = single_step;
  
 diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
 index 5fe6e75..7159952 100644
 --- a/tools/kvm/include/kvm/kvm.h
 +++ b/tools/kvm/include/kvm/kvm.h
 @@ -30,7 +30,7 @@ struct kvm_ext {
  void kvm__set_dir(const char *fmt, ...);
  const char *kvm__get_dir(void);
  
 -struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name);
 +struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
 ram_size, const char *name);
  int kvm__recommended_cpus(struct kvm *kvm);
  int kvm__max_cpus(struct kvm *kvm);
  void kvm__init_ram(struct kvm *kvm);
 @@ -54,7 +54,7 @@ int kvm__enumerate_instances(int (*callback)(const char 
 *name, int pid));
  void kvm__remove_socket(const char *name);
  
  void kvm__arch_set_cmdline(char *cmdline, bool video);
 -void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, 
 const char *name);
 +void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char 
 *hugetlbfs_path, u64 ram_size, const char *name);
  void kvm__arch_setup_firmware(struct kvm *kvm);
  bool kvm__arch_cpu_supports_vm(void);
  void kvm__arch_periodic_poll(struct kvm *kvm);
 diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
 index dc2e0b9..1f6fbbd 100644
 --- a/tools/kvm/include/kvm/util.h
 +++ b/tools/kvm/include/kvm/util.h
 @@ -20,6 +20,7 @@
  #include limits.h
  #include sys/param.h
  #include sys/types.h
 +#include linux/types.h
  
  #ifdef __GNUC__
  #define NORETURN __attribute__((__noreturn__))
 @@ -75,4 +76,7 @@ static inline void msleep(unsigned int msecs)
  {
  usleep(MSECS_TO_USECS(msecs));
  }
 +
 +void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
 +
  #endif /* KVM__UTIL_H */
 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index c54f886..35ca2c5 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -306,7 +306,7 @@ int kvm__max_cpus(struct kvm *kvm)
  return ret;
  }
  
 -struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
 +struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
 ram_size, const char *name)
  {
  struct kvm *kvm;
  int ret;
 @@ -339,7 +339,7 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, 
 const char *name)
  if (kvm__check_extensions(kvm))
  die(A required KVM extention is not supported by OS);
  
 -kvm__arch_init(kvm, kvm_dev, ram_size, name);
 +kvm__arch_init(kvm, kvm_dev, hugetlbfs_path, ram_size, name);
  
  kvm-name = name;
  
 diff --git a/tools/kvm/util.c b/tools/kvm/util.c
 index 4efbce9..90b6a3b 100644
 --- a/tools/kvm/util.c
 +++ b/tools/kvm/util.c
 @@ -4,6 +4,11 @@
  
  #include kvm/util.h
  
 +#include linux/magic.h/* For HUGETLBFS_MAGIC */
 +#include sys/mman.h
 +#include sys/stat.h
 +#include sys/statfs.h
 +
  static void report(const char *prefix, const char *err, va_list params)
  {
  char msg[1024];
 @@ -99,3 +104,43 @@ size_t strlcat(char *dest, const char *src, size_t count)
  
  return res;
  }
 +
 +void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 +{
 +char mpath[PATH_MAX];
 +int fd;
 +int r;
 +struct statfs sfs

Re: [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-11 Thread Matt Evans
On 09/12/11 19:42, Pekka Enberg wrote:
 On Fri, Dec 9, 2011 at 8:55 AM, Matt Evans m...@ozlabs.org wrote:
 Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
 memory (down in kvm__arch_init()).  For x86, guest memory is a normal
 ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

 Signed-off-by: Matt Evans m...@ozlabs.org
 
 Btw, why don't you want to use MADV_HUGEPAGE for this? You could just
 do it unconditionally, no?

Well, I'm manually mapping from hugetlbfs as currently* PPC KVM requires
hugepages to back guest RAM and MADV_HUGEPAGE is just a hint, no?  I also wanted
things to work on kernels without transparent hugepages enabled.  I think it's
safer to do things explicitly, as if the user requests hugepages it's more
transparent (I'm thinking benchmarking, etc.) to be definitely using hugepages.


Cheers,


Matt


*: I know Paul's posted patches to implement smallpage support... so this will
   change in time.
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-11 Thread Matt Evans
On 09/12/11 19:38, Pekka Enberg wrote:
 On Fri, Dec 9, 2011 at 8:55 AM, Matt Evans m...@ozlabs.org wrote:
 Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
 memory (down in kvm__arch_init()).  For x86, guest memory is a normal
 ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

 Signed-off-by: Matt Evans m...@ozlabs.org
 
 +void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 +{
 +   char mpath[PATH_MAX];
 +   int fd;
 +   int r;
 +   struct statfs sfs;
 +   void *addr;
 +
 +   do {
 +   /*
 +* QEMU seems to work around this returning EINTR...  Let's 
 do
 +* that too.
 +*/
 +   r = statfs(htlbfs_path, sfs);
 +   } while (r  errno == EINTR);
 
 Can this really happen? What about EAGAIN? The retry logic really
 wants to live in tools/kvm/read-write.c as a xstatfs() wrapper if we
 do need this.

I don't think it can.  As per the comment, I thought QEMU knew something I
didn't but I haven't seen any other reason for doing this.  I'll remove it,
thanks for the sanity jolt.


Matt

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and link appropriately

2011-12-11 Thread Matt Evans
On 09/12/11 19:29, Pekka Enberg wrote:
 On Fri, Dec 9, 2011 at 10:24 AM, Sasha Levin levinsasha...@gmail.com wrote:
 If you also got kernel patches that add __SANE_USERSPACE_TYPES__ to the
 headers, and KVM_CAP_NR_VCPUS to KVM PPC, we can carry them in the KVM
 tools tree as well.
 
 Yup, all we need is ACKs from PPC maintainers.

Cool, I've pinged them re. __SANE_USERSPACE_TYPES__, and that would be useful to
carry in your tree.  But, IMHO, the patch I sent to Alex ([PATCH] KVM: PPC: Add
KVM_CAP_NR_VCPUS and KVM_CAP_MAX_VCPUS) should go in via his tree.  The
KVM/PPC-HV kernel folk will get it quicker in their trees (pulled from Alex) and
it's not a build problem, only a limit of SMP CPU numbers.  That is, if you're
building a kernel for PPC KVM today you'll probably use something more similar
to Alex's tree than mainline/kvm tools tree.


Cheers,


Matt
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs

2011-12-11 Thread Matt Evans
On 09/12/11 18:39, Sasha Levin wrote:
 On Fri, 2011-12-09 at 17:55 +1100, Matt Evans wrote:
 Add a --hugetlbfs commandline option to give a path to hugetlbfs-map guest
 memory (down in kvm__arch_init()).  For x86, guest memory is a normal
 ANON mmap() if this option is not provided, otherwise a hugetlbfs mmap.

 Signed-off-by: Matt Evans m...@ozlabs.org
 ---
  tools/kvm/builtin-run.c  |4 ++-
  tools/kvm/include/kvm/kvm.h  |4 +-
  tools/kvm/include/kvm/util.h |4 +++
  tools/kvm/kvm.c  |4 +-
  tools/kvm/util.c |   45 
 ++
  tools/kvm/x86/kvm.c  |   20 +++--
  6 files changed, 73 insertions(+), 8 deletions(-)

 diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
 index 7969901..0acfe81 100644
 --- a/tools/kvm/builtin-run.c
 +++ b/tools/kvm/builtin-run.c
 @@ -82,6 +82,7 @@ static const char *guest_mac;
  static const char *host_mac;
  static const char *script;
  static const char *guest_name;
 +static const char *hugetlbfs_path;
  static struct virtio_net_params *net_params;
  static bool single_step;
  static bool readonly_image[MAX_DISK_IMAGES];
 @@ -422,6 +423,7 @@ static const struct option options[] = {
  OPT_CALLBACK('\0', tty, NULL, tty id,
   Remap guest TTY into a pty on the host,
   tty_parser),
 +OPT_STRING('\0', hugetlbfs, hugetlbfs_path, path, Hugetlbfs 
 path),
  
  OPT_GROUP(Kernel options:),
  OPT_STRING('k', kernel, kernel_filename, kernel,
 @@ -807,7 +809,7 @@ int kvm_cmd_run(int argc, const char **argv, const char 
 *prefix)
  guest_name = default_name;
  }
  
 -kvm = kvm__init(dev, ram_size, guest_name);
 +kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);
  
  kvm-single_step = single_step;
  
 diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
 index 5fe6e75..7159952 100644
 --- a/tools/kvm/include/kvm/kvm.h
 +++ b/tools/kvm/include/kvm/kvm.h
 @@ -30,7 +30,7 @@ struct kvm_ext {
  void kvm__set_dir(const char *fmt, ...);
  const char *kvm__get_dir(void);
  
 -struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name);
 +struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
 ram_size, const char *name);
  int kvm__recommended_cpus(struct kvm *kvm);
  int kvm__max_cpus(struct kvm *kvm);
  void kvm__init_ram(struct kvm *kvm);
 @@ -54,7 +54,7 @@ int kvm__enumerate_instances(int (*callback)(const char 
 *name, int pid));
  void kvm__remove_socket(const char *name);
  
  void kvm__arch_set_cmdline(char *cmdline, bool video);
 -void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, 
 const char *name);
 +void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char 
 *hugetlbfs_path, u64 ram_size, const char *name);
  void kvm__arch_setup_firmware(struct kvm *kvm);
  bool kvm__arch_cpu_supports_vm(void);
  void kvm__arch_periodic_poll(struct kvm *kvm);
 diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
 index dc2e0b9..1f6fbbd 100644
 --- a/tools/kvm/include/kvm/util.h
 +++ b/tools/kvm/include/kvm/util.h
 @@ -20,6 +20,7 @@
  #include limits.h
  #include sys/param.h
  #include sys/types.h
 +#include linux/types.h
  
  #ifdef __GNUC__
  #define NORETURN __attribute__((__noreturn__))
 @@ -75,4 +76,7 @@ static inline void msleep(unsigned int msecs)
  {
  usleep(MSECS_TO_USECS(msecs));
  }
 +
 +void *mmap_hugetlbfs(const char *htlbfs_path, u64 size);
 +
  #endif /* KVM__UTIL_H */
 diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
 index c54f886..35ca2c5 100644
 --- a/tools/kvm/kvm.c
 +++ b/tools/kvm/kvm.c
 @@ -306,7 +306,7 @@ int kvm__max_cpus(struct kvm *kvm)
  return ret;
  }
  
 -struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
 +struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 
 ram_size, const char *name)
  {
  struct kvm *kvm;
  int ret;
 @@ -339,7 +339,7 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, 
 const char *name)
  if (kvm__check_extensions(kvm))
  die(A required KVM extention is not supported by OS);
  
 -kvm__arch_init(kvm, kvm_dev, ram_size, name);
 +kvm__arch_init(kvm, kvm_dev, hugetlbfs_path, ram_size, name);
  
  kvm-name = name;
  
 diff --git a/tools/kvm/util.c b/tools/kvm/util.c
 index 4efbce9..90b6a3b 100644
 --- a/tools/kvm/util.c
 +++ b/tools/kvm/util.c
 @@ -4,6 +4,11 @@
  
  #include kvm/util.h
  
 +#include linux/magic.h/* For HUGETLBFS_MAGIC */
 +#include sys/mman.h
 +#include sys/stat.h
 +#include sys/statfs.h
 +
  static void report(const char *prefix, const char *err, va_list params)
  {
  char msg[1024];
 @@ -99,3 +104,43 @@ size_t strlcat(char *dest, const char *src, size_t count)
  
  return res;
  }
 +
 +void *mmap_hugetlbfs(const char *htlbfs_path, u64 size)
 +{
 +char mpath[PATH_MAX];
 +int fd;
 +int r;
 +struct statfs sfs

[PATCH V2 00/23] kvm tools: Prepare kvmtool for another architecture

2011-12-08 Thread Matt Evans
Hi,


This patch series rearranges and tidies various parts of kvmtool to pave the way
for the addition of support for another architecture -- SPAPR PPC64.  A second
patch series will follow to present the PPC64 support.

Building on the separation of x86-specific code into tools/kvm/x86, this series
change some of the mechanics of kvm tool, for example modifying the loop around
ioctl(KVM_RUN) so that whilst it stays generic, it calls into arch-specific code
to handle specific exit reasons, MMIO etc.  The builtin-run initialisation path
is rationalised so that PCI  IRQs are initialised before devices, and all of
this happens before arch-specific code is given the chance to initialise any
firmware and generate any device trees.

Most of this series is fairly trivial, in moving code, making definitions
arch-local or available via a header, endian sanitisation.  The PCI code changes
are probably most 'interesting', in that I have made the config space accesses
available to those not using the PC ioport access method, plus wrapped
initialisations of config space with cpu_to_leXX accesses.

Changes since V1:
- Merged up, V1 patches now upstream are obv. not included here
- No longer uses PRIx64 etc., defining __SANE_USERSPACE_TYPES__ for LL64 on PPC
- Returns kvm__recommended_cpus (and max cpus) to generic code, but fixes them
  so that they cope gracefully with KVM supporting neither CAP.  (A separate
  patch submitted for PPC KVM returns a useful number of CPUs.)
- Made hugetlbfs guest RAM mapping code generic, allow x86 to use it
- Drop unnecessary ifdef around symbol__init()
- Un-broke ioport PCI config access :o)
- Rolled in other review comments (e.g. removal of  0xff in term.c, fixing
  pci_config_address union, create both kvm_cpu__emulate_mmio and _io)

Applies on top of Pekka's linux-kvm.git as of today.


Cheers,


Matt


Matt Evans (23):
  kvm tools: Only build/init i8042 on x86
  kvm tools: Add Makefile parameter for kernel include path
  kvm tools: Re-arrange Makefile to heed CFLAGS before checking for
optional libs
  kvm tools: Get correct 64-bit types on PPC64 and link appropriately
  kvm tools: Add arch-specific KVM_RUN exit handling via
kvm_cpu__handle_exit()
  kvm tools: Don't die if KVM_CAP_NR_VCPUS isn't available
  kvm tools: Fix KVM_RUN exit code check
  kvm tools: Add kvm__arch_periodic_poll()
  kvm tools: Move arch-specific cmdline init into
kvm__arch_set_cmdline()
  kvm tools: Add CONSOLE_HV term type and allow it to be selected
  kvm tools: Fix term_getc(), term_getc_iov() endian bugs
  kvm tools: Allow initrd_check() to match a cpio
  kvm tools: Allow load_flat_binary() to load an initrd alongside
  kvm tools: Initialise PCI before devices start getting registered
with PCI
  kvm tools: Perform CPU and firmware setup after devices are added
  kvm tools: Init IRQs after determining nrcpus
  kvm tools: Add ability to map guest RAM from hugetlbfs
  kvm tools: Move PCI_MAX_DEVICES to pci.h
  kvm tools: Endian-sanitise pci.h and PCI device setup
  kvm tools: Correctly set virtio-pci bar_size and remove hardwired
address
  kvm tools: Add pci__config_{rd,wr}(), pci__find_dev()
  kvm tools: Arch-specific define for PCI MMIO allocation area
  kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io()

 tools/kvm/Makefile   |   99 --
 tools/kvm/builtin-run.c  |   61 +++
 tools/kvm/hw/pci-shmem.c |   23 ---
 tools/kvm/hw/vesa.c  |   15 +++--
 tools/kvm/include/kvm/ioport.h   |   11 ++--
 tools/kvm/include/kvm/kvm-cpu.h  |2 +
 tools/kvm/include/kvm/kvm.h  |8 ++-
 tools/kvm/include/kvm/pci.h  |   46 ++
 tools/kvm/include/kvm/term.h |1 +
 tools/kvm/include/kvm/util.h |4 +
 tools/kvm/include/linux/types.h  |1 +
 tools/kvm/kvm-cpu.c  |   46 --
 tools/kvm/kvm.c  |   28 ++---
 tools/kvm/pci.c  |   76 ++-
 tools/kvm/term.c |7 +--
 tools/kvm/util.c |   45 ++
 tools/kvm/virtio/pci.c   |   48 --
 tools/kvm/x86/include/kvm/kvm-arch.h |5 ++
 tools/kvm/x86/include/kvm/kvm-cpu-arch.h |   17 +-
 tools/kvm/x86/kvm-cpu.c  |5 ++
 tools/kvm/x86/kvm.c  |   52 ++--
 21 files changed, 396 insertions(+), 204 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 01/23] kvm tools: Only build/init i8042 on x86

2011-12-08 Thread Matt Evans
Not every architecture has an i8042 kbd controller, so only use this when
building for x86.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile  |2 +-
 tools/kvm/builtin-run.c |2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 243886e..f58a1d8 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -77,7 +77,6 @@ OBJS  += util/strbuf.o
 OBJS   += virtio/9p.o
 OBJS   += virtio/9p-pdu.o
 OBJS   += hw/vesa.o
-OBJS   += hw/i8042.o
 OBJS   += hw/pci-shmem.o
 OBJS   += kvm-ipc.o
 
@@ -153,6 +152,7 @@ ifeq ($(ARCH),x86)
OBJS+= x86/kvm.o
OBJS+= x86/kvm-cpu.o
OBJS+= x86/mptable.o
+   OBJS+= hw/i8042.o
 # Exclude BIOS object files from header dependencies.
OTHEROBJS   += x86/bios.o
OTHEROBJS   += x86/bios/bios-rom.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index d5abeb4..e273398 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -943,7 +943,9 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
kvm__init_ram(kvm);
 
+#ifdef CONFIG_X86
kbd__init(kvm);
+#endif
 
pci_shmem__init(kvm);
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 03/23] kvm tools: Re-arrange Makefile to heed CFLAGS before checking for optional libs

2011-12-08 Thread Matt Evans
The checks for optional libraries build code to perform the tests, so should
respect certain CFLAGS -- in particular, -m64 so we check for 64bit libraries if
they're required.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile |   86 ++-
 1 files changed, 44 insertions(+), 42 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index f85a154..009a6ba 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -85,48 +85,6 @@ OBJS += hw/vesa.o
 OBJS   += hw/pci-shmem.o
 OBJS   += kvm-ipc.o
 
-FLAGS_BFD := $(CFLAGS) -lbfd
-has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
-ifeq ($(has_bfd),y)
-   CFLAGS  += -DCONFIG_HAS_BFD
-   OBJS+= symbol.o
-   LIBS+= -lbfd
-endif
-
-FLAGS_VNCSERVER := $(CFLAGS) -lvncserver
-has_vncserver := $(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER))
-ifeq ($(has_vncserver),y)
-   OBJS+= ui/vnc.o
-   CFLAGS  += -DCONFIG_HAS_VNCSERVER
-   LIBS+= -lvncserver
-endif
-
-FLAGS_SDL := $(CFLAGS) -lSDL
-has_SDL := $(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL))
-ifeq ($(has_SDL),y)
-   OBJS+= ui/sdl.o
-   CFLAGS  += -DCONFIG_HAS_SDL
-   LIBS+= -lSDL
-endif
-
-FLAGS_ZLIB := $(CFLAGS) -lz
-has_ZLIB := $(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB))
-ifeq ($(has_ZLIB),y)
-   CFLAGS  += -DCONFIG_HAS_ZLIB
-   LIBS+= -lz
-endif
-
-FLAGS_AIO := $(CFLAGS) -laio
-has_AIO := $(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO))
-ifeq ($(has_AIO),y)
-   CFLAGS  += -DCONFIG_HAS_AIO
-   LIBS+= -laio
-endif
-
-LIBS   += -lrt
-LIBS   += -lpthread
-LIBS   += -lutil
-
 # Additional ARCH settings for x86
 ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
   -e s/arm.*/arm/ -e s/sa110/arm/ \
@@ -172,6 +130,50 @@ else
UNSUPP_ERR =
 endif
 
+
+FLAGS_BFD := $(CFLAGS) -lbfd
+has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
+ifeq ($(has_bfd),y)
+   CFLAGS  += -DCONFIG_HAS_BFD
+   OBJS+= symbol.o
+   LIBS+= -lbfd
+endif
+
+FLAGS_VNCSERVER := $(CFLAGS) -lvncserver
+has_vncserver := $(call try-cc,$(SOURCE_VNCSERVER),$(FLAGS_VNCSERVER))
+ifeq ($(has_vncserver),y)
+   OBJS+= ui/vnc.o
+   CFLAGS  += -DCONFIG_HAS_VNCSERVER
+   LIBS+= -lvncserver
+endif
+
+FLAGS_SDL := $(CFLAGS) -lSDL
+has_SDL := $(call try-cc,$(SOURCE_SDL),$(FLAGS_SDL))
+ifeq ($(has_SDL),y)
+   OBJS+= ui/sdl.o
+   CFLAGS  += -DCONFIG_HAS_SDL
+   LIBS+= -lSDL
+endif
+
+FLAGS_ZLIB := $(CFLAGS) -lz
+has_ZLIB := $(call try-cc,$(SOURCE_ZLIB),$(FLAGS_ZLIB))
+ifeq ($(has_ZLIB),y)
+   CFLAGS  += -DCONFIG_HAS_ZLIB
+   LIBS+= -lz
+endif
+
+FLAGS_AIO := $(CFLAGS) -laio
+has_AIO := $(call try-cc,$(SOURCE_AIO),$(FLAGS_AIO))
+ifeq ($(has_AIO),y)
+   CFLAGS  += -DCONFIG_HAS_AIO
+   LIBS+= -laio
+endif
+
+LIBS   += -lrt
+LIBS   += -lpthread
+LIBS   += -lutil
+
+
 DEPS   := $(patsubst %.o,%.d,$(OBJS))
 OBJS   += $(OTHEROBJS)
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 02/23] kvm tools: Add Makefile parameter for kernel include path

2011-12-08 Thread Matt Evans
This patch adds an 'I' parameter to override the default kernel include path of
'../../include'.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index f58a1d8..f85a154 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -9,7 +9,12 @@ else
E = @\#
Q =
 endif
-export E Q
+ifneq ($(I), )
+   KINCL_PATH=$(I)
+else
+   KINCL_PATH=../..
+endif
+export E Q KINCL_PATH
 
 include config/utilities.mak
 include config/feature-tests.mak
@@ -176,7 +181,7 @@ DEFINES += -DKVMTOOLS_VERSION='$(KVMTOOLS_VERSION)'
 DEFINES+= -DBUILD_ARCH='$(ARCH)'
 
 KVM_INCLUDE := include
-CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I../../include -I../../arch/$(ARCH)/include/ -Os -g
+CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -Os -g
 
 ifneq ($(WERROR),0)
WARNINGS += -Werror
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and link appropriately

2011-12-08 Thread Matt Evans
kvmtool's types.h includes asm/types.h, which by default on PPC64 brings in
int-l64.h; define __SANE_USERSPACE_TYPES__ to get LL64 types.

This patch also adds CFLAGS to the final link, so that any -m64 is obeyed
when linking, too.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/Makefile  |2 +-
 tools/kvm/include/linux/types.h |1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 009a6ba..57dc521 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -218,7 +218,7 @@ KVMTOOLS-VERSION-FILE:
 
 $(PROGRAM): $(DEPS) $(OBJS)
$(E)   LINK $@
-   $(Q) $(CC) $(OBJS) $(LIBS) -o $@
+   $(Q) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $@
 
 $(GUEST_INIT): guest/init.c
$(E)   LINK $@
diff --git a/tools/kvm/include/linux/types.h b/tools/kvm/include/linux/types.h
index 357799c..5e20f10 100644
--- a/tools/kvm/include/linux/types.h
+++ b/tools/kvm/include/linux/types.h
@@ -2,6 +2,7 @@
 #define LINUX_TYPES_H
 
 #include kvm/compiler.h
+#define __SANE_USERSPACE_TYPES__   /* For PPC64, to get LL64 types */
 #include asm/types.h
 
 typedef __u64 u64;
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 05/23] kvm tools: Add arch-specific KVM_RUN exit handling via kvm_cpu__handle_exit()

2011-12-08 Thread Matt Evans
This patch creates a new function in x86/kvm-cpu.c, kvm_cpu__handle_exit(), in
which arch-specific exit reasons can be handled outside of the common runloop.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/include/kvm/kvm-cpu.h |2 ++
 tools/kvm/kvm-cpu.c |   10 --
 tools/kvm/x86/kvm-cpu.c |5 +
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm-cpu.h b/tools/kvm/include/kvm/kvm-cpu.h
index 719e286..15618f1 100644
--- a/tools/kvm/include/kvm/kvm-cpu.h
+++ b/tools/kvm/include/kvm/kvm-cpu.h
@@ -2,6 +2,7 @@
 #define KVM__KVM_CPU_H
 
 #include kvm/kvm-cpu-arch.h
+#include stdbool.h
 
 struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id);
 void kvm_cpu__delete(struct kvm_cpu *vcpu);
@@ -11,6 +12,7 @@ void kvm_cpu__enable_singlestep(struct kvm_cpu *vcpu);
 void kvm_cpu__run(struct kvm_cpu *vcpu);
 void kvm_cpu__reboot(void);
 int kvm_cpu__start(struct kvm_cpu *cpu);
+bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu);
 
 int kvm_cpu__get_debug_fd(void);
 void kvm_cpu__set_debug_fd(int fd);
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 5aba3bb..9bc0796 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -137,8 +137,14 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
goto exit_kvm;
case KVM_EXIT_SHUTDOWN:
goto exit_kvm;
-   default:
-   goto panic_kvm;
+   default: {
+   bool ret;
+
+   ret = kvm_cpu__handle_exit(cpu);
+   if (!ret)
+   goto panic_kvm;
+   break;
+   }
}
kvm_cpu__handle_coalesced_mmio(cpu);
}
diff --git a/tools/kvm/x86/kvm-cpu.c b/tools/kvm/x86/kvm-cpu.c
index b26b208..a0d10cc 100644
--- a/tools/kvm/x86/kvm-cpu.c
+++ b/tools/kvm/x86/kvm-cpu.c
@@ -212,6 +212,11 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)
kvm_cpu__setup_msrs(vcpu);
 }
 
+bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)
+{
+   return false;
+}
+
 static void print_dtable(const char *name, struct kvm_dtable *dtable)
 {
dprintf(debug_fd,  %s %016llx  %08hx\n,
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 06/23] kvm tools: Don't die if KVM_CAP_NR_VCPUS isn't available

2011-12-08 Thread Matt Evans
We die() if we can't read KVM_CAP_NR_VCPUS, but the API docs suggest to assume
the value 4 in this case.  This is pertinent to PPC KVM, which currently
does not support this CAP.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm.c |6 +-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 0356d74..0bbe9ba 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -266,7 +266,11 @@ int kvm__recommended_cpus(struct kvm *kvm)
 
ret = ioctl(kvm-sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
if (ret = 0)
-   die_perror(KVM_CAP_NR_VCPUS);
+   /*
+* api.txt states that if KVM_CAP_NR_VCPUS does not exist,
+* assume 4.
+*/
+   return 4;
 
return ret;
 }
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 07/23] kvm tools: Fix KVM_RUN exit code check

2011-12-08 Thread Matt Evans
kvm_cpu__run() currently die()s if KVM_RUN returns non-zero.  Some architectures
may return positive values in non-error cases, whereas real errors are always
negative return values.  Check for those instead.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm-cpu.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 9bc0796..884a89f 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -30,7 +30,7 @@ void kvm_cpu__run(struct kvm_cpu *vcpu)
int err;
 
err = ioctl(vcpu-vcpu_fd, KVM_RUN, 0);
-   if (err  (errno != EINTR  errno != EAGAIN))
+   if (err  0  (errno != EINTR  errno != EAGAIN))
die_perror(KVM_RUN failed);
 }
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 08/23] kvm tools: Add kvm__arch_periodic_poll()

2011-12-08 Thread Matt Evans
Currently, the SIGALRM handler calls device poll functions (for serial, virtio
console) directly.  Which devices are present and which require polling is a
system-specific decision, so create a new function called from common code 
move the x86-specific poll calls into it.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c |3 +--
 tools/kvm/include/kvm/kvm.h |1 +
 tools/kvm/x86/kvm.c |8 
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index e273398..47a2f09 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -522,8 +522,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
 
 static void handle_sigalrm(int sig)
 {
-   serial8250__inject_interrupt(kvm);
-   virtio_console__inject_interrupt(kvm);
+   kvm__arch_periodic_poll(kvm);
 }
 
 static void handle_stop(int fd, u32 type, u32 len, u8 *msg)
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index ca1acc0..60842d5 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -56,6 +56,7 @@ void kvm__remove_socket(const char *name);
 void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const 
char *name);
 void kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
+void kvm__arch_periodic_poll(struct kvm *kvm);
 
 int load_flat_binary(struct kvm *kvm, int fd);
 bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline, u16 vidmode);
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index ac6c91e..70df27e 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -4,6 +4,8 @@
 #include kvm/interrupt.h
 #include kvm/mptable.h
 #include kvm/util.h
+#include kvm/8250-serial.h
+#include kvm/virtio-console.h
 
 #include asm/bootparam.h
 #include linux/kvm.h
@@ -328,3 +330,9 @@ void kvm__arch_setup_firmware(struct kvm *kvm)
/* MP table */
mptable_setup(kvm, kvm-nrcpus);
 }
+
+void kvm__arch_periodic_poll(struct kvm *kvm)
+{
+   serial8250__inject_interrupt(kvm);
+   virtio_console__inject_interrupt(kvm);
+}
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 09/23] kvm tools: Move arch-specific cmdline init into kvm__arch_set_cmdline()

2011-12-08 Thread Matt Evans
Different systems will want different base kernel commandlines, e.g. non-x86
systems probably don't need noapic, i8042.* etc., so set the commandline up in
arch-specific code.  Then, if the resulting commandline is empty, don't strcat a
space onto the front.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c |   12 +---
 tools/kvm/include/kvm/kvm.h |1 +
 tools/kvm/x86/kvm.c |   11 +++
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 47a2f09..68a3246 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -835,13 +835,11 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
vidmode = 0;
 
memset(real_cmdline, 0, sizeof(real_cmdline));
-   strcpy(real_cmdline, noapic noacpi pci=conf1 reboot=k panic=1 
i8042.direct=1 
-   i8042.dumbkbd=1 i8042.nopnp=1);
-   if (vnc || sdl) {
-   strcat(real_cmdline,  video=vesafb console=tty0);
-   } else
-   strcat(real_cmdline,  console=ttyS0 earlyprintk=serial 
i8042.noaux=1);
-   strcat(real_cmdline,  );
+   kvm__arch_set_cmdline(real_cmdline, vnc || sdl);
+
+   if (strlen(real_cmdline)  0)
+   strcat(real_cmdline,  );
+
if (kernel_cmdline)
strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
 
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 60842d5..fae2ba9 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -53,6 +53,7 @@ int kvm__get_sock_by_instance(const char *name);
 int kvm__enumerate_instances(int (*callback)(const char *name, int pid));
 void kvm__remove_socket(const char *name);
 
+void kvm__arch_set_cmdline(char *cmdline, bool video);
 void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const 
char *name);
 void kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 70df27e..b49b372 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -119,6 +119,17 @@ void kvm__init_ram(struct kvm *kvm)
}
 }
 
+/* Arch-specific commandline setup */
+void kvm__arch_set_cmdline(char *cmdline, bool video)
+{
+   strcpy(cmdline, noapic noacpi pci=conf1 reboot=k panic=1 
i8042.direct=1 
+   i8042.dumbkbd=1 i8042.nopnp=1);
+   if (video) {
+   strcat(cmdline,  video=vesafb console=tty0);
+   } else
+   strcat(cmdline,  console=ttyS0 earlyprintk=serial 
i8042.noaux=1);
+}
+
 /* Architecture-specific KVM init */
 void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const 
char *name)
 {
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 10/23] kvm tools: Add CONSOLE_HV term type and allow it to be selected

2011-12-08 Thread Matt Evans
This patch paves the way for adding a hypervisor console, useful on systems that
support one out of the box yet don't have either serial port or virtio console
support (e.g. kernels expecting POWER SPAPR).

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c  |8 ++--
 tools/kvm/include/kvm/term.h |1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 68a3246..c067685 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -416,7 +416,7 @@ static const struct option options[] = {
OPT_BOOLEAN('\0', rng, virtio_rng, Enable virtio Random Number 
Generator),
OPT_CALLBACK('\0', 9p, NULL, dir_to_share,tag_name,
 Enable virtio 9p to share files between host and guest, 
virtio_9p_rootdir_parser),
-   OPT_STRING('\0', console, console, serial or virtio,
+   OPT_STRING('\0', console, console, serial, virtio or hv,
Console to use),
OPT_STRING('\0', dev, dev, device_file, KVM device file),
OPT_CALLBACK('\0', tty, NULL, tty id,
@@ -776,8 +776,12 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
if (!strncmp(console, virtio, 6))
active_console  = CONSOLE_VIRTIO;
-   else
+   else if (!strncmp(console, serial, 6))
active_console  = CONSOLE_8250;
+   else if (!strncmp(console, hv, 2))
+   active_console = CONSOLE_HV;
+   else
+   pr_warning(No console!);
 
if (!host_ip)
host_ip = DEFAULT_HOST_ADDR;
diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h
index 938c26f..a6a9822 100644
--- a/tools/kvm/include/kvm/term.h
+++ b/tools/kvm/include/kvm/term.h
@@ -6,6 +6,7 @@
 
 #define CONSOLE_8250   1
 #define CONSOLE_VIRTIO 2
+#define CONSOLE_HV 3
 
 int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term);
 int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term);
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 11/23] kvm tools: Fix term_getc(), term_getc_iov() endian bugs

2011-12-08 Thread Matt Evans
term_getc()'s int c has one byte written into it (at its lowest address) by
read_in_full().  This is expected to be the least significant byte, but that
isn't the case on BE!  Use correct type, unsigned char.  A similar issue exists
in term_getc_iov(), which needs to write a char to the iov rather than an int.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/term.c |7 ++-
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index fb5d71c..b7d8934 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/term.c
@@ -30,16 +30,13 @@ int term_fds[4][2];
 
 int term_getc(int who, int term)
 {
-   int c;
+   unsigned char c;
 
if (who != active_console)
return -1;
-
if (read_in_full(term_fds[term][TERM_FD_IN], c, 1)  0)
return -1;
 
-   c = 0xff;
-
if (term_got_escape) {
term_got_escape = false;
if (c == 'x')
@@ -84,7 +81,7 @@ int term_getc_iov(int who, struct iovec *iov, int iovcnt, int 
term)
if (c  0)
return 0;
 
-   *((int *)iov[TERM_FD_IN].iov_base)  = c;
+   *((char *)iov[TERM_FD_IN].iov_base) = (char)c;
 
return sizeof(char);
 }
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 12/23] kvm tools: Allow initrd_check() to match a cpio

2011-12-08 Thread Matt Evans
cpios are valid as initrds too, so allow them through the check.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/kvm.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 0bbe9ba..d26e3d7 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -351,10 +351,11 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, 
const char *name)
 /* RFC 1952 */
 #define GZIP_ID1   0x1f
 #define GZIP_ID2   0x8b
-
+#define CPIO_MAGIC 0707
+/* initrd may be gzipped, or a plain cpio */
 static bool initrd_check(int fd)
 {
-   unsigned char id[2];
+   unsigned char id[4];
 
if (read_in_full(fd, id, ARRAY_SIZE(id))  0)
return false;
@@ -362,7 +363,8 @@ static bool initrd_check(int fd)
if (lseek(fd, 0, SEEK_SET)  0)
die_perror(lseek);
 
-   return id[0] == GZIP_ID1  id[1] == GZIP_ID2;
+   return (id[0] == GZIP_ID1  id[1] == GZIP_ID2) ||
+   !memcmp(id, CPIO_MAGIC, 4);
 }
 
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 13/23] kvm tools: Allow load_flat_binary() to load an initrd alongside

2011-12-08 Thread Matt Evans
This patch passes the initrd fd and commandline to load_flat_binary(), which may
be used to load both the kernel  an initrd (stashing or inserting the
commandline as appropriate) in the same way that load_bzimage() does.  This is
especially useful when load_bzimage() is unused for a particular
architecture. :-)

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/include/kvm/kvm.h |2 +-
 tools/kvm/kvm.c |   10 ++
 tools/kvm/x86/kvm.c |   13 ++---
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index fae2ba9..5fe6e75 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -59,7 +59,7 @@ void kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
 void kvm__arch_periodic_poll(struct kvm *kvm);
 
-int load_flat_binary(struct kvm *kvm, int fd);
+int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline);
 bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline, u16 vidmode);
 
 /*
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index d26e3d7..c54f886 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -388,23 +388,25 @@ bool kvm__load_kernel(struct kvm *kvm, const char 
*kernel_filename,
 
ret = load_bzimage(kvm, fd_kernel, fd_initrd, kernel_cmdline, vidmode);
 
-   if (initrd_filename)
-   close(fd_initrd);
-
if (ret)
goto found_kernel;
 
pr_warning(%s is not a bzImage. Trying to load it as a flat 
binary..., kernel_filename);
 
-   ret = load_flat_binary(kvm, fd_kernel);
+   ret = load_flat_binary(kvm, fd_kernel, fd_initrd, kernel_cmdline);
+
if (ret)
goto found_kernel;
 
+   if (initrd_filename)
+   close(fd_initrd);
close(fd_kernel);
 
die(%s is not a valid bzImage or flat binary, kernel_filename);
 
 found_kernel:
+   if (initrd_filename)
+   close(fd_initrd);
close(fd_kernel);
 
return ret;
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index b49b372..a116f4b 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -197,17 +197,24 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
 #define BOOT_PROTOCOL_REQUIRED 0x206
 #define LOAD_HIGH  0x01
 
-int load_flat_binary(struct kvm *kvm, int fd)
+int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char 
*kernel_cmdline)
 {
void *p;
int nr;
 
-   if (lseek(fd, 0, SEEK_SET)  0)
+   /*
+* Some architectures may support loading an initrd alongside the flat 
kernel,
+* but we do not.
+*/
+   if (fd_initrd != -1)
+   pr_warning(Loading initrd with flat binary not supported.);
+
+   if (lseek(fd_kernel, 0, SEEK_SET)  0)
die_perror(lseek);
 
p = guest_real_to_host(kvm, BOOT_LOADER_SELECTOR, BOOT_LOADER_IP);
 
-   while ((nr = read(fd, p, 65536))  0)
+   while ((nr = read(fd_kernel, p, 65536))  0)
p += nr;
 
kvm-boot_selector  = BOOT_LOADER_SELECTOR;
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH V2 14/23] kvm tools: Initialise PCI before devices start getting registered with PCI

2011-12-08 Thread Matt Evans
Re-arrange pci__init() in builtin-run such that it comes before devices are
initialised.

Signed-off-by: Matt Evans m...@ozlabs.org
---
 tools/kvm/builtin-run.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index c067685..99db522 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -828,6 +828,8 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
kvm-nrcpus = nrcpus;
 
+   pci__init();
+
/*
 * vidmode should be either specified
 * either set by default
@@ -895,8 +897,6 @@ int kvm_cmd_run(int argc, const char **argv, const char 
*prefix)
 
serial8250__init(kvm);
 
-   pci__init();
-
if (active_console == CONSOLE_VIRTIO)
virtio_console__init(kvm);
 
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   >