Re: [kvm-devel] [RFC/PATCH 15/15] guest: virtio device support, and kvm hypercalls

2008-03-22 Thread Carsten Otte
Rusty Russell wrote:
 On Friday 21 March 2008 19:15:47 Christian Borntraeger wrote:
 Am Freitag, 21. März 2008 schrieb Rusty Russell:
 Hmm, panic on device_register fail, but -ENOMEM on add_shared_memory
 fail? My theory was that since this is boot time, panic() is the right
 thing.
 Good spot, but I agree with Carsten. Drivers should not panic. I have
 module load/unload capability on my long term todo list, but I can change
 the panic now.
 
 Yep, that makes sense.  For lguest, we panic: it's always at boot time so if 
 it fails we should die early to make it easier to diagnose (and that makes 
 sure it happens before we lose our early console).
Diangnostic is easy here at any time during the boot process: we've 
got our store status ioctl that userspace calls after guest execution 
has ended. It causes all cpus to store their register content and such 
into the cpu's lowcore area. Then it writes out our memory to a dump 
image, which lkcdutils and/or crash can read.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] kvm pxe boot

2008-03-22 Thread Matthias Pfafferodt
Hello,

I'm using libvirt 0.4.1 and kvm version 63. I try to boot using pxe. I noticed 
that qemu uses the ne2k_pci network card as default while kvm has a rtl8139 
card. And here I start to get strange results:

With qemu I can use the default network card [1] or the rtl8139 card [2] to 
boot from the network.

[1] /usr/bin/qemu -m 1024 -boot n \
 -net nic,macaddr=00:16:3e:26:fc:ac \
 -net tap,script=./qemu-ifup

[2] /usr/bin/qemu -m 1024 -boot n \
 -net nic,macaddr=00:16:3e:26:fc:ac,model=rtl8139 \
 -net tap,script=./qemu-ifup

With kvm I have to specify the model to boot from the network. So [3] is 
working while [4] only loops trying to find the dhcp server. In both cases 
the same network card seems to be used (rtl8139).

[3] /usr/bin/qemu-kvm -m 1024 -boot n \
 -net nic,macaddr=00:16:3e:26:fc:ac,model=rtl8139 \
 -net tap,script=./qemu-ifup

[4] /usr/bin/qemu-kvm -m 1024 -boot n \
 -net nic,macaddr=00:16:3e:26:fc:ac \
 -net tap,script=./qemu-ifup

All network cards are working fine with kvm if set in the command line but the 
default setup is unable to boot using pxe. I want to use kvm with libvirt and 
there I have to use the default setup (it is not possible to set the model). 

I changed the default card to a ne2k_pci and pxe boot is now also working 
without setting the model in the command line. A patch is attached (against 
kvm-63).

Matthias Pfafferodt
--- qemu.orig/vl.c
+++ qemu/vl.c
@@ -9495,7 +9495,7 @@
 	char buf[1024];
 if (net_boot  (1  i)) {
 if (model == NULL)
-model = rtl8139;
+model = ne2k_pci;
 snprintf(buf, sizeof(buf), %s/pxe-%s.bin, bios_dir, model);
 if (get_image_size(buf)  0) {
 if (nb_option_roms = MAX_OPTION_ROMS) {
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH] 'make clean' is eager to delete config.mak files

2008-03-22 Thread Ryota OZAKI
Hi all,

Current 'make clean' deletes config.mak files so
that we have to ./configure again after doing that.
This behavior is different from that of standard
'make clean'.

This patch introduces 'make distclean' to delete
config.mak files instead of 'make clean', following
a standard manner of Makefile.

Thanks,
ozaki-r
--
 Makefile |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index d4cd877..83f9387 100644
--- a/Makefile
+++ b/Makefile
@@ -91,4 +91,6 @@ clean:
for i in $(if $(WANT_MODULE), kernel) user libkvm qemu; do \
make -C $$i clean; \
done
+
+distclean: clean
rm -f config.mak user/config.mak

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] question: HPET for multiple VMs

2008-03-22 Thread Ryota OZAKI
Hi all,

Current kvm allows only one VM to use HPET. Is
there a plan to implement a functionality to
allow multiple VMs to use HPET? If so, how
about the status of that?

And I would like to ask right and wrong to
implement the functionality in terms of need
and efficiency (scalability and time accuracy).

Thanks,
ozaki-r

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] W2k3 Installation fails with segfault.

2008-03-22 Thread Fabian Deutsch
Hey,

I just tried the latest kvm head (kernel+userspace). But my fresh W2k3 
Installation failed with a segfault.
Facts:

CPU:
model name  : Intel(R) Xeon(R) CPU   X3210  @ 2.13GHz
MemTotal:  8196292 kB

Host:
Fedora release 8 (Werewolf) (up to date)
Linux fry.localdomain 2.6.24.3-34.fc8 #1 SMP Wed Mar 12 16:51:49 EDT 2008 
x86_64 x86_64 x86_64 GNU/Linux

KVM:
kernel: kvm-63-791-g361be34
userspace: kvm-63-105-g92b1c7d

Guest:
Windows Server 2003 Standard

Qemu:
/usr/bin/qemu-system-x86_64 -M pc -m 1024 -smp 2 -monitor pty -no-acpi -boot c 
-hda /root/win_smp.img -cdrom /root/win-all-in-one.iso -net 
nic,macaddr=52:54:00:d8:65:c9,vlan=0 -net tap,fd=12,script=,vlan=0 -usb -vnc 
127.0.0.1:0 
char device redirected to /dev/pts/2

Bug:
During installation (17min left) the (later) following segfault appears.
Maybe something like 
http://sourceforge.net/tracker/index.php?func=detailaid=1890597group_id=180599atid=893831.


-- SNIP --
Unable to handle kernel paging request at 00100100 RIP: 
 [882aca22] :kvm:kvm_mmu_slot_remove_write_access+0x3c/0x4f
PGD 1ead00067 PUD 1bedfd067 PMD 0 
Oops:  [1] SMP 
CPU 3 
Modules linked in: kvm_intel(U) kvm(U) tun ipt_MASQUERADE iptable_nat nf_nat 
nf_conntrack_ipv4 xt_state nf_conntrack ipt_REJECT xt_tcpudp iptable_filter 
ip_tables x_tables autofs4 fuse rfcomm l2cap bluetooth sunrpc bridge 
cpufreq_ondemand acpi_cpufreq loop dm_multipath ipv6 iTCO_wdt 
iTCO_vendor_support button i2c_i801 ipmi_msghandler i2c_core pcspkr e1000 
sr_mod cdrom sg floppy usb_storage ata_piix libata dm_snapshot dm_zero 
dm_mirror dm_mod shpchp 3w_9xxx sd_mod scsi_mod ext3 jbd mbcache uhci_hcd 
ohci_hcd ehci_hcd
Pid: 3737, comm: qemu-system-x86 Not tainted 2.6.24.3-34.fc8 #1
RIP: 0010:[882aca22]  [882aca22] 
:kvm:kvm_mmu_slot_remove_write_access+0x3c/0x4f
RSP: 0018:810210cc3e20  EFLAGS: 00010246
RAX:  RBX: 81016dccc000 RCX: 
RDX: 00100100 RSI: 0005 RDI: 81016dccc000
RBP: 810210cc3e88 R08: b2226490 R09: 
R10: 0001 R11: 8101ced7 R12: 
R13: 81016dccc020 R14: 0006 R15: 7fffb2226620
FS:  2ad64360() GS:81021fc01f00() knlGS:
CS:  0010 DS: 002b ES: 002b CR0: 8005003b
CR2: 00100100 CR3: 000210cf8000 CR4: 26a0
DR0:  DR1:  DR2: 
DR3:  DR6: 0ff0 DR7: 0400
Process qemu-system-x86 (pid: 3737, threadinfo 810210cc2000, task 
810194171160)
Stack:  882a8f30 0008 810210cc3eb8 00011d9cf3c0
 810210cc3e88 7fffb2226130 81016dccc000 0006
 882a7243 810194171160 810210cc3eb8 81016ec09b60
Call Trace:
 [882a8f30] :kvm:kvm_vm_ioctl_get_dirty_log+0x4d/0x93
 [882a7243] :kvm:kvm_vm_ioctl+0x1a4/0x1c8
 [810fa199] file_has_perm+0x94/0xa3
 [810ac005] do_ioctl+0x21/0x6b
 [810ac292] vfs_ioctl+0x243/0x25c
 [810ac2fc] sys_ioctl+0x51/0x71
 [8100c005] tracesys+0xd5/0xda


Code: 48 8b 02 0f 18 08 48 8d 87 f0 2a 00 00 48 39 c2 75 bb c3 53 
RIP  [882aca22] :kvm:kvm_mmu_slot_remove_write_access+0x3c/0x4f
 RSP 810210cc3e20
CR2: 00100100
---[ end trace 43c0403702b30db0 ]---
-- SNAP --

- fabian

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [RFC/PATCH 03/15 v2] preparation: address of the 64bit extint parm in lowcore

2008-03-22 Thread Carsten Otte
From: Christian Borntraeger [EMAIL PROTECTED]

The address 0x11b8 is used by z/VM for pfault and diag 250 I/O to
provide a 64 bit extint parameter. virtio uses the same address, so
its time to update the lowcore structure.

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 include/asm-s390/lowcore.h |   15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

Index: kvm/include/asm-s390/lowcore.h
===
--- kvm.orig/include/asm-s390/lowcore.h
+++ kvm/include/asm-s390/lowcore.h
@@ -380,27 +380,32 @@ struct _lowcore
 /* whether the kernel died with panic() or not */
 __u32panic_magic;  /* 0xe00 */
 
-   __u8 pad13[0x1200-0xe04];  /* 0xe04 */
+   __u8 pad13[0x11b8-0xe04];  /* 0xe04 */
+
+   /* 64 bit extparam used for pfault, diag 250 etc  */
+   __u64ext_params2;   /* 0x11B8 */
+
+   __u8 pad14[0x1200-0x11C0];  /* 0x11C0 */
 
 /* System info area */ 
 
__u64floating_pt_save_area[16]; /* 0x1200 */
__u64gpregs_save_area[16];  /* 0x1280 */
__u32st_status_fixed_logout[4]; /* 0x1300 */
-   __u8 pad14[0x1318-0x1310];  /* 0x1310 */
+   __u8 pad15[0x1318-0x1310];  /* 0x1310 */
__u32prefixreg_save_area;   /* 0x1318 */
__u32fpt_creg_save_area;/* 0x131c */
-   __u8 pad15[0x1324-0x1320];  /* 0x1320 */
+   __u8 pad16[0x1324-0x1320];  /* 0x1320 */
__u32tod_progreg_save_area; /* 0x1324 */
__u32cpu_timer_save_area[2];/* 0x1328 */
__u32clock_comp_save_area[2];   /* 0x1330 */
-   __u8 pad16[0x1340-0x1338];  /* 0x1338 */ 
+   __u8 pad17[0x1340-0x1338];  /* 0x1338 */
__u32access_regs_save_area[16]; /* 0x1340 */ 
__u64cregs_save_area[16];   /* 0x1380 */
 
/* align to the top of the prefix area */
 
-   __u8 pad17[0x2000-0x1400];  /* 0x1400 */
+   __u8 pad18[0x2000-0x1400];  /* 0x1400 */
 #endif /* !__s390x__ */
 } __attribute__((packed)); /* End structure*/
 



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [RFC/PATCH 02/15 v2] preparation: host memory management changes for s390 kvm

2008-03-22 Thread Carsten Otte
From: Heiko Carstens [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]

This patch changes the s390 memory management defintions to use the pgste field
for dirty and reference bit tracking of host and guest code. Usually on s390, 
dirty and referenced are tracked in storage keys, which belong to the physical
page. This changes with virtualization: The guest and host dirty/reference bits
are defined to be the logical OR of the values for the mapping and the physical
page. This patch implements the necessary changes in pgtable.h for s390.


There is a common code change in mm/rmap.c, the call to 
page_test_and_clear_young
must be moved. This is a no-op for all architecture but s390. page_referenced
checks the referenced bits for the physiscal page and for all mappings:
o The physical page is checked with page_test_and_clear_young.
o The mappings are checked with ptep_test_and_clear_young and friends.

Without pgstes (the current implementation on Linux s390) the physical page
check is implemented but the mapping callbacks are no-ops because dirty 
and referenced are not tracked in the s390 page tables. The pgstes introduces 
guest and host dirty and reference bits for s390 in the host mapping. These
mapping must be checked before page_test_and_clear_young resets the reference
bit. 

Signed-off-by: Heiko Carstens [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 include/asm-s390/pgtable.h |  109 +++--
 mm/rmap.c  |7 +-
 2 files changed, 110 insertions(+), 6 deletions(-)

Index: linux-host/include/asm-s390/pgtable.h
===
--- linux-host.orig/include/asm-s390/pgtable.h
+++ linux-host/include/asm-s390/pgtable.h
@@ -30,6 +30,7 @@
  */
 #ifndef __ASSEMBLY__
 #include linux/mm_types.h
+#include asm/atomic.h
 #include asm/bug.h
 #include asm/processor.h
 
@@ -258,6 +259,13 @@ extern char empty_zero_page[PAGE_SIZE];
  * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
  */
 
+/* Page status extended for virtualization */
+#define _PAGE_RCP_PCL  0x0080UL
+#define _PAGE_RCP_HR   0x0040UL
+#define _PAGE_RCP_HC   0x0020UL
+#define _PAGE_RCP_GR   0x0004UL
+#define _PAGE_RCP_GC   0x0002UL
+
 #ifndef __s390x__
 
 /* Bits in the segment table address-space-control-element */
@@ -513,6 +521,67 @@ static inline int pte_file(pte_t pte)
 #define __HAVE_ARCH_PTE_SAME
 #define pte_same(a,b)  (pte_val(a) == pte_val(b))
 
+static inline void rcp_lock(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+   atomic64_t *rcp = (atomic64_t *) (ptep + PTRS_PER_PTE);
+   preempt_disable();
+   atomic64_set_mask(_PAGE_RCP_PCL, rcp);
+#endif
+}
+
+static inline void rcp_unlock(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+   atomic64_t *rcp = (atomic64_t *) (ptep + PTRS_PER_PTE);
+   atomic64_clear_mask(_PAGE_RCP_PCL, rcp);
+   preempt_enable();
+#endif
+}
+
+static inline void rcp_set_bits(pte_t *ptep, unsigned long val)
+{
+#ifdef CONFIG_PGSTE
+   *(unsigned long *) (ptep + PTRS_PER_PTE) |= val;
+#endif
+}
+
+static inline int rcp_test_and_clear_bits(pte_t *ptep, unsigned long val)
+{
+#ifdef CONFIG_PGSTE
+   unsigned long ret;
+
+   ret = *(unsigned long *) (ptep + PTRS_PER_PTE);
+   *(unsigned long *) (ptep + PTRS_PER_PTE) = ~val;
+   return (ret  val) == val;
+#else
+   return 0;
+#endif
+}
+
+
+/* forward declaration for SetPageUptodate in page-flags.h*/
+static inline void page_clear_dirty(struct page *page);
+#include linux/page-flags.h
+
+static inline void ptep_rcp_copy(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+   struct page *page = virt_to_page(pte_val(*ptep));
+   unsigned int skey;
+
+   skey = page_get_storage_key(page_to_phys(page));
+   if (skey  _PAGE_CHANGED)
+   rcp_set_bits(ptep, _PAGE_RCP_GC);
+   if (skey  _PAGE_REFERENCED)
+   rcp_set_bits(ptep, _PAGE_RCP_GR);
+   if (rcp_test_and_clear_bits(ptep, _PAGE_RCP_HC))
+   SetPageDirty(page);
+   if (rcp_test_and_clear_bits(ptep, _PAGE_RCP_HR))
+   SetPageReferenced(page);
+#endif
+}
+
 /*
  * query functions pte_write/pte_dirty/pte_young only work if
  * pte_present() is true. Undefined behaviour if not..
@@ -599,6 +668,8 @@ static inline void pmd_clear(pmd_t *pmd)
 
 static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t 
*ptep)
 {
+   if (mm-context.pgstes)
+   ptep_rcp_copy(ptep);
pte_val(*ptep) = _PAGE_TYPE_EMPTY;
if (mm-context.noexec)
pte_val(ptep[PTRS_PER_PTE]) = _PAGE_TYPE_EMPTY;
@@ -667,6 +738,22 @@ static inline pte_t pte_mkyoung(pte_t pt
 static inline int ptep_test_and_clear_young(struct vm_area_struct *vma,
unsigned long addr, pte_t 

[kvm-devel] [RFC/PATCH 04/15 v2] preparation: split sysinfo defintions for kvm use

2008-03-22 Thread Carsten Otte
From: Christian Borntraeger [EMAIL PROTECTED]

drivers/s390/sysinfo.c uses the store system information intruction to query
the system about information of the machine, the LPAR and additional 
hypervisors. KVM has to implement the host part for this instruction. 

To avoid code duplication, this patch splits the common definitions from
sysinfo.c into a separate header file include/asm-s390/sysinfo.h for KVM use.

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 drivers/s390/sysinfo.c |  100 
 include/asm-s390/sysinfo.h |  112 +
 2 files changed, 113 insertions(+), 99 deletions(-)

Index: kvm/drivers/s390/sysinfo.c
===
--- kvm.orig/drivers/s390/sysinfo.c
+++ kvm/drivers/s390/sysinfo.c
@@ -11,111 +11,13 @@
 #include linux/init.h
 #include linux/delay.h
 #include asm/ebcdic.h
+#include asm/sysinfo.h
 
 /* Sigh, math-emu. Don't ask. */
 #include asm/sfp-util.h
 #include math-emu/soft-fp.h
 #include math-emu/single.h
 
-struct sysinfo_1_1_1 {
-   char reserved_0[32];
-   char manufacturer[16];
-   char type[4];
-   char reserved_1[12];
-   char model_capacity[16];
-   char sequence[16];
-   char plant[4];
-   char model[16];
-};
-
-struct sysinfo_1_2_1 {
-   char reserved_0[80];
-   char sequence[16];
-   char plant[4];
-   char reserved_1[2];
-   unsigned short cpu_address;
-};
-
-struct sysinfo_1_2_2 {
-   char format;
-   char reserved_0[1];
-   unsigned short acc_offset;
-   char reserved_1[24];
-   unsigned int secondary_capability;
-   unsigned int capability;
-   unsigned short cpus_total;
-   unsigned short cpus_configured;
-   unsigned short cpus_standby;
-   unsigned short cpus_reserved;
-   unsigned short adjustment[0];
-};
-
-struct sysinfo_1_2_2_extension {
-   unsigned int alt_capability;
-   unsigned short alt_adjustment[0];
-};
-
-struct sysinfo_2_2_1 {
-   char reserved_0[80];
-   char sequence[16];
-   char plant[4];
-   unsigned short cpu_id;
-   unsigned short cpu_address;
-};
-
-struct sysinfo_2_2_2 {
-   char reserved_0[32];
-   unsigned short lpar_number;
-   char reserved_1;
-   unsigned char characteristics;
-   unsigned short cpus_total;
-   unsigned short cpus_configured;
-   unsigned short cpus_standby;
-   unsigned short cpus_reserved;
-   char name[8];
-   unsigned int caf;
-   char reserved_2[16];
-   unsigned short cpus_dedicated;
-   unsigned short cpus_shared;
-};
-
-#define LPAR_CHAR_DEDICATED(1  7)
-#define LPAR_CHAR_SHARED   (1  6)
-#define LPAR_CHAR_LIMITED  (1  5)
-
-struct sysinfo_3_2_2 {
-   char reserved_0[31];
-   unsigned char count;
-   struct {
-   char reserved_0[4];
-   unsigned short cpus_total;
-   unsigned short cpus_configured;
-   unsigned short cpus_standby;
-   unsigned short cpus_reserved;
-   char name[8];
-   unsigned int caf;
-   char cpi[16];
-   char reserved_1[24];
-
-   } vm[8];
-};
-
-static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
-{
-   register int r0 asm(0) = (fc  28) | sel1;
-   register int r1 asm(1) = sel2;
-
-   asm volatile(
-  stsi 0(%2)\n
-   0: jz   2f\n
-   1: lhi  %0,%3\n
-   2:\n
-   EX_TABLE(0b,1b)
-   : +d (r0) : d (r1), a (sysinfo), K (-ENOSYS)
-   : cc, memory );
-   return r0;
-}
-
 static inline int stsi_0(void)
 {
int rc = stsi (NULL, 0, 0, 0);
Index: kvm/include/asm-s390/sysinfo.h
===
--- /dev/null
+++ kvm/include/asm-s390/sysinfo.h
@@ -0,0 +1,112 @@
+/*
+ * definition for store system information stsi
+ *
+ * Copyright IBM Corp. 2001,2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Ulrich Weigand [EMAIL PROTECTED]
+ *   Christian Borntraeger [EMAIL PROTECTED]
+ */
+
+struct sysinfo_1_1_1 {
+   char reserved_0[32];
+   char manufacturer[16];
+   char type[4];
+   char reserved_1[12];
+   char model_capacity[16];
+   char sequence[16];
+   char plant[4];
+   char model[16];
+};
+
+struct sysinfo_1_2_1 {
+   char reserved_0[80];
+   char sequence[16];
+   char plant[4];
+   char reserved_1[2];
+   unsigned short cpu_address;
+};
+
+struct sysinfo_1_2_2 {
+   char format;
+   char reserved_0[1];
+   unsigned short acc_offset;
+   

[kvm-devel] [RFC/PATCH 01/15 v2] preparation: provide hook to enable pgstes in user pagetable

2008-03-22 Thread Carsten Otte
From: Martin Schwidefsky [EMAIL PROTECTED]

The SIE instruction on s390 uses the 2nd half of the page table page to
virtualize the storage keys of a guest. This patch offers the s390_enable_sie
function, which reorganizes the page tables of a single-threaded process to
reserve space in the page table:
s390_enable_sie makes sure that the process is single threaded and then uses
dup_mm to create a new mm with reorganized page tables. The old mm is freed 
and the process has now a page status extended field after every page table.

Code that wants to exploit pgstes should SELECT CONFIG_PGSTE.

This patch has a small common code hit, namely making dup_mm non-static.

Edit (Carsten): I've modified Martin's patch, following Jeremy Fitzhardinge's
review feedback. Now we do have the prototype for dup_mm in
include/linux/sched.h.

Signed-off-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---

 arch/s390/Kconfig  |4 +++
 arch/s390/kernel/setup.c   |4 +++
 arch/s390/mm/pgtable.c |   53 ++---
 include/asm-s390/mmu.h |1 
 include/asm-s390/mmu_context.h |8 +-
 include/asm-s390/pgtable.h |1 
 include/linux/sched.h  |2 +
 kernel/fork.c  |2 -
 8 files changed, 70 insertions(+), 5 deletions(-)

Index: linux-host/arch/s390/Kconfig
===
--- linux-host.orig/arch/s390/Kconfig
+++ linux-host/arch/s390/Kconfig
@@ -55,6 +55,10 @@ config GENERIC_LOCKBREAK
default y
depends on SMP  PREEMPT
 
+config PGSTE
+   bool
+   default y if KVM
+
 mainmenu Linux Kernel Configuration
 
 config S390
Index: linux-host/arch/s390/kernel/setup.c
===
--- linux-host.orig/arch/s390/kernel/setup.c
+++ linux-host/arch/s390/kernel/setup.c
@@ -315,7 +315,11 @@ static int __init early_parse_ipldelay(c
 early_param(ipldelay, early_parse_ipldelay);
 
 #ifdef CONFIG_S390_SWITCH_AMODE
+#ifdef CONFIG_PGSTE
+unsigned int switch_amode = 1;
+#else
 unsigned int switch_amode = 0;
+#endif
 EXPORT_SYMBOL_GPL(switch_amode);
 
 static void set_amode_and_uaccess(unsigned long user_amode,
Index: linux-host/arch/s390/mm/pgtable.c
===
--- linux-host.orig/arch/s390/mm/pgtable.c
+++ linux-host/arch/s390/mm/pgtable.c
@@ -30,11 +30,27 @@
 #define TABLES_PER_PAGE4
 #define FRAG_MASK  15UL
 #define SECOND_HALVES  10UL
+
+void clear_table_pgstes(unsigned long *table)
+{
+   clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE/4);
+   memset(table + 256, 0, PAGE_SIZE/4);
+   clear_table(table + 512, _PAGE_TYPE_EMPTY, PAGE_SIZE/4);
+   memset(table + 768, 0, PAGE_SIZE/4);
+}
+
 #else
 #define ALLOC_ORDER2
 #define TABLES_PER_PAGE2
 #define FRAG_MASK  3UL
 #define SECOND_HALVES  2UL
+
+void clear_table_pgstes(unsigned long *table)
+{
+   clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE/2);
+   memset(table + 256, 0, PAGE_SIZE/2);
+}
+
 #endif
 
 unsigned long *crst_table_alloc(struct mm_struct *mm, int noexec)
@@ -153,7 +169,7 @@ unsigned long *page_table_alloc(struct m
unsigned long *table;
unsigned long bits;
 
-   bits = mm-context.noexec ? 3UL : 1UL;
+   bits = (mm-context.noexec || mm-context.pgstes) ? 3UL : 1UL;
spin_lock(mm-page_table_lock);
page = NULL;
if (!list_empty(mm-context.pgtable_list)) {
@@ -170,7 +186,10 @@ unsigned long *page_table_alloc(struct m
pgtable_page_ctor(page);
page-flags = ~FRAG_MASK;
table = (unsigned long *) page_to_phys(page);
-   clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
+   if (mm-context.pgstes)
+   clear_table_pgstes(table);
+   else
+   clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
spin_lock(mm-page_table_lock);
list_add(page-lru, mm-context.pgtable_list);
}
@@ -191,7 +210,7 @@ void page_table_free(struct mm_struct *m
struct page *page;
unsigned long bits;
 
-   bits = mm-context.noexec ? 3UL : 1UL;
+   bits = (mm-context.noexec || mm-context.pgstes) ? 3UL : 1UL;
bits = (__pa(table)  (PAGE_SIZE - 1)) / 256 / sizeof(unsigned long);
page = pfn_to_page(__pa(table)  PAGE_SHIFT);
spin_lock(mm-page_table_lock);
@@ -228,3 +247,31 @@ void disable_noexec(struct mm_struct *mm
mm-context.noexec = 0;
update_mm(mm, tsk);
 }
+
+/*
+ * switch on pgstes for its userspace process (for kvm)
+ */
+int s390_enable_sie(void)
+{
+   struct task_struct *tsk = current;
+   struct mm_struct *mm;
+
+   if (tsk-mm-context.pgstes)
+   return 0;
+   if (!tsk-mm || atomic_read(tsk-mm-mm_users)  1 ||
+   tsk-mm != tsk-active_mm || 

[kvm-devel] [RFC/PATCH 07/15 v2] kvm-s390: interrupt subsystem, cpu timer, waitpsw

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]

This patch contains the s390 interrupt subsystem (similar to in kernel apic)
including timer interrupts (similar to in-kernel-pit) and enabled wait
(similar to in kernel hlt).

In order to achieve that, this patch also introduces intercept handling
for instruction intercepts, and it implements load control instructions.

This patch introduces an ioctl KVM_S390_INTERRUPT which is valid for both
the vm file descriptors and the vcpu file descriptors. In case this ioctl is
issued against a vm file descriptor, the interrupt is considered floating.
Floating interrupts may be delivered to any virtual cpu in the configuration.

The following interrupts are supported:
SIGP STOP   - interprocessor signal that stops a remote cpu
SIGP SET PREFIX - interprocessor signal that sets the prefix register of a
  (stopped) remote cpu
INT EMERGENCY   - interprocessor interrupt, usually used to signal need_reshed
  and for smp_call_function() in the guest.
PROGRAM INT - exception during program execution such as page fault, illegal
  instruction and friends
RESTART - interprocessor signal that starts a stopped cpu
INT VIRTIO  - floating interrupt for virtio signalisation
INT SERVICE - floating interrupt for signalisations from the system
  service processor

struct kvm_s390_interrupt, which is submitted as ioctl parameter when injecting
an interrupt, also carrys parameter data for interrupts along with the interrupt
type. Interrupts on s390 usually have a state that represents the current
operation, or identifies which device has caused the interruption on s390.

kvm_s390_handle_wait() does handle waitpsw in two flavors: in case of a
disabled wait (that is, disabled for interrupts), we exit to userspace. In case
of an enabled wait we set up a timer that equals the cpu clock comparator value
and sleep on a wait queue.

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/kvm/Makefile  |2 
 arch/s390/kvm/intercept.c   |  123 +
 arch/s390/kvm/interrupt.c   |  583 
 arch/s390/kvm/kvm-s390.c|   48 +++
 arch/s390/kvm/kvm-s390.h|   15 +
 include/asm-s390/kvm_host.h |   75 +
 include/linux/kvm.h |   17 +
 7 files changed, 860 insertions(+), 3 deletions(-)

Index: linux-host/arch/s390/kvm/Makefile
===
--- linux-host.orig/arch/s390/kvm/Makefile
+++ linux-host/arch/s390/kvm/Makefile
@@ -10,5 +10,5 @@ common-objs = $(addprefix ../../../virt/
 
 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
 
-kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o
 obj-$(CONFIG_KVM) += kvm.o
Index: linux-host/arch/s390/kvm/intercept.c
===
--- linux-host.orig/arch/s390/kvm/intercept.c
+++ linux-host/arch/s390/kvm/intercept.c
@@ -18,6 +18,91 @@
 #include asm/kvm_host.h
 
 #include kvm-s390.h
+#include gaccess.h
+
+static int handle_lctg(struct kvm_vcpu *vcpu)
+{
+   int reg1 = (vcpu-arch.sie_block-ipa  0x00f0)  4;
+   int reg3 = vcpu-arch.sie_block-ipa  0x000f;
+   int base2 = vcpu-arch.sie_block-ipb  28;
+   int disp2 = ((vcpu-arch.sie_block-ipb  0x0fff)  16) +
+   ((vcpu-arch.sie_block-ipb  0xff00)  4);
+   u64 useraddr;
+   int reg, rc;
+
+   vcpu-stat.instruction_lctg++;
+   if ((vcpu-arch.sie_block-ipb  0xff) != 0x2f)
+   return -ENOTSUPP;
+
+   useraddr = disp2;
+   if (base2)
+   useraddr += vcpu-arch.guest_gprs[base2];
+
+   reg = reg1;
+
+   VCPU_EVENT(vcpu, 5, lctg r1:%x, r3:%x,b2:%x,d2:%x, reg1, reg3, base2,
+  disp2);
+
+   do {
+   rc = get_guest_u64(vcpu, useraddr,
+   vcpu-arch.sie_block-gcr[reg]);
+   if (rc == -EFAULT) {
+   kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+   break;
+   }
+   useraddr += 8;
+   if (reg == reg3)
+   break;
+   reg = reg + 1;
+   if (reg  15)
+   reg = 0;
+   } while (1);
+   return 0;
+}
+
+static int handle_lctl(struct kvm_vcpu *vcpu)
+{
+   int reg1 = (vcpu-arch.sie_block-ipa  0x00f0)  4;
+   int reg3 = vcpu-arch.sie_block-ipa  0x000f;
+   int base2 = vcpu-arch.sie_block-ipb  28;
+   int disp2 = ((vcpu-arch.sie_block-ipb  0x0fff)  16);
+   u64 useraddr;
+   u32 val = 0;
+   int reg, rc;
+
+   vcpu-stat.instruction_lctl++;
+
+   useraddr = disp2;
+   if (base2)
+   useraddr += vcpu-arch.guest_gprs[base2];
+
+   reg = reg1;
+
+   VCPU_EVENT(vcpu, 5, lctl r1:%x, r3:%x,b2:%x,d2:%x, reg1, 

[kvm-devel] [RFC/PATCH 06/15 v2] kvm-s390: sie intercept handling

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]

This path introduces handling of sie intercepts in three flavors: Intercepts
are either handled completely in-kernel by kvm_handle_sie_intercept(),
or passed to userspace with corresponding data in struct kvm_run in case
kvm_handle_sie_intercept() returns -ENOTSUPP.
In case of partial execution in kernel with the need of userspace support,
kvm_handle_sie_intercept() may choose to set up struct kvm_run and return
-EREMOTE.

The trivial intercept reasons are handled in this patch:
handle_noop() just does nothing for intercepts that don't require our support
  at all
handle_stop() is called when a cpu enters stopped state, and it drops out to
  userland after updating our vcpu state
handle_validity() faults in the cpu lowcore if needed, or passes the request
  to userland

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/kvm/Makefile  |2 -
 arch/s390/kvm/intercept.c   |   83 
 arch/s390/kvm/kvm-s390.c|   46 +++-
 arch/s390/kvm/kvm-s390.h|6 +++
 include/asm-s390/kvm_host.h |4 ++
 include/linux/kvm.h |9 
 6 files changed, 148 insertions(+), 2 deletions(-)

Index: linux-host/arch/s390/kvm/Makefile
===
--- linux-host.orig/arch/s390/kvm/Makefile
+++ linux-host/arch/s390/kvm/Makefile
@@ -10,5 +10,5 @@ common-objs = $(addprefix ../../../virt/
 
 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
 
-kvm-objs := $(common-objs) kvm-s390.o sie64a.o
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o
 obj-$(CONFIG_KVM) += kvm.o
Index: linux-host/arch/s390/kvm/intercept.c
===
--- /dev/null
+++ linux-host/arch/s390/kvm/intercept.c
@@ -0,0 +1,83 @@
+/*
+ * intercept.c - in-kernel handling for sie intercepts
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Carsten Otte [EMAIL PROTECTED]
+ *   Christian Borntraeger [EMAIL PROTECTED]
+ */
+
+#include linux/kvm_host.h
+#include linux/errno.h
+#include linux/pagemap.h
+
+#include asm/kvm_host.h
+
+#include kvm-s390.h
+
+static int handle_noop(struct kvm_vcpu *vcpu)
+{
+   switch (vcpu-arch.sie_block-icptcode) {
+   case 0x10:
+   vcpu-stat.exit_external_request++;
+   break;
+   case 0x14:
+   vcpu-stat.exit_external_interrupt++;
+   break;
+   default:
+   break; /* nothing */
+   }
+   return 0;
+}
+
+static int handle_stop(struct kvm_vcpu *vcpu)
+{
+   vcpu-stat.exit_stop_request++;
+   VCPU_EVENT(vcpu, 3, %s, cpu stopped);
+   atomic_clear_mask(CPUSTAT_RUNNING, vcpu-arch.sie_block-cpuflags);
+   return -ENOTSUPP;
+}
+
+static int handle_validity(struct kvm_vcpu *vcpu)
+{
+   int viwhy = vcpu-arch.sie_block-ipb  16;
+   vcpu-stat.exit_validity++;
+   if (viwhy == 0x37) {
+   fault_in_pages_writeable((char __user *)
+   vcpu-kvm-arch.guest_origin +
+   vcpu-arch.sie_block-prefix, PAGE_SIZE);
+   return 0;
+   }
+   VCPU_EVENT(vcpu, 2, unhandled validity intercept code %d,
+   viwhy);
+   return -ENOTSUPP;
+}
+
+static const intercept_handler_t intercept_funcs[0x48  2] = {
+   [0x00  2] = handle_noop,
+   [0x10  2] = handle_noop,
+   [0x14  2] = handle_noop,
+   [0x20  2] = handle_validity,
+   [0x28  2] = handle_stop,
+};
+
+int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
+{
+   intercept_handler_t func;
+   u8 code = vcpu-arch.sie_block-icptcode;
+
+   if (code  3 || code  0x48)
+   return -ENOTSUPP;
+
+   func = intercept_funcs[code  2];
+
+   if (func)
+   return func(vcpu);
+
+   return -ENOTSUPP;
+}
+
Index: linux-host/arch/s390/kvm/kvm-s390.c
===
--- linux-host.orig/arch/s390/kvm/kvm-s390.c
+++ linux-host/arch/s390/kvm/kvm-s390.c
@@ -23,12 +23,17 @@
 #include asm/lowcore.h
 #include asm/pgtable.h
 
+#include kvm-s390.h
 #include gaccess.h
 
 #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
 
 struct kvm_stats_debugfs_item debugfs_entries[] = {
{ userspace_handled, VCPU_STAT(exit_userspace) },
+   { exit_validity, VCPU_STAT(exit_validity) },
+   { exit_stop_request, VCPU_STAT(exit_stop_request) },
+   { exit_external_request, VCPU_STAT(exit_external_request) },
+   { exit_external_interrupt, VCPU_STAT(exit_external_interrupt) },
{ NULL }

[kvm-devel] [RFC/PATCH 09/15 v2] kvm-s390: interprocessor communication via sigp

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]

This patch introduces in-kernel handling of _some_ sigp interprocessor
signals (similar to ipi).
kvm_s390_handle_sigp() decodes the sigp instruction and calls individual
handlers depending on the operation requested:
- sigp sense tries to retrieve information such as existence or running state
  of the remote cpu
- sigp emergency sends an external interrupt to the remove cpu
- sigp stop stops a remove cpu
- sigp stop store status stops a remote cpu, and stores its entire internal
  state to the cpus lowcore
- sigp set arch sets the architecture mode of the remote cpu. setting to
  ESAME (s390x 64bit) is accepted, setting to ESA/S390 (s390, 31 or 24 bit) is
  denied, all others are passed to userland
- sigp set prefix sets the prefix register of a remote cpu

For implementation of this, the stop intercept indication starts to get reused
on purpose: a set of action bits defines what to do once a cpu gets stopped:
ACTION_STOP_ON_STOP  really stops the cpu when a stop intercept is recognized
ACTION_STORE_ON_STOP stores the cpu status to lowcore when a stop intercept is
 recognized

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/kvm/Makefile  |2 
 arch/s390/kvm/intercept.c   |   22 +++
 arch/s390/kvm/kvm-s390.c|7 +
 arch/s390/kvm/kvm-s390.h|7 +
 arch/s390/kvm/sigp.c|  289 
 include/asm-s390/kvm_host.h |   12 +
 6 files changed, 336 insertions(+), 3 deletions(-)

Index: linux-host/arch/s390/kvm/Makefile
===
--- linux-host.orig/arch/s390/kvm/Makefile
+++ linux-host/arch/s390/kvm/Makefile
@@ -10,5 +10,5 @@ common-objs = $(addprefix ../../../virt/
 
 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
 
-kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o 
sigp.o
 obj-$(CONFIG_KVM) += kvm.o
Index: linux-host/arch/s390/kvm/intercept.c
===
--- linux-host.orig/arch/s390/kvm/intercept.c
+++ linux-host/arch/s390/kvm/intercept.c
@@ -100,6 +100,7 @@ static int handle_lctl(struct kvm_vcpu *
 }
 
 static intercept_handler_t instruction_handlers[256] = {
+   [0xae] = kvm_s390_handle_sigp,
[0xb2] = kvm_s390_handle_priv,
[0xb7] = handle_lctl,
[0xeb] = handle_lctg,
@@ -122,10 +123,27 @@ static int handle_noop(struct kvm_vcpu *
 
 static int handle_stop(struct kvm_vcpu *vcpu)
 {
+   int rc;
+
vcpu-stat.exit_stop_request++;
-   VCPU_EVENT(vcpu, 3, %s, cpu stopped);
atomic_clear_mask(CPUSTAT_RUNNING, vcpu-arch.sie_block-cpuflags);
-   return -ENOTSUPP;
+   spin_lock_bh(vcpu-arch.local_int.lock);
+   if (vcpu-arch.local_int.action_bits  ACTION_STORE_ON_STOP) {
+   vcpu-arch.local_int.action_bits = ~ACTION_STORE_ON_STOP;
+   rc = __kvm_s390_vcpu_store_status(vcpu,
+ KVM_S390_STORE_STATUS_NOADDR);
+   if (rc = 0)
+   rc = -ENOTSUPP;
+   }
+
+   if (vcpu-arch.local_int.action_bits  ACTION_STOP_ON_STOP) {
+   vcpu-arch.local_int.action_bits = ~ACTION_STOP_ON_STOP;
+   VCPU_EVENT(vcpu, 3, %s, cpu stopped);
+   rc = -ENOTSUPP;
+   } else
+   rc = 0;
+   spin_unlock_bh(vcpu-arch.local_int.lock);
+   return rc;
 }
 
 static int handle_validity(struct kvm_vcpu *vcpu)
Index: linux-host/arch/s390/kvm/kvm-s390.c
===
--- linux-host.orig/arch/s390/kvm/kvm-s390.c
+++ linux-host/arch/s390/kvm/kvm-s390.c
@@ -57,6 +57,12 @@ struct kvm_stats_debugfs_item debugfs_en
{ instruction_chsc, VCPU_STAT(instruction_chsc) },
{ instruction_stsi, VCPU_STAT(instruction_stsi) },
{ instruction_stfl, VCPU_STAT(instruction_stfl) },
+   { instruction_sigp_sense, VCPU_STAT(instruction_sigp_sense) },
+   { instruction_sigp_emergency, VCPU_STAT(instruction_sigp_emergency) },
+   { instruction_sigp_stop, VCPU_STAT(instruction_sigp_stop) },
+   { instruction_sigp_set_arch, VCPU_STAT(instruction_sigp_arch) },
+   { instruction_sigp_set_prefix, VCPU_STAT(instruction_sigp_prefix) },
+   { instruction_sigp_restart, VCPU_STAT(instruction_sigp_restart) },
{ NULL }
 };
 
@@ -290,6 +296,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(st
spin_lock_bh(kvm-arch.float_int.lock);
kvm-arch.float_int.local_int[id] = vcpu-arch.local_int;
init_waitqueue_head(vcpu-arch.local_int.wq);
+   vcpu-arch.local_int.cpuflags = vcpu-arch.sie_block-cpuflags;
spin_unlock_bh(kvm-arch.float_int.lock);
 
rc 

[kvm-devel] [RFC/PATCH 05/15 v2] kvm-s390: s390 arch backend for the kvm kernel module

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]
From: Heiko Carstens [EMAIL PROTECTED]

This patch contains the port of Qumranet's kvm kernel module to IBM zSeries
 (aka s390x, mainframe) architecture. It uses the mainframe's virtualization
instruction SIE to run virtual machines with up to 64 virtual CPUs each.
This port is only usable on 64bit host kernels, and can only run 64bit guest
kernels. However, running 31bit applications in guest userspace is possible.

The following source files are introduced by this patch
arch/s390/kvm/kvm-s390.csimilar to arch/x86/kvm/x86.c, this implements all
arch callbacks for kvm. __vcpu_run calls back into
sie64a to enter the guest machine context
arch/s390/kvm/sie64a.S  assembler function sie64a, which enters guest
context via SIE, and switches world before and 
afterthat
include/asm-s390/kvm_host.h contains all vital data structures needed to run
virtual machines on the mainframe
include/asm-s390/kvm.h  defines kvm_regs and friends for user access to
guest register content
arch/s390/kvm/gaccess.h functions similar to uaccess to access guest memory
arch/s390/kvm/kvm-s390.hheader file for kvm-s390 internals, extended by
later patches

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Heiko Carstens [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/Makefile  |2 
 arch/s390/kernel/vtime.c|1 
 arch/s390/kvm/Makefile  |   14 +
 arch/s390/kvm/gaccess.h |  280 +
 arch/s390/kvm/kvm-s390.c|  574 
 arch/s390/kvm/kvm-s390.h|   29 ++
 arch/s390/kvm/sie64a.S  |   47 +++
 include/asm-s390/Kbuild |1 
 include/asm-s390/kvm.h  |   44 +++
 include/asm-s390/kvm_host.h |  127 +
 include/asm-s390/kvm_para.h |   30 ++
 include/linux/kvm.h |   15 +
 12 files changed, 1163 insertions(+), 1 deletion(-)

Index: linux-host/arch/s390/Makefile
===
--- linux-host.orig/arch/s390/Makefile
+++ linux-host/arch/s390/Makefile
@@ -87,7 +87,7 @@ LDFLAGS_vmlinux := -e start
 head-y := arch/s390/kernel/head.o arch/s390/kernel/init_task.o
 
 core-y += arch/s390/mm/ arch/s390/kernel/ arch/s390/crypto/ \
-  arch/s390/appldata/ arch/s390/hypfs/
+  arch/s390/appldata/ arch/s390/hypfs/ arch/s390/kvm/
 libs-y += arch/s390/lib/
 drivers-y  += drivers/s390/
 drivers-$(CONFIG_MATHEMU) += arch/s390/math-emu/
Index: linux-host/arch/s390/kernel/vtime.c
===
--- linux-host.orig/arch/s390/kernel/vtime.c
+++ linux-host/arch/s390/kernel/vtime.c
@@ -110,6 +110,7 @@ void account_system_vtime(struct task_st
S390_lowcore.steal_clock -= cputime  12;
account_system_time(tsk, 0, cputime);
 }
+EXPORT_SYMBOL_GPL(account_system_vtime);
 
 static inline void set_vtimer(__u64 expires)
 {
Index: linux-host/arch/s390/kvm/Makefile
===
--- /dev/null
+++ linux-host/arch/s390/kvm/Makefile
@@ -0,0 +1,14 @@
+# Makefile for kernel virtual machines on s390
+#
+# Copyright IBM Corp. 2008
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License (version 2 only)
+# as published by the Free Software Foundation.
+
+common-objs = $(addprefix ../../../virt/kvm/, kvm_main.o)
+
+EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
+
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o
+obj-$(CONFIG_KVM) += kvm.o
Index: linux-host/arch/s390/kvm/gaccess.h
===
--- /dev/null
+++ linux-host/arch/s390/kvm/gaccess.h
@@ -0,0 +1,280 @@
+/*
+ * gaccess.h -  access guest memory
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Carsten Otte [EMAIL PROTECTED]
+ */
+
+#ifndef __KVM_S390_GACCESS_H
+#define __KVM_S390_GACCESS_H
+
+#include linux/compiler.h
+#include linux/kvm_host.h
+#include asm/uaccess.h
+
+static inline void __user *__guestaddr_to_user(struct kvm_vcpu *vcpu,
+  u64 guestaddr)
+{
+   u64 prefix  = vcpu-arch.sie_block-prefix;
+   u64 origin  = vcpu-kvm-arch.guest_origin;
+   u64 memsize = vcpu-kvm-arch.guest_memsize;
+
+   if (guestaddr  2 * PAGE_SIZE)
+   guestaddr += prefix;
+   else if ((guestaddr = prefix)  (guestaddr  

[kvm-devel] [RFC/PATCH 10/15 v2] kvm-s390: intercepts for diagnose instructions

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]

This patch introduces interpretation of some diagnose instruction intercepts.
Diagnose is our classic architected way of doing a hypercall. This patch
features the following diagnose codes:
- vm storage size, that tells the guest about its memory layout
- time slice end, which is used by the guest to indicate that it waits
  for a lock and thus cannot use up its time slice in a useful way
- ipl functions, which a guest can use to reset and reboot itself

In order to implement ipl functions, we also introduce an exit reason that
causes userspace to perform various resets on the virtual machine. All resets
are described in the principles of operation book, except KVM_S390_RESET_IPL
which causes a reboot of the machine.

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/kvm/Makefile  |2 -
 arch/s390/kvm/diag.c|   67 
 arch/s390/kvm/intercept.c   |1 
 arch/s390/kvm/kvm-s390.c|1 
 arch/s390/kvm/kvm-s390.h|2 +
 include/asm-s390/kvm_host.h |5 ++-
 include/linux/kvm.h |8 +
 7 files changed, 84 insertions(+), 2 deletions(-)

Index: linux-host/arch/s390/kvm/Makefile
===
--- linux-host.orig/arch/s390/kvm/Makefile
+++ linux-host/arch/s390/kvm/Makefile
@@ -10,5 +10,5 @@ common-objs = $(addprefix ../../../virt/
 
 EXTRA_CFLAGS += -Ivirt/kvm -Iarch/s390/kvm
 
-kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o 
sigp.o
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o 
sigp.o diag.o
 obj-$(CONFIG_KVM) += kvm.o
Index: linux-host/arch/s390/kvm/diag.c
===
--- /dev/null
+++ linux-host/arch/s390/kvm/diag.c
@@ -0,0 +1,67 @@
+/*
+ * diag.c - handling diagnose instructions
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Carsten Otte [EMAIL PROTECTED]
+ *   Christian Borntraeger [EMAIL PROTECTED]
+ */
+
+#include linux/kvm.h
+#include linux/kvm_host.h
+#include kvm-s390.h
+
+static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
+{
+   VCPU_EVENT(vcpu, 5, %s, diag time slice end);
+   vcpu-stat.diagnose_44++;
+   vcpu_put(vcpu);
+   schedule();
+   vcpu_load(vcpu);
+   return 0;
+}
+
+static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
+{
+   unsigned int reg = vcpu-arch.sie_block-ipa  0xf;
+   unsigned long subcode = vcpu-arch.guest_gprs[reg]  0x;
+
+   VCPU_EVENT(vcpu, 5, diag ipl functions, subcode %lx, subcode);
+   switch (subcode) {
+   case 3:
+   vcpu-run-s390_reset_flags = KVM_S390_RESET_CLEAR;
+   break;
+   case 4:
+   vcpu-run-s390_reset_flags = 0;
+   break;
+   default:
+   return -ENOTSUPP;
+   }
+
+   atomic_clear_mask(CPUSTAT_RUNNING, vcpu-arch.sie_block-cpuflags);
+   vcpu-run-s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
+   vcpu-run-s390_reset_flags |= KVM_S390_RESET_IPL;
+   vcpu-run-s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
+   vcpu-run-exit_reason = KVM_EXIT_S390_RESET;
+   VCPU_EVENT(vcpu, 3, requesting userspace resets %lx,
+ vcpu-run-s390_reset_flags);
+   return -EREMOTE;
+}
+
+int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
+{
+   int code = (vcpu-arch.sie_block-ipb  0xfff)  16;
+
+   switch (code) {
+   case 0x44:
+   return __diag_time_slice_end(vcpu);
+   case 0x308:
+   return __diag_ipl_functions(vcpu);
+   default:
+   return -ENOTSUPP;
+   }
+}
Index: linux-host/arch/s390/kvm/intercept.c
===
--- linux-host.orig/arch/s390/kvm/intercept.c
+++ linux-host/arch/s390/kvm/intercept.c
@@ -100,6 +100,7 @@ static int handle_lctl(struct kvm_vcpu *
 }
 
 static intercept_handler_t instruction_handlers[256] = {
+   [0x83] = kvm_s390_handle_diag,
[0xae] = kvm_s390_handle_sigp,
[0xb2] = kvm_s390_handle_priv,
[0xb7] = handle_lctl,
Index: linux-host/arch/s390/kvm/kvm-s390.c
===
--- linux-host.orig/arch/s390/kvm/kvm-s390.c
+++ linux-host/arch/s390/kvm/kvm-s390.c
@@ -63,6 +63,7 @@ struct kvm_stats_debugfs_item debugfs_en
{ instruction_sigp_set_arch, VCPU_STAT(instruction_sigp_arch) },
{ instruction_sigp_set_prefix, VCPU_STAT(instruction_sigp_prefix) },
{ instruction_sigp_restart, VCPU_STAT(instruction_sigp_restart) },
+   { 

[kvm-devel] [RFC/PATCH 13/15 v2] kvm-s390: update maintainers

2008-03-22 Thread Carsten Otte
From: Christian Borntraeger [EMAIL PROTECTED]

This patch adds an entry for kvm on s390 to the MAINTAINERS file :-). We intend
to push all patches regarding this via Avi's kvm.git.

Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 MAINTAINERS |   10 ++
 1 files changed, 10 insertions(+)

Index: linux-host/MAINTAINERS
===
--- linux-host.orig/MAINTAINERS
+++ linux-host/MAINTAINERS
@@ -2305,6 +2305,16 @@ L:   [EMAIL PROTECTED]
 W: kvm.sourceforge.net
 S: Supported
 
+KERNEL VIRTUAL MACHINE for s390 (KVM/s390)
+P: Carsten Otte
+M: [EMAIL PROTECTED]
+P: Christian Borntraeger
+M: [EMAIL PROTECTED]
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://www.ibm.com/developerworks/linux/linux390/
+S: Supported
+
 KEXEC
 P: Eric Biederman
 M: [EMAIL PROTECTED]



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [RFC/PATCH 12/15 v2] kvm-s390: API documentation

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]

This patch adds Documentation/s390/kvm.txt, which describes specifics of kvm's
user interface that are unique to s390 architecture.

Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 Documentation/s390/kvm.txt |  125 +
 1 files changed, 125 insertions(+)

Index: linux-host/Documentation/s390/kvm.txt
===
--- /dev/null
+++ linux-host/Documentation/s390/kvm.txt
@@ -0,0 +1,125 @@
+*** BIG FAT WARNING ***
+The kvm module is currently in EXPERIMENTAL state for s390. This means that
+the interface to the module is not yet considered to remain stable. Thus, be
+prepared that we keep breaking your userspace application and guest
+compatibility over and over again until we feel happy with the result. Make 
sure
+your guest kernel, your host kernel, and your userspace launcher are in a
+consistent state.
+
+This Documentation describes the unique ioctl calls to /dev/kvm, the resulting
+kvm-vm file descriptors, and the kvm-vcpu file descriptors that differ from 
x86.
+
+1. ioctl calls to /dev/kvm
+KVM does support the following ioctls on s390 that are common with other
+architectures and do behave the same:
+KVM_GET_API_VERSION
+KVM_CREATE_VM  (*) see note
+KVM_CHECK_EXTENSION
+KVM_GET_VCPU_MMAP_SIZE
+
+Notes:
+* KVM_CREATE_VM may fail on s390, if the calling process has multiple
+threads and has not called KVM_S390_ENABLE_SIE before.
+
+In addition, on s390 the following architecture specific ioctls are supported:
+ioctl: KVM_S390_ENABLE_SIE
+args:  none
+see also:  include/linux/kvm.h
+This call causes the kernel to switch on PGSTE in the user page table. This
+operation is needed in order to run a virtual machine, and it requires the
+calling process to be single-threaded. Note that the first call to 
KVM_CREATE_VM
+will implicitly try to switch on PGSTE if the user process has not called
+KVM_S390_ENABLE_SIE before. User processes that want to launch multiple threads
+before creating a virtual machine have to call KVM_S390_ENABLE_SIE, or will
+observe an error calling KVM_CREATE_VM. Switching on PGSTE is a one-time
+operation, is not reversible, and will persist over the entire lifetime of
+the calling process. It does not have any user-visible effect other than a 
small
+performance penalty.
+
+2. ioctl calls to the kvm-vm file descriptor
+KVM does support the following ioctls on s390 that are common with other
+architectures and do behave the same:
+KVM_CREATE_VCPU
+KVM_SET_USER_MEMORY_REGION  (*) see note
+KVM_GET_DIRTY_LOG  (**) see note
+
+Notes:
+*  kvm does only allow exactly one memory slot on s390, which has to start
+   at guest absolute address zero and at a user address that is aligned on any
+   page boundary. This hardware limitation allows us to have a few unique
+   optimizations. The memory slot doesn't have to be filled
+   with memory actually, it may contain sparse holes. That said, with different
+   user memory layout this does still allow a large flexibility when
+   doing the guest memory setup.
+** KVM_GET_DIRTY_LOG doesn't work properly yet. The user will receive an empty
+log. This ioctl call is only needed for guest migration, and we intend to
+implement this one in the future.
+
+In addition, on s390 the following architecture specific ioctls for the kvm-vm
+file descriptor are supported:
+ioctl: KVM_S390_INTERRUPT
+args:  struct kvm_s390_interrupt *
+see also:  include/linux/kvm.h
+This ioctl is used to submit a floating interrupt for a virtual machine.
+Floating interrupts may be delivered to any virtual cpu in the configuration.
+Only some interrupt types defined in include/linux/kvm.h make sense when
+submitted as floating interrupts. The following interrupts are not considered
+to be useful as floating interrupts, and a call to inject them will result in
+-EINVAL error code: program interrupts and interprocessor signals. Valid
+floating interrupts are:
+KVM_S390_INT_VIRTIO
+KVM_S390_INT_SERVICE
+
+3. ioctl calls to the kvm-vcpu file descriptor
+KVM does support the following ioctls on s390 that are common with other
+architectures and do behave the same:
+KVM_RUN
+KVM_GET_REGS
+KVM_SET_REGS
+KVM_GET_SREGS
+KVM_SET_SREGS
+KVM_GET_FPU
+KVM_SET_FPU
+
+In addition, on s390 the following architecture specific ioctls for the
+kvm-vcpu file descriptor are supported:
+ioctl: KVM_S390_INTERRUPT
+args:  struct kvm_s390_interrupt *
+see also:  include/linux/kvm.h
+This ioctl is used to submit an interrupt for a specific virtual cpu.
+Only some interrupt types defined in include/linux/kvm.h make sense when
+submitted for a specific cpu. The following interrupts are not considered
+to be useful, and a call to inject them will result in -EINVAL error code:
+service processor calls and virtio interrupts. Valid interrupt types are:
+KVM_S390_PROGRAM_INT

[kvm-devel] [RFC/PATCH 11/15 v2] kvm-s390: add kvm to kconfig on s390

2008-03-22 Thread Carsten Otte
From: Carsten Otte [EMAIL PROTECTED]
From: Christian Borntraeger [EMAIL PROTECTED]

This patch adds the virtualization submenu and the kvm option to the kernel
config. It also defines HAVE_KVM for 64bit kernels.

Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/Kconfig |3 +++
 arch/s390/kvm/Kconfig |   43 +++
 2 files changed, 46 insertions(+)

Index: kvm/arch/s390/Kconfig
===
--- kvm.orig/arch/s390/Kconfig
+++ kvm/arch/s390/Kconfig
@@ -66,6 +66,7 @@ config S390
select HAVE_OPROFILE
select HAVE_KPROBES
select HAVE_KRETPROBES
+   select HAVE_KVM if 64BIT
 
 source init/Kconfig
 
@@ -553,3 +554,5 @@ source security/Kconfig
 source crypto/Kconfig
 
 source lib/Kconfig
+
+source arch/s390/kvm/Kconfig
Index: kvm/arch/s390/kvm/Kconfig
===
--- /dev/null
+++ kvm/arch/s390/kvm/Kconfig
@@ -0,0 +1,43 @@
+#
+# KVM configuration
+#
+config HAVE_KVM
+   bool
+
+menuconfig VIRTUALIZATION
+   bool Virtualization
+   default y
+   ---help---
+ Say Y here to get to see options for using your Linux host to run 
other
+ operating systems inside virtual machines (guests).
+ This option alone does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and 
disabled.
+
+if VIRTUALIZATION
+
+config KVM
+   tristate Kernel-based Virtual Machine (KVM) support
+   depends on HAVE_KVM  EXPERIMENTAL
+   select PREEMPT_NOTIFIERS
+   select ANON_INODES
+   select S390_SWITCH_AMODE
+   select PREEMPT
+   ---help---
+ Support hosting paravirtualized guest machines using the SIE
+ virtualization capability on the mainframe. This should work
+ on any 64bit machine.
+
+ This module provides access to the hardware capabilities through
+ a character device node named /dev/kvm.
+
+ To compile this as a module, choose M here: the module
+ will be called kvm.
+
+ If unsure, say N.
+
+# OK, it's a little counter-intuitive to do this, but it puts it neatly under
+# the virtualization menu.
+source drivers/virtio/Kconfig
+
+endif # VIRTUALIZATION



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [RFC/PATCH 14/15 v2] guest: detect when running on kvm

2008-03-22 Thread Carsten Otte
From: Christian Borntraeger [EMAIL PROTECTED]
From: Carsten Otte [EMAIL PROTECTED]

This patch adds functionality to detect if the kernel runs under the KVM
hypervisor. A macro MACHINE_IS_KVM is exported for device drivers. This
allows drivers to skip device detection if the systems runs non-virtualized.
We also define a preferred console to avoid having the ttyS0, which is a line
mode only console.

Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 arch/s390/Kconfig|7 +++
 arch/s390/kernel/early.c |4 
 arch/s390/kernel/setup.c |   10 +++---
 include/asm-s390/setup.h |1 +
 4 files changed, 19 insertions(+), 3 deletions(-)

Index: kvm/arch/s390/Kconfig
===
--- kvm.orig/arch/s390/Kconfig
+++ kvm/arch/s390/Kconfig
@@ -533,6 +533,13 @@ config ZFCPDUMP
  Select this option if you want to build an zfcpdump enabled kernel.
  Refer to file:Documentation/s390/zfcpdump.txt for more details on 
this.
 
+config S390_GUEST
+bool s390 guest support (EXPERIMENTAL)
+   depends on 64BIT  EXPERIMENTAL
+   select VIRTIO
+   select VIRTIO_RING
+   help
+ Select this option if you want to run the kernel under s390 linux
 endmenu
 
 source net/Kconfig
Index: kvm/arch/s390/kernel/early.c
===
--- kvm.orig/arch/s390/kernel/early.c
+++ kvm/arch/s390/kernel/early.c
@@ -143,6 +143,10 @@ static noinline __init void detect_machi
/* Running on a P/390 ? */
if (cpuinfo-cpu_id.machine == 0x7490)
machine_flags |= 4;
+
+   /* Running under KVM ? */
+   if (cpuinfo-cpu_id.version == 0xfe)
+   machine_flags |= 64;
 }
 
 #ifdef CONFIG_64BIT
Index: kvm/arch/s390/kernel/setup.c
===
--- kvm.orig/arch/s390/kernel/setup.c
+++ kvm/arch/s390/kernel/setup.c
@@ -793,9 +793,13 @@ setup_arch(char **cmdline_p)
   This machine has an IEEE fpu\n :
   This machine has no IEEE fpu\n);
 #else /* CONFIG_64BIT */
-   printk((MACHINE_IS_VM) ?
-  We are running under VM (64 bit mode)\n :
-  We are running native (64 bit mode)\n);
+   if (MACHINE_IS_VM)
+   printk(We are running under VM (64 bit mode)\n);
+   else if (MACHINE_IS_KVM) {
+   printk(We are running under KVM (64 bit mode)\n);
+   add_preferred_console(ttyS, 1, NULL);
+   } else
+   printk(We are running native (64 bit mode)\n);
 #endif /* CONFIG_64BIT */
 
/* Save unparsed command line copy for /proc/cmdline */
Index: kvm/include/asm-s390/setup.h
===
--- kvm.orig/include/asm-s390/setup.h
+++ kvm/include/asm-s390/setup.h
@@ -62,6 +62,7 @@ extern unsigned long machine_flags;
 #define MACHINE_IS_VM  (machine_flags  1)
 #define MACHINE_IS_P390(machine_flags  4)
 #define MACHINE_HAS_MVPG   (machine_flags  16)
+#define MACHINE_IS_KVM (machine_flags  64)
 #define MACHINE_HAS_IDTE   (machine_flags  128)
 #define MACHINE_HAS_DIAG9C (machine_flags  256)
 



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [RFC/PATCH 15/15 v2] guest: virtio device support, and kvm hypercalls

2008-03-22 Thread Carsten Otte
From: Christian Borntraeger [EMAIL PROTECTED]

This patch implements kvm guest kernel support for paravirtualized devices
and contains two parts:
o a basic virtio stub using virtio_ring and external interrupts and hypercalls
o full hypercall implementation in kvm_para.h

Currently we dont have PCI on s390. Making virtio_pci usable for s390 seems
more complicated that providing an own stub. This virtio stub is similar to
the lguest one, the memory for the descriptors and the device detection is made
via additional mapped memory on top of the guest storage. We use an external
interrupt with extint code 1237 for host-guest notification. 

The hypercall definition uses the diag instruction for issuing a hypercall. The
parameters are written in R2-R7, the hypercall number is written in R1. This is
similar to the system call ABI (svc) which can use R1 for the number and R2-R6 
for the parameters.


Signed-off-by: Christian Borntraeger [EMAIL PROTECTED]
Acked-by: Martin Schwidefsky [EMAIL PROTECTED]
Signed-off-by: Carsten Otte [EMAIL PROTECTED]
---
 drivers/s390/Makefile |2 
 drivers/s390/kvm/Makefile |9 +
 drivers/s390/kvm/kvm_virtio.c |  326 ++
 drivers/s390/kvm/kvm_virtio.h |   47 ++
 include/asm-s390/kvm_para.h   |  124 +++
 5 files changed, 505 insertions(+), 3 deletions(-)

Index: kvm/drivers/s390/Makefile
===
--- kvm.orig/drivers/s390/Makefile
+++ kvm/drivers/s390/Makefile
@@ -5,7 +5,7 @@
 CFLAGS_sysinfo.o += -Iinclude/math-emu -Iarch/s390/math-emu -w
 
 obj-y += s390mach.o sysinfo.o s390_rdev.o
-obj-y += cio/ block/ char/ crypto/ net/ scsi/
+obj-y += cio/ block/ char/ crypto/ net/ scsi/ kvm/
 
 drivers-y += drivers/s390/built-in.o
 
Index: kvm/drivers/s390/kvm/Makefile
===
--- /dev/null
+++ kvm/drivers/s390/kvm/Makefile
@@ -0,0 +1,9 @@
+# Makefile for kvm guest drivers on s390
+#
+# Copyright IBM Corp. 2008
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License (version 2 only)
+# as published by the Free Software Foundation.
+
+obj-$(CONFIG_VIRTIO) += kvm_virtio.o
Index: kvm/drivers/s390/kvm/kvm_virtio.c
===
--- /dev/null
+++ kvm/drivers/s390/kvm/kvm_virtio.c
@@ -0,0 +1,326 @@
+/*
+ * kvm_virtio.c - virtio for kvm on s390
+ *
+ * Copyright IBM Corp. 2008
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ *Author(s): Christian Borntraeger [EMAIL PROTECTED]
+ */
+
+#include linux/init.h
+#include linux/bootmem.h
+#include linux/err.h
+#include linux/virtio.h
+#include linux/virtio_config.h
+#include linux/interrupt.h
+#include linux/virtio_ring.h
+#include asm/io.h
+#include asm/kvm_para.h
+#include asm/setup.h
+#include asm/s390_ext.h
+
+#include kvm_virtio.h
+
+/*
+ * The pointer to our (page) of device descriptions.
+ */
+static void *kvm_devices;
+
+/*
+ * Unique numbering for kvm devices.
+ */
+static unsigned int dev_index;
+
+struct kvm_device {
+   struct virtio_device vdev;
+   struct kvm_device_desc *desc;
+};
+
+#define to_kvmdev(vd) container_of(vd, struct kvm_device, vdev)
+
+/*
+ * memory layout:
+ * - kvm_device_descriptor
+ *struct kvm_device_desc
+ * - configuration
+ *struct kvm_vqconfig
+ * - feature bits
+ * - config space
+ */
+static struct kvm_vqconfig *kvm_vq_config(const struct kvm_device_desc *desc)
+{
+   return (struct kvm_vqconfig *)(desc + 1);
+}
+
+static u8 *kvm_vq_features(const struct kvm_device_desc *desc)
+{
+   return (u8 *)(kvm_vq_config(desc) + desc-num_vq);
+}
+
+static u8 *kvm_vq_configspace(const struct kvm_device_desc *desc)
+{
+   return kvm_vq_features(desc) + desc-feature_len * 2;
+}
+
+/*
+ * The total size of the config page used by this device (incl. desc)
+ */
+static unsigned desc_size(const struct kvm_device_desc *desc)
+{
+   return sizeof(*desc)
+   + desc-num_vq * sizeof(struct kvm_vqconfig)
+   + desc-feature_len * 2
+   + desc-config_len;
+}
+
+/*
+ * This tests (and acknowleges) a feature bit.
+ */
+static bool kvm_feature(struct virtio_device *vdev, unsigned fbit)
+{
+   struct kvm_device_desc *desc = to_kvmdev(vdev)-desc;
+   u8 *features;
+
+   if (fbit / 8  desc-feature_len)
+   return false;
+
+   features = kvm_vq_features(desc);
+   if (!(features[fbit / 8]  (1  (fbit % 8
+   return false;
+
+   /*
+* We set the matching bit in the other half of the bitmap to tell the
+* Host we want to use this feature.
+*/
+   features[desc-feature_len + fbit / 8] |= (1  (fbit % 8));
+   return true;
+}
+

[kvm-devel] [RFC/PATCH 00/15 v2] kvm on big iron

2008-03-22 Thread Carsten Otte
This patch series introduces a backend for kvm to run on IBM System z
machines (aka s390x) that uses the mainframe's sie virtualization
capability. Many thanks for the review feedback we have received so far,
I do greatly appreciate it!

The first submission didn't draw much attention of elder vm magicians on
linux-mm. I am adding Nick, Hugh and Andrew explicitly to the first two
patches. Please do comment on our common code change buried in there. Is
this acceptable for you? Who else does need to review them?

Changes from the Version 1:
- include Feedback from Randy Dunlap on the Documentation
- include Feedback from Jeremy Fitzhardinge, the prototype for dup_mm
  has moved to include/linux/sched.h
- rebase to current kvm.git hash g361be34. Thank you Avi for pulling
  in the fix we need, and for moving KVM_MAX_VCPUS to include/arch :-).

Todo list:
- I've created a patch for Christoph Helwig's feedback about symbolic
names for machine_flags. This change is independent of the kvm port, and
I will submit it for review to Martin.
- Rusty Russell has provided feedback that improves patch #15. Christian
is looking into that and will likely update that patch. If this goes in
before, we can safely do an add-on patch on top of #15.
- an open comment from Dave Hansen about a possible race enable_sie
versus ptrace in patch #1 exceeds my basic vm knowledge and needs to be
answered by Martin or Heiko

The patch queue consists of the following patches:
[RFC/PATCH 01/15] preparation: provide hook to enable pgstes in user 
   pagetable
[RFC/PATCH 02/15] preparation: host memory management changes for s390 
   kvm
[RFC/PATCH 03/15] preparation: address of the 64bit extint parm in 
   lowcore
[RFC/PATCH 04/15] preparation: split sysinfo defintions for kvm use
[RFC/PATCH 05/15] kvm-s390: s390 arch backend for the kvm kernel module
[RFC/PATCH 06/15] kvm-s390: sie intercept handling
[RFC/PATCH 07/15] kvm-s390: interrupt subsystem, cpu timer, waitpsw
[RFC/PATCH 08/15] kvm-s390: intercepts for privileged instructions
[RFC/PATCH 09/15] kvm-s390: interprocessor communication via sigp
[RFC/PATCH 10/15] kvm-s390: intercepts for diagnose instructions
[RFC/PATCH 11/15] kvm-s390: add kvm to kconfig on s390
[RFC/PATCH 12/15] kvm-s390: API documentation
[RFC/PATCH 13/15] kvm-s390: update maintainers
[RFC/PATCH 14/15] guest: detect when running on kvm
[RFC/PATCH 15/15] guest: virtio device support, and kvm hypercalls


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [RFC/PATCH 14/15] guest: detect when running on kvm

2008-03-22 Thread Heiko Carstens
On Fri, Mar 21, 2008 at 03:33:29PM +0100, Carsten Otte wrote:
 Am Freitag, den 21.03.2008, 15:06 +0100 schrieb Heiko Carstens:
  Just introduce something like MACHINE_FLAG_KVM. The rest can be converted
  later. Unless you're bored and feel like fiddling around with assembly code 
  :)
 I've done that patch this morning already, see below. I agree with HCH
 that we should do that, but after the kvm merge. I don't want kvm-s390
 conflict with Martin's patches. This is just a beautification, and can
 safely wait a release cycle.

That's nice for a start. But you didn't convert the assembly files to use
the new defines. So there is still no connection between setting a bit
in asm code and the new defines.
That's the reason why I said something about fiddling around with asm code.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [RFC/PATCH 01/15] preparation: provide hook to enable pgstes in user pagetable

2008-03-22 Thread Heiko Carstens
 What you've done with dup_mm() is probably the brute-force way that I
 would have done it had I just been trying to make a proof of concept or
 something.  I'm worried that there are a bunch of corner cases that
 haven't been considered.
 
 What if someone else is poking around with ptrace or something similar
 and they bump the mm_users:
 
 +   if (tsk-mm-context.pgstes)
 +   return 0;
 +   if (!tsk-mm || atomic_read(tsk-mm-mm_users)  1 ||
 +   tsk-mm != tsk-active_mm || tsk-mm-ioctx_list)
 +   return -EINVAL;
 HERE
 +   tsk-mm-context.pgstes = 1;/* dirty little tricks .. */
 +   mm = dup_mm(tsk);
 
 It'll race, possibly fault in some other pages, and those faults will be
 lost during the dup_mm().  I think you need to be able to lock out all
 of the users of access_process_vm() before you go and do this.  You also
 need to make sure that anyone who has looked at task-mm doesn't go and
 get a reference to it and get confused later when it isn't the task-mm
 any more.
 
  Therefore, we need to reallocate the page table after fork() 
  once we know that task is going to be a hypervisor. That's what this 
  code does: reallocate a bigger page table to accomondate the extra 
  information. The task needs to be single-threaded when calling for 
  extended page tables.
  
  Btw: at fork() time, we cannot tell whether or not the user's going to 
  be a hypervisor. Therefore we cannot do this in fork.
 
 Can you convert the page tables at a later time without doing a
 wholesale replacement of the mm?  It should be a bit easier to keep
 people off the pagetables than keep their grubby mitts off the mm
 itself.

Yes, as far as I can see you're right. And whatever we do in arch code,
after all it's just a work around to avoid a new clone flag.
If something like clone() with CLONE_KVM would be useful for more
architectures than just s390 then maybe we should try to get a flag.

Oh... there are just two unused clone flag bits left. Looks like the
namespace changes ate up a lot of them lately.

Well, we could still play dirty tricks like setting a bit in current
via whatever mechanism which indicates child-wants-extended-page-tables
and then just fork and be happy.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] You can be the Alpha Male

2008-03-22 Thread jorn doyal
Achieve incredible, unbelievably climaxes for her and you like never before.

http://www.Hanoestly.com/
Get paid starring in our porno film

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] question: HPET for multiple VMs

2008-03-22 Thread Avi Kivity
Ryota OZAKI wrote:
 Hi all,

 Current kvm allows only one VM to use HPET. Is
 there a plan to implement a functionality to
 allow multiple VMs to use HPET? If so, how
 about the status of that?

   

If you use the dyntick clock option (the default, IIRC), and a newer 
host kernel, then the kernel provides high-resolution timers, very 
likely using HPET internally or some other high resolution clock and 
event source.

 And I would like to ask right and wrong to
 implement the functionality in terms of need
 and efficiency (scalability and time accuracy).

I think that for newer kernels we already have the desired accuracy.  
We're not always good at exploiting that accuracy; hence the recent 
movement of the PIT implementation from userspace to the kernel.  But 
recent discussion leads me to believe it could have been implemented 
with the userspace PIT as well.

-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] Virtio block device and LVM

2008-03-22 Thread Dennis Jacobfeuerborn
Hi,
I'm trying to get the paravirtualized block device going but get in trouble 
with LVM. Both host and guest a very recent snapshot of Fedora 9 rawhide. 
The guest is a pristine F9 install with / mounted as /dev/VolGroup00/LogVol00.

When I boot with the command:
/usr/bin/qemu-kvm -m 512 -drive file=/root/test-1.img,media=disk,boot=on
the guest boots fine but when I try to boot with:
/usr/bin/qemu-kvm -m 512 -drive file=/root/test-1.img,if=virtio,boot=on
the kernel panics because it cannot find any volume-groups and thus not 
mount /.

Do I have to make any specific changes to the guest to make it 
recognize/detect the volume-group on the virtual block device?

Regards,
   Dennis

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] Virtio block device and LVM

2008-03-22 Thread Anthony Liguori
Dennis Jacobfeuerborn wrote:
 Hi,
 I'm trying to get the paravirtualized block device going but get in trouble 
 with LVM. Both host and guest a very recent snapshot of Fedora 9 rawhide. 
 The guest is a pristine F9 install with / mounted as /dev/VolGroup00/LogVol00.

 When I boot with the command:
 /usr/bin/qemu-kvm -m 512 -drive file=/root/test-1.img,media=disk,boot=on
 the guest boots fine but when I try to boot with:
 /usr/bin/qemu-kvm -m 512 -drive file=/root/test-1.img,if=virtio,boot=on
 the kernel panics because it cannot find any volume-groups and thus not 
 mount /.

 Do I have to make any specific changes to the guest to make it 
 recognize/detect the volume-group on the virtual block device?
   

You need to make sure virtio_blk and virtio_pci are included in your initrd.

Regards,

Anthony Liguori

 Regards,
Dennis

 -
 This SF.net email is sponsored by: Microsoft
 Defy all challenges. Microsoft(R) Visual Studio 2008.
 http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
 ___
 kvm-devel mailing list
 kvm-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/kvm-devel
   


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] question: HPET for multiple VMs

2008-03-22 Thread Anthony Liguori
Avi Kivity wrote:
 And I would like to ask right and wrong to
 implement the functionality in terms of need
 and efficiency (scalability and time accuracy).
 

 I think that for newer kernels we already have the desired accuracy.  
 We're not always good at exploiting that accuracy; hence the recent 
 movement of the PIT implementation from userspace to the kernel.  But 
 recent discussion leads me to believe it could have been implemented 
 with the userspace PIT as well.
   

What do you think is needed to get the same accuracy in userspace as in 
kernelspace?  Better yet, do you think there is a reasonable kvmctl 
harness we could write to quantify the PIT accuracy?

It's easy enough to count timer interrupts and use compare that to an 
external time source to get some notion of accuracy (on varying 
frequencies of course).  I know you mentioned before that guest CPU 
consumption also comes into play... I'm not quite sure why though so I'm 
not sure how to simulate that.

The nice thing about the CAP infrastructure is we can always move the 
PIT back to userspace.  I'll happily invest some cycles here as I'm a 
big fan of getting rid of unneeded kernel code :-)

Regards,

Anthony Liguori


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel