Re: [kvm-devel] s390 kvm_virtio.c build error

2008-05-05 Thread Carsten Otte
[EMAIL PROTECTED] wrote:
> I've added Heiko's patch to my patchqueue. But since this is
> drivers/s390/kvm this should go in over the kvm.git. See patch below.
Acked-by: Carsten Otte <[EMAIL PROTECTED]>


-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH] Handle vma regions with no backing page (v2)

2008-04-30 Thread Carsten Otte
Avi Kivity wrote:
> Hollis/Xiantao/Carsten, can you confirm that this approach works for 
> you?  Carsten, I believe you don't have mmio, but at least this 
> shouldn't interfere.
Should work fine on s390 afaics.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 13/45] KVM: s390: API documentation

2008-04-17 Thread Carsten Otte
Randy Dunlap wrote:
> Please use "CPU" consistently throughout the file (i.e., not "cpu").
Thanks, will fix that with a patch that'll go on top.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 2/2] QEMU: decrease console "refresh rate" with -nographic

2008-04-16 Thread Carsten Otte
Anthony Liguori wrote:
> There is a 5th option.  Do away with the use of posix aio.  We get 
> absolutely no benefit from it because it's limited to a single thread.  
> Fabrice has reverted a patch to change that in the past.
How about using linux aio for it? It seems much better, because it 
doesn't use userspace threads but has a direct in-kernel 
implementation. I've had good performance on zldisk with that, and 
it's stable.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 1/2] kvm-s390: provide get/set_mp_state stubs to fix compile error

2008-04-16 Thread Carsten Otte
From: Christian Borntraeger <[EMAIL PROTECTED]>

Since 

commit ded6fb24fb694bcc5f308a02ec504d45fbc8aaa6
Author: Marcelo Tosatti <[EMAIL PROTECTED]>
Date:   Fri Apr 11 13:24:45 2008 -0300
KVM: add ioctls to save/store mpstate

kvm does not compile on s390. 
This patch provides ioctl stubs for s390 to make kvm.git compile again.
As migration is not yet supported, the ioctl definitions are empty.

Signed-off-by: Christian Borntraeger <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 arch/s390/kvm/kvm-s390.c |   12 
 1 file changed, 12 insertions(+)

Index: kvm/arch/s390/kvm/kvm-s390.c
===
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -414,6 +414,18 @@ int kvm_arch_vcpu_ioctl_debug_guest(stru
return -EINVAL; /* not implemented yet */
 }
 
+int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
+   struct kvm_mp_state *mp_state)
+{
+   return -EINVAL; /* not implemented yet */
+}
+
+int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
+   struct kvm_mp_state *mp_state)
+{
+   return -EINVAL; /* not implemented yet */
+}
+
 static void __vcpu_run(struct kvm_vcpu *vcpu)
 {
memcpy(&vcpu->arch.sie_block->gg14, &vcpu->arch.guest_gprs[14], 16);



-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 2/2] virtio-s390: Change virtio interrupt definitions to follow architecture

2008-04-16 Thread Carsten Otte
From: Christian Borntraeger <[EMAIL PROTECTED]>

This patch changes the interrupt defintions for virtio on s390. We now use
the extint number 0x2603, which is used as a host interrupt already by z/VM
for pfault and dasd_diag.
We will use subcode 0x0D to distinguish virtio from dasd and pfault.

Signed-off-by: Christian Borntraeger <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 arch/s390/kvm/interrupt.c |6 +-
 drivers/s390/kvm/kvm_virtio.c |8 +++-
 2 files changed, 12 insertions(+), 2 deletions(-)

Index: kvm/arch/s390/kvm/interrupt.c
===
--- kvm.orig/arch/s390/kvm/interrupt.c
+++ kvm/arch/s390/kvm/interrupt.c
@@ -162,7 +162,11 @@ static void __do_deliver_interrupt(struc
VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%lx",
   inti->ext.ext_params, inti->ext.ext_params2);
vcpu->stat.deliver_virtio_interrupt++;
-   rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1237);
+   rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x2603);
+   if (rc == -EFAULT)
+   exception = 1;
+
+   rc = put_guest_u16(vcpu, __LC_CPU_ADDRESS, 0x0d00);
if (rc == -EFAULT)
exception = 1;
 
Index: kvm/drivers/s390/kvm/kvm_virtio.c
===
--- kvm.orig/drivers/s390/kvm/kvm_virtio.c
+++ kvm/drivers/s390/kvm/kvm_virtio.c
@@ -23,6 +23,8 @@
 #include 
 #include 
 
+#define VIRTIO_SUBCODE_64 0x0D00
+
 /*
  * The pointer to our (page) of device descriptions.
  */
@@ -291,6 +293,10 @@ static void scan_devices(void)
 static void kvm_extint_handler(u16 code)
 {
void *data = (void *) *(long *) __LC_PFAULT_INTPARM;
+   u16 subcode = S390_lowcore.cpu_addr;
+
+   if ((subcode & 0xff00) != VIRTIO_SUBCODE_64)
+   return;
 
vring_interrupt(0, data);
 }
@@ -319,8 +325,8 @@ static int __init kvm_devices_init(void)
 
kvm_devices  = (void *) (max_pfn << PAGE_SHIFT);
 
-   register_external_interrupt(0x1237, kvm_extint_handler);
ctl_set_bit(0, 9);
+   register_external_interrupt(0x2603, kvm_extint_handler);
 
scan_devices();
return 0;



-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 0/2] kvm-s390 fixes

2008-04-16 Thread Carsten Otte
Hi Avi,

these two fixes repair two things in kvm-s390:
- #1 makes kvm complile again on s390 after a common code change
- #2 changes our virtio interrupt definitions to the values that will
  be reserved for kvm use in s390 architecture

I'd be great if both could make 2.6.26.

so long,
Carsten


-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 2/2] QEMU: decrease console "refresh rate" with -nographic

2008-04-14 Thread Carsten Otte
Avi Kivity wrote:
> Anthony Liguori wrote:
>> BTW, when we set O_ASYNC on the tap fd, we're eliminating O_NONBLOCK.  
>> This means that we have to poll loop select() when readv()'ing packets 
>> instead of just reading until hitting AGAIN.  This means at least an 
>> extra syscall per packet.
> 
> I didn't know that O_ASYNC and O_NONBLOCK were mutually exclusive.  Can 
> you point me at the relevant documentation?
They should'nt be mutual exclusive. If they are, the tap driver 
requires fixing afaics. The relevant documentation is the man page 
open(2), and it doesn't state they are exclusive.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 1/2] KVM: hlt emulation should take in-kernel APIC/PIT timers into account

2008-04-14 Thread Carsten Otte
Avi Kivity wrote:
> Why?
This one does'nt work for us. Our arch defines various reasons why we 
would not fall asleep but do something else, and we need to check them 
while in atomic of a lock that other archs don't have before sleeping.
See kvm_s390_handle_wait in arch/s390/kvm/interrupt.c.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [patch 1/2] KVM: hlt emulation should take in-kernel APIC/PIT timers into account

2008-04-11 Thread Carsten Otte
Avi Kivity wrote:
>> @@ -765,6 +766,7 @@ void kvm_vcpu_block(struct kvm_vcpu *vcp
>>   
> 
> 
> This breaks ia64 (and shouldn't s390 use this too?)
>>   * We will block until either an interrupt or a signal wakes us up
>>   */
>>  while (!kvm_cpu_has_interrupt(vcpu)
>> +   && !kvm_cpu_has_pending_timer(vcpu)
>>   
> 
> I guess the fix is to stub this out for the other archs.

We don't use that, we have our own implementation of vcpu_block.

-
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 03/04 v2] kvm-s390: Improve pgste accesses

2008-04-04 Thread Carsten Otte
From: Heiko Carstens <[EMAIL PROTECTED]>

There is no need to use interlocked updates when the rcp
lock is held. Therefore the simple bitops variants can be
used. This should improve performance.

Signed-off-by: Heiko Carstens <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 include/asm-s390/pgtable.h |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

Index: kvm/include/asm-s390/pgtable.h
===
--- kvm.orig/include/asm-s390/pgtable.h
+++ kvm/include/asm-s390/pgtable.h
@@ -553,12 +553,12 @@ static inline void ptep_rcp_copy(pte_t *
 
skey = page_get_storage_key(page_to_phys(page));
if (skey & _PAGE_CHANGED)
-   set_bit(RCP_GC_BIT, pgste);
+   set_bit_simple(RCP_GC_BIT, pgste);
if (skey & _PAGE_REFERENCED)
-   set_bit(RCP_GR_BIT, pgste);
-   if (test_and_clear_bit(RCP_HC_BIT, pgste))
+   set_bit_simple(RCP_GR_BIT, pgste);
+   if (test_and_clear_bit_simple(RCP_HC_BIT, pgste))
SetPageDirty(page);
-   if (test_and_clear_bit(RCP_HR_BIT, pgste))
+   if (test_and_clear_bit_simple(RCP_HR_BIT, pgste))
SetPageReferenced(page);
 #endif
 }
@@ -732,8 +732,8 @@ static inline int ptep_test_and_clear_yo
young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
rcp_lock(ptep);
if (young)
-   set_bit(RCP_GR_BIT, pgste);
-   young |= test_and_clear_bit(RCP_HR_BIT, pgste);
+   set_bit_simple(RCP_GR_BIT, pgste);
+   young |= test_and_clear_bit_simple(RCP_HR_BIT, pgste);
rcp_unlock(ptep);
return young;
 #endif



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [PATCH 03/04] kvm-s390: Improve pgste accesses

2008-04-04 Thread Carsten Otte
[EMAIL PROTECTED] wrote:
> Major formatting accident ?
Ops! How did that happen? Thanks, will resend that patch.

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 00/04] kvm-s390 updates

2008-04-04 Thread Carsten Otte
Hi Avi,

looks like Heiko played around with kvm a bit :-):
01/04: cosmetics, including part of Arnd's review feedback
02/04: bugfix, if KVM_VCPU_IOCTL_RUN got interrupted by signal
03/04: performance improvement with our pgste memory handling
04/04: resolve merge conflict in linux-next kvm.git versus git-s390
   that was reported by Stephen Rothwell today (thanks, Stephen!)

I think it's save to queue all for 2.6.26, #2 and #4 seem crucial to me.

thanks,
Carsten


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 03/04] kvm-s390: Improve pgste accesses

2008-04-04 Thread Carsten Otte
From: Heiko Carstens <[EMAIL PROTECTED]>

There is no need to use interlocked updates when the rcp
lock is held. Therefore the simple bitops variants can be
used. This should improve performance.

Signed-off-by: Heiko Carstens <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
include/asm-s390/pgtable.h |   12 ++--
1 file changed, 6 insertions(+), 6 deletions(-)

Index: kvm/include/asm-s390/pgtable.h
===
--- kvm.orig/include/asm-s390/pgtable.h
+++ kvm/include/asm-s390/pgtable.h
@@ -553,12 +553,12 @@ static inline void ptep_rcp_copy(pte_t *

skey = page_get_storage_key(page_to_phys(page));
if (skey & _PAGE_CHANGED)
- set_bit(RCP_GC_BIT, pgste);
+ set_bit_simple(RCP_GC_BIT, pgste);
if (skey & _PAGE_REFERENCED)
- set_bit(RCP_GR_BIT, pgste);
- if (test_and_clear_bit(RCP_HC_BIT, pgste))
+ set_bit_simple(RCP_GR_BIT, pgste);
+ if (test_and_clear_bit_simple(RCP_HC_BIT, pgste))
SetPageDirty(page);
- if (test_and_clear_bit(RCP_HR_BIT, pgste))
+ if (test_and_clear_bit_simple(RCP_HR_BIT, pgste))
SetPageReferenced(page);
#endif
}
@@ -732,8 +732,8 @@ static inline int ptep_test_and_clear_yo
young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
rcp_lock(ptep);
if (young)
- set_bit(RCP_GR_BIT, pgste);
- young |= test_and_clear_bit(RCP_HR_BIT, pgste);
+ set_bit_simple(RCP_GR_BIT, pgste);
+ young |= test_and_clear_bit_simple(RCP_HR_BIT, pgste);
rcp_unlock(ptep);
return young;
#endif



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 02/04] kvm-s390: Fix incorrect return value

2008-04-04 Thread Carsten Otte
From: Heiko Carstens <[EMAIL PROTECTED]>

kvm_arch_vcpu_ioctl_run currently incorrectly always returns 0.

Signed-off-by: Heiko Carstens <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 arch/s390/kvm/kvm-s390.c |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

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
@@ -497,7 +497,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v
vcpu_put(vcpu);
 
vcpu->stat.exit_userspace++;
-   return 0;
+   return rc;
 }
 
 static int __guestcopy(struct kvm_vcpu *vcpu, u64 guestdest, const void *from,



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 04/04] kvm-s390: rename stfl to kvm_stfl

2008-04-04 Thread Carsten Otte
From: Heiko Carstens <[EMAIL PROTECTED]>

Temporarily rename this function to avoid merge conflicts and/or
dependencies. This function will be removed as soon as git-s390
and kvm.git are finally upstream.

Signed-off-by: Heiko Carstens <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 arch/s390/kvm/priv.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Index: kvm/arch/s390/kvm/priv.c
===
--- kvm.orig/arch/s390/kvm/priv.c
+++ kvm/arch/s390/kvm/priv.c
@@ -151,7 +151,7 @@ static int handle_chsc(struct kvm_vcpu *
return 0;
 }
 
-static unsigned int stfl(void)
+static unsigned int kvm_stfl(void)
 {
asm volatile(
"   .insn   s,0xb2b1,0(0)\n" /* stfl */
@@ -162,7 +162,7 @@ static unsigned int stfl(void)
 
 static int handle_stfl(struct kvm_vcpu *vcpu)
 {
-   unsigned int facility_list = stfl();
+   unsigned int facility_list = kvm_stfl();
int rc;
 
vcpu->stat.instruction_stfl++;



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


[kvm-devel] [PATCH 01/04] kvm-s390: Some codingstyle issues.

2008-04-04 Thread Carsten Otte
From: Heiko Carstens <[EMAIL PROTECTED]>

Just a few codingstyle issues that have already been
commented on but that somehow got forgotten.

Signed-off-by: Heiko Carstens <[EMAIL PROTECTED]>
Signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
 arch/s390/kvm/gaccess.h   |   18 ++
 arch/s390/kvm/intercept.c |   35 +--
 arch/s390/kvm/kvm-s390.c  |   46 +++---
 arch/s390/kvm/kvm-s390.h  |6 --
 arch/s390/kvm/priv.c  |   11 ++-
 arch/s390/kvm/sigp.c  |4 +---
 6 files changed, 49 insertions(+), 71 deletions(-)

Index: linux-host/arch/s390/kvm/gaccess.h
===
--- linux-host.orig/arch/s390/kvm/gaccess.h
+++ linux-host/arch/s390/kvm/gaccess.h
@@ -42,8 +42,7 @@ static inline int get_guest_u64(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 7)
-   BUG();
+   BUG_ON(guestaddr & 7);
 
if (IS_ERR((void __force *) uptr))
return PTR_ERR((void __force *) uptr);
@@ -56,8 +55,7 @@ static inline int get_guest_u32(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 3)
-   BUG();
+   BUG_ON(guestaddr & 3);
 
if (IS_ERR((void __force *) uptr))
return PTR_ERR((void __force *) uptr);
@@ -70,8 +68,7 @@ static inline int get_guest_u16(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 1)
-   BUG();
+   BUG_ON(guestaddr & 1);
 
if (IS_ERR(uptr))
return PTR_ERR(uptr);
@@ -95,8 +92,7 @@ static inline int put_guest_u64(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 7)
-   BUG();
+   BUG_ON(guestaddr & 7);
 
if (IS_ERR((void __force *) uptr))
return PTR_ERR((void __force *) uptr);
@@ -109,8 +105,7 @@ static inline int put_guest_u32(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 3)
-   BUG();
+   BUG_ON(guestaddr & 3);
 
if (IS_ERR((void __force *) uptr))
return PTR_ERR((void __force *) uptr);
@@ -123,8 +118,7 @@ static inline int put_guest_u16(struct k
 {
void __user *uptr = __guestaddr_to_user(vcpu, guestaddr);
 
-   if (guestaddr & 1)
-   BUG();
+   BUG_ON(guestaddr & 1);
 
if (IS_ERR((void __force *) uptr))
return PTR_ERR((void __force *) uptr);
Index: linux-host/arch/s390/kvm/intercept.c
===
--- linux-host.orig/arch/s390/kvm/intercept.c
+++ linux-host/arch/s390/kvm/intercept.c
@@ -45,7 +45,7 @@ static int handle_lctg(struct kvm_vcpu *
 
do {
rc = get_guest_u64(vcpu, useraddr,
-   &vcpu->arch.sie_block->gcr[reg]);
+  &vcpu->arch.sie_block->gcr[reg]);
if (rc == -EFAULT) {
kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
break;
@@ -53,9 +53,7 @@ static int handle_lctg(struct kvm_vcpu *
useraddr += 8;
if (reg == reg3)
break;
-   reg = reg + 1;
-   if (reg > 15)
-   reg = 0;
+   reg = (reg + 1) % 16;
} while (1);
return 0;
 }
@@ -76,11 +74,10 @@ static int handle_lctl(struct kvm_vcpu *
if (base2)
useraddr += vcpu->arch.guest_gprs[base2];
 
-   reg = reg1;
-
VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
   disp2);
 
+   reg = reg1;
do {
rc = get_guest_u32(vcpu, useraddr, &val);
if (rc == -EFAULT) {
@@ -92,9 +89,7 @@ static int handle_lctl(struct kvm_vcpu *
useraddr += 4;
if (reg == reg3)
break;
-   reg = reg + 1;
-   if (reg > 15)
-   reg = 0;
+   reg = (reg + 1) % 16;
} while (1);
return 0;
 }
@@ -153,26 +148,25 @@ static int handle_validity(struct kvm_vc
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);
+vcpu->kvm->arch.guest_origin +
+vcpu->arch.sie_block->prefix,
+PAGE_SIZE);
return 0;
   

Re: [kvm-devel] [04/17] [PATCH] Add kvm arch-specific core code for kvm/ia64.-V8

2008-04-01 Thread Carsten Otte
Zhang, Xiantao wrote:
> Carsten Otte wrote:
>> Zhang, Xiantao wrote:
>>> Carsten Otte wrote:
>>>> Zhang, Xiantao wrote:
>>>>> Hi, Carsten
>>>>>  Why do you think it is racy?  In this function,
>>>>> target_vcpu->arch.launched should be set to 1 for the first run,
>>>>> and keep its value all the time.  Except the first IPI to wake up
>>>>> the vcpu, all IPIs received by target vcpu should go into "else"
>>>>> condition. So you mean the race condition exist in "else"  code ?
>>>> For example to lock against destroying that vcpu. Or, the waitqueue
>>>> may become active after if (waitqueue_active()) and before
>>>> wake_up_interruptible(). In that case, the target vcpu might sleep
>>>> and not get waken up by the ipi.
>>> I don't think it may cause issue, because the target vcpu at least
>>> can be waken up by the timer interrupt.
>>>
>>> But as you said,  x86 side also have the same race issue ?
>> As far as I can tell, x86 does'nt have that race.
> 
> Hi, Carsten
>   I can't understand why it only exist at IA64 side. Thank you! 
> Xiantao
Well, x86 does'nt signal the target processor by accessing the vcpu 
data structure. They use the IPI signal for that as far as I can see.
And s390 does have an explicit lock for this purpose. Itanium however, 
does not have a lock but does access the target vcpu struct.

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [04/17] [PATCH] Add kvm arch-specific core code for kvm/ia64.-V8

2008-04-01 Thread Carsten Otte
Zhang, Xiantao wrote:
> Carsten Otte wrote:
>> Zhang, Xiantao wrote:
>>> Hi, Carsten
>>>  Why do you think it is racy?  In this function,
>>> target_vcpu->arch.launched should be set to 1 for the first run, and
>>> keep its value all the time.  Except the first IPI to wake up the
>>> vcpu, all IPIs received by target vcpu should go into "else"
>>> condition. So you mean the race condition exist in "else"  code ?
>> For example to lock against destroying that vcpu. Or, the waitqueue
>> may become active after if (waitqueue_active()) and before
>> wake_up_interruptible(). In that case, the target vcpu might sleep and
>> not get waken up by the ipi.
> I don't think it may cause issue, because the target vcpu at least can
> be waken up by the timer interrupt. 
> 
> But as you said,  x86 side also have the same race issue ? 
As far as I can tell, x86 does'nt have that race.

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [04/17] [PATCH] Add kvm arch-specific core code for kvm/ia64.-V8

2008-04-01 Thread Carsten Otte
Zhang, Xiantao wrote:
> Hi, Carsten 
>  Why do you think it is racy?  In this function,
> target_vcpu->arch.launched should be set to 1 for the first run, and
> keep its value all the time.  Except the first IPI to wake up the vcpu,
> all IPIs received by target vcpu should go into "else" condition. So you
> mean the race condition exist in "else"  code ?
For example to lock against destroying that vcpu. Or, the waitqueue 
may become active after if (waitqueue_active()) and before 
wake_up_interruptible(). In that case, the target vcpu might sleep and 
not get waken up by the ipi.

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [01/17]PATCH Add API for allocating dynamic TR resouce. V8

2008-04-01 Thread Carsten Otte
Zhang, Xiantao wrote:
> Carsten Otte wrote:
>> Zhang, Xiantao wrote:
>>> +/*  mca_insert_tr
>>> + *
>>> + *  Switch rid when TR reload and needed!
>>> + *  iord: 1: itr, 2: itr;
>>> + *
>>> +*/
>>> +static void mca_insert_tr(u64 iord)
>>> +{
>>> +
>>> +   int i;
>>> +   u64 old_rr;
>>> +   struct ia64_tr_entry *p;
>>> +   unsigned long psr;
>>> +   int cpu = smp_processor_id();
>> What if CONFIG_PREEMPT is on, and we're being preempted and scheduled
>> to a different CPU here? Are we running preempt disabled here? If so,
>> the function header should state that this function needs to be called
>> preempt_disabled.
> 
> The function insert one TR to local TLB, and doesn't allow preempt
> before and after the call, so the caller should be with preempt_disable
> before calling into this routine. 
> Maybe the descripiton of this function should contain "Called with
> preempt disabled!".  Does it make sense ?
Yea, I think a comment would help in that case :-).


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [05/17][PATCH] kvm/ia64 : Add head files for kvm/ia64

2008-03-31 Thread Carsten Otte

> +/**
> 
> +  VCPU control register access routines
> +
> 
> **/
> +static inline u64 vcpu_get_itir(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, itir));
> +}
> +
> +static inline void vcpu_set_itir(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, itir) = val;
> +}
> +
> +static inline u64 vcpu_get_ifa(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, ifa));
> +}
> +
> +static inline void vcpu_set_ifa(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, ifa) = val;
> +}
> +
> +static inline u64 vcpu_get_iva(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, iva));
> +}
> +
> +static inline u64 vcpu_get_pta(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, pta));
> +}
> +
> +static inline u64 vcpu_get_lid(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, lid));
> +}
> +
> +static inline u64 vcpu_get_tpr(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, tpr));
> +}
> +
> +static inline u64 vcpu_get_eoi(VCPU *vcpu)
> +{
> + return (0UL);   /*reads of eoi always return 0 */
> +}
> +
> +static inline u64 vcpu_get_irr0(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, irr[0]));
> +}
> +
> +static inline u64 vcpu_get_irr1(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, irr[1]));
> +}
> +
> +static inline u64 vcpu_get_irr2(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, irr[2]));
> +}
> +
> +static inline u64 vcpu_get_irr3(VCPU *vcpu)
> +{
> + return ((u64)VCPU(vcpu, irr[3]));
> +}
> +
> +static inline void vcpu_set_dcr(VCPU *vcpu, u64 val)
> +{
> + ia64_set_dcr(val);
> +}
> +
> +static inline void vcpu_set_isr(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, isr) = val;
> +}
> +
> +static inline void vcpu_set_lid(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, lid) = val;
> +}
> +
> +static inline void vcpu_set_ipsr(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, ipsr) = val;
> +}
> +
> +static inline void vcpu_set_iip(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, iip) = val;
> +}
> +
> +static inline void vcpu_set_ifs(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, ifs) = val;
> +}
> +
> +static inline void vcpu_set_iipa(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, iipa) = val;
> +}
> +
> +static inline void vcpu_set_iha(VCPU *vcpu, u64 val)
> +{
> + VCPU(vcpu, iha) = val;
> +}
> +
> +
> +static inline u64 vcpu_get_rr(VCPU *vcpu, u64 reg)
> +{
> + return vcpu->arch.vrr[reg>>61];
> +}
Looks to me like most of them can be replaced by a few macros using 
macro_##.

> +static inline int highest_bits(int *dat)
> +{
> + u32  bits, bitnum;
> + int i;
> +
> + /* loop for all 256 bits */
> + for (i = 7; i >= 0 ; i --) {
> + bits = dat[i];
> + if (bits) {
> + bitnum = fls(bits);
> + return i * 32 + bitnum - 1;
> + }
> + }
> + return NULL_VECTOR;
> +}
duplicate to asm/bitops.h find_first_bit().

-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [04/17] [PATCH] Add kvm arch-specific core code for kvm/ia64.-V8

2008-03-31 Thread Carsten Otte
Zhang, Xiantao wrote:
> +static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id,
> + unsigned long eid)
> +{
> + ia64_lid_t lid;
> + int i;
> +
> + for (i = 0; i < KVM_MAX_VCPUS; i++) {
> + if (kvm->vcpus[i]) {
> + lid.val = VCPU_LID(kvm->vcpus[i]);
> + if (lid.id == id && lid.eid == eid)
> + return kvm->vcpus[i];
> + }
> + }
> +
> + return NULL;
> +}
> +
> +static int handle_ipi(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
> +{
> + struct exit_ctl_data *p = kvm_get_exit_data(vcpu);
> + struct kvm_vcpu *target_vcpu;
> + struct kvm_pt_regs *regs;
> + ia64_ipi_a addr = p->u.ipi_data.addr;
> + ia64_ipi_d data = p->u.ipi_data.data;
> +
> + target_vcpu = lid_to_vcpu(vcpu->kvm, addr.id, addr.eid);
> + if (!target_vcpu)
> + return handle_vm_error(vcpu, kvm_run);
> +
> + if (!target_vcpu->arch.launched) {
> + regs = vcpu_regs(target_vcpu);
> +
> + regs->cr_iip = vcpu->kvm->arch.rdv_sal_data.boot_ip;
> + regs->r1 = vcpu->kvm->arch.rdv_sal_data.boot_gp;
> +
> + target_vcpu->arch.mp_state = VCPU_MP_STATE_RUNNABLE;
> + if (waitqueue_active(&target_vcpu->wq))
> + wake_up_interruptible(&target_vcpu->wq);
> + } else {
> + vcpu_deliver_ipi(target_vcpu, data.dm, data.vector);
> + if (target_vcpu != vcpu)
> + kvm_vcpu_kick(target_vcpu);
> + }
> +
> + return 1;
> +}
*Shrug*. This looks highly racy to me. You do access various values in 
target_vcpu without any lock! I know that taking the target vcpu's 
lock does'nt work because that one is held all the time during 
KVM_VCPU_RUN. My solution to that was struct local_interrupt, which 
has its own lock, and has the waitqueue plus everything I need to send 
a sigp [that's our flavor of ipi].

> +int kvm_emulate_halt(struct kvm_vcpu *vcpu)
> +{
> +
> + ktime_t kt;
> + long itc_diff;
> + unsigned long vcpu_now_itc;
> +
> + unsigned long expires;
> + struct hrtimer *p_ht = &vcpu->arch.hlt_timer;
That makes me jealous, I'd love to have hrtimer on s390 for this. I've 
got to round up to the next jiffie. *Sigh*

> +int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
> + struct kvm_sregs *sregs)
> +{
> + printk(KERN_WARNING"kvm:kvm_arch_vcpu_ioctl_set_sregs
> called!!\n");
> + return 0;
> +}
> +
> +int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
> + struct kvm_sregs *sregs)
> +{
> + printk(KERN_WARNING"kvm:kvm_arch_vcpu_ioctl_get_sregs
> called!!\n");
> + return 0;
> +
> +}
Suggestion: if get/set sregs does'nt seem useful on ia64, why not 
return -EINVAL? In that case, you could also not print a kern warning, 
the user will either handle that situation or complain.

> +int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
> +{

> + /*FIXME:Need to removed it later!!\n*/
> + vcpu->arch.apic = kzalloc(sizeof(struct kvm_lapic), GFP_KERNEL);
> + vcpu->arch.apic->vcpu = vcpu;
Fixme!

> +static int vti_vcpu_setup(struct kvm_vcpu *vcpu, int id)
> +{
> + unsigned long psr;
> + int r;
> +
> + local_irq_save(psr);
> + r = kvm_insert_vmm_mapping(vcpu);
> + if (r)
> + goto fail;
> + r = kvm_vcpu_init(vcpu, vcpu->kvm, id);
> + if (r)
> + goto fail;
Maybe change to return r, rather then goto fail?

> +int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
> *fpu)
> +{
> + printk(KERN_WARNING"kvm:IA64 doesn't need to export"
> + "fpu to userspace!\n");
> + return 0;
> +}
> +
> +int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
> *fpu)
> +{
> + printk(KERN_WARNING"kvm:IA64 doesn't need to export"
> + "fpu to userspace !\n");
> + return 0;
> +}
maybe -EINVAL?

> +static int find_highest_bits(int *dat)
> +{
> + u32  bits, bitnum;
> + int i;
> +
> + /* loop for all 256 bits */
> + for (i = 7; i >= 0 ; i--) {
> + bits = dat[i];
> + if (bits) {
> + bitnum = fls(bits);
> + return i * 32 + bitnum - 1;
> + }
> + }
> +
> + return -1;
> +}
Should be in asm/bitops.h. Look at find_first_bit() and friends, this 
is duplicate.


-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


Re: [kvm-devel] [03/15][PATCH] kvm/ia64: Add header files for kvm/ia64. V8

2008-03-31 Thread Carsten Otte
Zhang, Xiantao wrote:
> +typedef union context {
> + /* 8K size */
> + chardummy[KVM_CONTEXT_SIZE];
> + struct {
> + unsigned long   psr;
> + unsigned long   pr;
> + unsigned long   caller_unat;
> + unsigned long   pad;
> + unsigned long   gr[32];
> + unsigned long   ar[128];
> + unsigned long   br[8];
> + unsigned long   cr[128];
> + unsigned long   rr[8];
> + unsigned long   ibr[8];
> + unsigned long   dbr[8];
> + unsigned long   pkr[8];
> + struct ia64_fpreg   fr[128];
> + };
> +} context_t;
This looks ugly to me. I'd rather prefer to have a straight struct 
with elements psr...fr[], and cast the pointer to char* when needed. 
KVM_CONTEXT_SIZE can be used as parameter to kzalloc() on allocation, 
it's too large to be on stack anyway.

> +typedef struct thash_data {
> + union {
> + struct {
> + unsigned long p:  1; /* 0 */
> + unsigned long rv1  :  1; /* 1 */
> + unsigned long ma   :  3; /* 2-4 */
> + unsigned long a:  1; /* 5 */
> + unsigned long d:  1; /* 6 */
> + unsigned long pl   :  2; /* 7-8 */
> + unsigned long ar   :  3; /* 9-11 */
> + unsigned long ppn  : 38; /* 12-49 */
> + unsigned long rv2  :  2; /* 50-51 */
> + unsigned long ed   :  1; /* 52 */
> + unsigned long ig1  : 11; /* 53-63 */
> + };
> + struct {
> + unsigned long __rv1 : 53; /* 0-52 */
> + unsigned long contiguous : 1; /*53 */
> + unsigned long tc : 1; /* 54 TR or TC */
> + unsigned long cl : 1;
> + /* 55 I side or D side cache line */
> + unsigned long len  :  4;  /* 56-59 */
> + unsigned long io  : 1;  /* 60 entry is for io or
> not */
> + unsigned long nomap : 1;
> + /* 61 entry cann't be inserted into machine
> TLB.*/
> + unsigned long checked : 1;
> + /* 62 for VTLB/VHPT sanity check */
> + unsigned long invalid : 1;
> + /* 63 invalid entry */
> + };
> + unsigned long page_flags;
> + };  /* same for VHPT and TLB */
> +
> + union {
> + struct {
> + unsigned long rv3  :  2;
> + unsigned long ps   :  6;
> + unsigned long key  : 24;
> + unsigned long rv4  : 32;
> + };
> + unsigned long itir;
> + };
> + union {
> + struct {
> + unsigned long ig2  :  12;
> + unsigned long vpn  :  49;
> + unsigned long vrn  :   3;
> + };
> + unsigned long ifa;
> + unsigned long vadr;
> + struct {
> + unsigned long tag  :  63;
> + unsigned long ti   :  1;
> + };
> + unsigned long etag;
> + };
> + union {
> + struct thash_data *next;
> + unsigned long rid;
> + unsigned long gpaddr;
> + };
> +} thash_data_t;
A matter of taste, but I'd prefer unsigned long mask, and
#define MASK_BIT_FOR_PURPUSE over bitfields. This structure could be 
much smaller that way.

> +struct kvm_regs {
> + char *saved_guest;
> + char *saved_stack;
> + struct saved_vpd vpd;
> + /*Arch-regs*/
> + int mp_state;
> + unsigned long vmm_rr;
> + /* TR and TC.  */
> + struct thash_data itrs[NITRS];
> + struct thash_data dtrs[NDTRS];
> + /* Bit is set if there is a tr/tc for the region.  */
> + unsigned char itr_regions;
> + unsigned char dtr_regions;
> + unsigned char tc_regions;
> +
> + char irq_check;
> + unsigned long saved_itc;
> + unsigned long itc_check;
> + unsigned long timer_check;
> + unsigned long timer_pending;
> + unsigned long last_itc;
> +
> + unsigned long vrr[8];
> + unsigned long ibr[8];
> + unsigned long dbr[8];
> + unsigned long insvc[4]; /* Interrupt in service.  */
> + unsigned long xtp;
> +
> + unsigned long metaphysical_rr0; /* from kvm_arch (so is pinned)
> */
> + unsigned long metaphysical_rr4; /* from kvm_arch (so is pinned)
> */
> + unsigned long metaphysical_saved_rr0; /* from kvm_arch
> */
> + unsigned long metaphysical_saved_rr4; /* from kvm_arch
> */
> + unsigned long fp_psr;   /*used for lazy float register */
> + unsigned long saved_gp;
> + /*for phycial  emulation */

Re: [kvm-devel] [01/17]PATCH Add API for allocating dynamic TR resouce. V8

2008-03-31 Thread Carsten Otte
Zhang, Xiantao wrote:
> +/*  mca_insert_tr
> + *
> + *  Switch rid when TR reload and needed!
> + *  iord: 1: itr, 2: itr;
> + *
> +*/
> +static void mca_insert_tr(u64 iord)
> +{
> +
> + int i;
> + u64 old_rr;
> + struct ia64_tr_entry *p;
> + unsigned long psr;
> + int cpu = smp_processor_id();
What if CONFIG_PREEMPT is on, and we're being preempted and scheduled 
to a different CPU here? Are we running preempt disabled here? If so, 
the function header should state that this function needs to be called 
preempt_disabled.

> +/*
> + * ia64_insert_tr in virtual mode. Allocate a TR slot
> + *
> + * target_mask : 0x1 : itr, 0x2 : dtr, 0x3 : idtr
> + *
> + * va: virtual address.
> + * pte   : pte entries inserted.
> + * log_size: range to be covered.
> + *
> + * Return value:  <0 :  error No.
> + *
> + * >=0 : slot number allocated for TR.
> + */
> +int ia64_itr_entry(u64 target_mask, u64 va, u64 pte, u64 log_size)
> +{
> + int i, r;
> + unsigned long psr;
> + struct ia64_tr_entry *p;
> + int cpu = smp_processor_id();
Same here.

> +/*
> + * ia64_purge_tr
> + *
> + * target_mask: 0x1: purge itr, 0x2 : purge dtr, 0x3 purge idtr.
> + *
> + * slot: slot number to be freed.
> + */
> +void ia64_ptr_entry(u64 target_mask, int slot)
> +{
> + int cpu = smp_processor_id();
> + int i;
> + struct ia64_tr_entry *p;
Here again.



-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel


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

2008-03-25 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 14/15 v3] guest: detect when running on kvm

2008-03-25 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  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 v3] guest: virtio device support, and kvm hypercalls

2008-03-25 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 |  332 ++
 include/asm-s390/kvm_para.h   |  124 +++
 include/asm-s390/kvm_virtio.h |   54 ++
 5 files changed, 518 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,332 @@
+/*
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * 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;
+}
+
+/*
+ * Reading and writing elements in config spa

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

2008-03-25 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 10/15 v3] kvm-s390: intercepts for diagnose instructions

2008-03-25 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 
+#include 
+#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
{ "instr

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

2008-03-25 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 
+#include 
+#include 
+
+#include 
+
+#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 
 #include 
 
+#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_va

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

2008-03-25 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_l

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

2008-03-25 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 inter

[kvm-devel] [RFC/PATCH 08/15 v3] kvm-s390: intercepts for privileged instructions

2008-03-25 Thread Carsten Otte
From: Carsten Otte <[EMAIL PROTECTED]>
From: Christian Borntraeger <[EMAIL PROTECTED]>

This patch introduces in-kernel handling of some intercepts for privileged
instructions:
handle_set_prefix()sets the prefix register of the local cpu
handle_store_prefix()  stores the content of the prefix register to memory
handle_store_cpu_address() stores the cpu number of the current cpu to memory
handle_skey()  just decrements the instruction address and retries
handle_stsch() delivers condition code 3 "operation not supported"
handle_chsc()  same here
handle_stfl()  stores the facility list which contains the
   capabilities of the cpu
handle_stidp() stores cpu type/model/revision and such
handle_stsi()  stores information about the system topology

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   |1 
 arch/s390/kvm/kvm-s390.c|   11 +
 arch/s390/kvm/kvm-s390.h|3 
 arch/s390/kvm/priv.c|  322 
 include/asm-s390/kvm_host.h |   13 +
 6 files changed, 351 insertions(+), 1 deletion(-)

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
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.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] = {
+   [0xb2] = kvm_s390_handle_priv,
[0xb7] = handle_lctl,
[0xeb] = handle_lctg,
 };
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
@@ -48,6 +48,15 @@ struct kvm_stats_debugfs_item debugfs_en
{ "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) },
{ "deliver_program_interruption", VCPU_STAT(deliver_program_int) },
{ "exit_wait_state", VCPU_STAT(exit_wait_state) },
+   { "instruction_stidp", VCPU_STAT(instruction_stidp) },
+   { "instruction_spx", VCPU_STAT(instruction_spx) },
+   { "instruction_stpx", VCPU_STAT(instruction_stpx) },
+   { "instruction_stap", VCPU_STAT(instruction_stap) },
+   { "instruction_storage_key", VCPU_STAT(instruction_storage_key) },
+   { "instruction_stsch", VCPU_STAT(instruction_stsch) },
+   { "instruction_chsc", VCPU_STAT(instruction_chsc) },
+   { "instruction_stsi", VCPU_STAT(instruction_stsi) },
+   { "instruction_stfl", VCPU_STAT(instruction_stfl) },
{ NULL }
 };
 
@@ -249,6 +258,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu 
vcpu->arch.sie_block->eca   = 0xC1002001U;
setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup,
 (unsigned long) vcpu);
+   get_cpu_id(&vcpu->arch.cpu_id);
+   vcpu->arch.cpu_id.version = 0xfe;
return 0;
 }
 
Index: linux-host/arch/s390/kvm/kvm-s390.h
===
--- linux-host.orig/arch/s390/kvm/kvm-s390.h
+++ linux-host/arch/s390/kvm/kvm-s390.h
@@ -47,4 +47,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
 int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
struct kvm_s390_interrupt *s390int);
 int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
+
+/* implemented in priv.c */
+int kvm_s390_handle_priv(struct kvm_vcpu *vcpu);
 #endif
Index: linux-host/arch/s390/kvm/priv.c
===
--- /dev/null
+++ linux-host/arch/s390/kvm/priv.c
@@ -0,0 +1,322 @@
+/*
+ * priv.c - handling privileged 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "gaccess.h&qu

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

2008-03-25 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 
 
 #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;
+   

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

2008-03-25 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 
+#include 
+#include 
+
+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)
+   g

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

2008-03-25 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 
 #include 
 #include 
+#include 
 
 /* Sigh, math-emu. Don't ask. */
 #include 
 #include 
 #include 
 
-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];
+   unsign

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

2008-03-25 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 v3] preparation: host memory management changes for s390 kvm

2008-03-25 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 |   92 +++--
 mm/rmap.c  |7 +--
 2 files changed, 93 insertions(+), 6 deletions(-)

Index: kvm/include/asm-s390/pgtable.h
===
--- kvm.orig/include/asm-s390/pgtable.h
+++ kvm/include/asm-s390/pgtable.h
@@ -30,6 +30,7 @@
  */
 #ifndef __ASSEMBLY__
 #include 
+#include 
 #include 
 #include 
 
@@ -258,6 +259,13 @@ extern char empty_zero_page[PAGE_SIZE];
  * swap pte is 1011 and 0001, 0011, 0101, 0111 are invalid.
  */
 
+/* Page status table bits for virtualization */
+#define RCP_PCL_BIT55
+#define RCP_HR_BIT 54
+#define RCP_HC_BIT 53
+#define RCP_GR_BIT 50
+#define RCP_GC_BIT 49
+
 #ifndef __s390x__
 
 /* Bits in the segment table address-space-control-element */
@@ -513,6 +521,48 @@ 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
+   unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+   preempt_disable();
+   while (test_and_set_bit(RCP_PCL_BIT, pgste))
+   ;
+#endif
+}
+
+static inline void rcp_unlock(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+   unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+   clear_bit(RCP_PCL_BIT, pgste);
+   preempt_enable();
+#endif
+}
+
+/* forward declaration for SetPageUptodate in page-flags.h*/
+static inline void page_clear_dirty(struct page *page);
+#include 
+
+static inline void ptep_rcp_copy(pte_t *ptep)
+{
+#ifdef CONFIG_PGSTE
+   struct page *page = virt_to_page(pte_val(*ptep));
+   unsigned int skey;
+   unsigned long *pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+
+   skey = page_get_storage_key(page_to_phys(page));
+   if (skey & _PAGE_CHANGED)
+   set_bit(RCP_GC_BIT, pgste);
+   if (skey & _PAGE_REFERENCED)
+   set_bit(RCP_GR_BIT, pgste);
+   if (test_and_clear_bit(RCP_HC_BIT, pgste))
+   SetPageDirty(page);
+   if (test_and_clear_bit(RCP_HR_BIT, pgste))
+   SetPageReferenced(page);
+#endif
+}
+
 /*
  * query functions pte_write/pte_dirty/pte_young only work if
  * pte_present() is true. Undefined behaviour if not..
@@ -599,6 +649,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 +719,24 @@ 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 *ptep)
 {
+#ifdef CONFIG_PGSTE
+   unsigned long physpage;
+   int young;
+   unsigned long *pgste;
+
+   if (!vma->vm_mm->context.pgstes)
+   return 0;
+   physpage = pte_val(*ptep) & PAGE_MASK;
+   pgste = (unsigned long *) (ptep + PTRS_PER_PTE);
+
+   young = ((page_get_storage_key(physpage) & _PAGE_REFERENCED) != 0);
+   rcp_lock(ptep);
+   if (young)
+   set_bit(RCP_GR_BIT, pgste);
+   young |= test_and_clear_bit(RC

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

2008-03-25 Thread Carsten Otte
Many thanks for the review feedback we have received so far,
and many thanks to Andrew for reviewing our common code memory
management changes. I do greatly appreciate that :-).

All important parts have been reviewed, all review feedback has been
integrated in the code. Therefore we would like to ask for inclusion of
our work into kvm.git.

Changes from 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 :-).

Changes from Version 2:
- include feedback from Rusty Russell on the virtio patch
- include fix for race s390_enable_sie() versus ptrace spotted by Dave 
  Hansen: we now do task_lock() to protect mm_users from update while 
  we're growing the page table. Good catch, Dave :-).
- rebase to current kvm.git hash g680615e

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.

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


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

2008-03-25 Thread Carsten Otte
From: Martin Schwidefsky <[EMAIL PROTECTED]>
From: Carsten Otte <[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. Following Martin's suggestion, s390_enable_sie() does now
call task_lock() to prevent race against ptrace modification of mm_users.

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 |   65 +++--
 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, 82 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,43 @@ void disable_noexec(struct mm_struct *mm
mm->context.noexec = 0;

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

2008-03-25 Thread Carsten Otte
Am Freitag, den 21.03.2008, 11:29 -0700 schrieb Dave Hansen:
> 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.

Good catch, Dave. We intend to get rid of that race via task_lock().
That should lock out ptrace and all others who modify mm_users via get_task_mm.


See patch below:
---

 arch/s390/Kconfig  |4 ++
 arch/s390/kernel/setup.c   |4 ++
 arch/s390/mm/pgtable.c |   65 +++--
 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, 82 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,43 @@ void disable_noexec(struct mm_stru

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

2008-03-24 Thread Carsten Otte
Avi Kivity wrote:
> Well, dup_mm() can't work (and now that I think about it, for more 
> reasons -- what if the process has threads?).
We lock out multithreaded users already, -EINVAL.


-
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 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


[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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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;
+}
+
+/*
+ * Reading and writing elements in 

[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  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 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 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 inter

[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 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 
+#include 
+#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
{ "instr

[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 
+#include 
+#include 
+
+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)
+   g

[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_l

[kvm-devel] [RFC/PATCH 08/15 v2] kvm-s390: intercepts for privileged instructions

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

This patch introduces in-kernel handling of some intercepts for privileged
instructions:
handle_set_prefix()sets the prefix register of the local cpu
handle_store_prefix()  stores the content of the prefix register to memory
handle_store_cpu_address() stores the cpu number of the current cpu to memory
handle_skey()  just decrements the instruction address and retries
handle_stsch() delivers condition code 3 "operation not supported"
handle_chsc()  same here
handle_stfl()  stores the facility list which contains the
   capabilities of the cpu
handle_stidp() stores cpu type/model/revision and such
handle_stsi()  stores information about the system topology

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   |1 
 arch/s390/kvm/kvm-s390.c|   11 +
 arch/s390/kvm/kvm-s390.h|3 
 arch/s390/kvm/priv.c|  322 
 include/asm-s390/kvm_host.h |   13 +
 6 files changed, 351 insertions(+), 1 deletion(-)

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
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.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] = {
+   [0xb2] = kvm_s390_handle_priv,
[0xb7] = handle_lctl,
[0xeb] = handle_lctg,
 };
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
@@ -48,6 +48,15 @@ struct kvm_stats_debugfs_item debugfs_en
{ "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) },
{ "deliver_program_interruption", VCPU_STAT(deliver_program_int) },
{ "exit_wait_state", VCPU_STAT(exit_wait_state) },
+   { "instruction_stidp", VCPU_STAT(instruction_stidp) },
+   { "instruction_spx", VCPU_STAT(instruction_spx) },
+   { "instruction_stpx", VCPU_STAT(instruction_stpx) },
+   { "instruction_stap", VCPU_STAT(instruction_stap) },
+   { "instruction_storage_key", VCPU_STAT(instruction_storage_key) },
+   { "instruction_stsch", VCPU_STAT(instruction_stsch) },
+   { "instruction_chsc", VCPU_STAT(instruction_chsc) },
+   { "instruction_stsi", VCPU_STAT(instruction_stsi) },
+   { "instruction_stfl", VCPU_STAT(instruction_stfl) },
{ NULL }
 };
 
@@ -249,6 +258,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu 
vcpu->arch.sie_block->eca   = 0xC1002001U;
setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup,
 (unsigned long) vcpu);
+   get_cpu_id(&vcpu->arch.cpu_id);
+   vcpu->arch.cpu_id.version = 0xfe;
return 0;
 }
 
Index: linux-host/arch/s390/kvm/kvm-s390.h
===
--- linux-host.orig/arch/s390/kvm/kvm-s390.h
+++ linux-host/arch/s390/kvm/kvm-s390.h
@@ -47,4 +47,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
 int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
struct kvm_s390_interrupt *s390int);
 int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
+
+/* implemented in priv.c */
+int kvm_s390_handle_priv(struct kvm_vcpu *vcpu);
 #endif
Index: linux-host/arch/s390/kvm/priv.c
===
--- /dev/null
+++ linux-host/arch/s390/kvm/priv.c
@@ -0,0 +1,322 @@
+/*
+ * priv.c - handling privileged 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "gaccess.h&qu

[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 
+#include 
+#include 
+
+#include 
+
+#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 
 #include 
 
+#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_va

[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 
 
 #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;
+   

[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;
+   

[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 
 #include 
 #include 
+#include 
 
 /* Sigh, math-emu. Don't ask. */
 #include 
 #include 
 #include 
 
-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];
+   unsign

[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 
+#include 
 #include 
 #include 
 
@@ -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 
+
+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, 

[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


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


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

2008-03-21 Thread Carsten Otte
Dave Hansen wrote:
> On Thu, 2008-03-20 at 21:35 +0100, Carsten Otte wrote:
>> Dave Hansen wrote:
>>> Well, and more fundamentally: do we really want dup_mm() able to be
>>> called from other code?
>>>
>>> Maybe we need a bit more detailed justification why fork() itself isn't
>>> good enough.  It looks to me like they basically need an arch-specific
>>> argument to fork, telling the new process's page tables to take the
>>> fancy new bit.
>>>
>>> I'm really curious how this new stuff is going to get used.  Are you
>>> basically replacing fork() when creating kvm guests?
>> No. The trick is, that we do need bigger page tables when running 
>> guests: our page tables are usually 2k, but when running a guest 
>> they're 4k to track both guest and host dirty&reference information. 
>> This looks like this:
>> *--*
>> *2k PTE's  *
>> *--*
>> *2k PGSTE  *
>> *--*
>> We don't want to waste precious memory for all page tables. We'd like 
>> to have one kernel image that runs regular server workload _and_ 
>> guests.
> 
> That makes a lot of sense.
> 
> Is that layout (the shadow and regular stacked together) specified in
> hardware somehow, or was it just chosen?
It's defined by hardware. The chip just adds +2k to the ptep to get to 
the corresponding pgste. Both pte and pgste are 64bit per page. I know 
Heiko and Martin have thought a lot about possible races. I'll have to 
leave your question on the race against pfault open for them.

Btw: thanks a lot for reviewing our changes :-)

cheers,
Carsten

-
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-21 Thread Carsten Otte
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.
---
 arch/s390/kernel/early.c |6 +++---
 include/asm-s390/setup.h |   32 ++--
 2 files changed, 25 insertions(+), 13 deletions(-)

Index: linux-host/arch/s390/kernel/early.c
===
--- linux-host.orig/arch/s390/kernel/early.c
+++ linux-host/arch/s390/kernel/early.c
@@ -138,15 +138,15 @@ static noinline __init void detect_machi
 
/* Running under z/VM ? */
if (cpuinfo->cpu_id.version == 0xff)
-   machine_flags |= 1;
+   machine_flags |= MACHINE_FLAG_VM;
 
/* Running on a P/390 ? */
if (cpuinfo->cpu_id.machine == 0x7490)
-   machine_flags |= 4;
+   machine_flags |= MACHINE_FLAG_P390;
 
/* Running under KVM ? */
if (cpuinfo->cpu_id.version == 0xfe)
-   machine_flags |= 64;
+   machine_flags |= MACHINE_FLAG_KVM;
 }
 
 #ifdef CONFIG_64BIT
Index: linux-host/include/asm-s390/setup.h
===
--- linux-host.orig/include/asm-s390/setup.h
+++ linux-host/include/asm-s390/setup.h
@@ -59,23 +59,35 @@ extern unsigned int s390_noexec;
  */
 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)
+#define MACHINE_FLAG_VM1
+#define MACHINE_FLAG_IEEE  2
+#define MACHINE_FLAG_P390  4
+#define MACHINE_FLAG_CSP   8
+#define MACHINE_FLAG_MVPG  16
+#define MACHINE_FLAG_DIAG4432
+#define MACHINE_FLAG_KVM   64
+#define MACHINE_FLAG_IDTE  128
+#define MACHINE_FLAG_DIAG9C256
+#define MACHINE_FLAG_MVCOS 512
+
+
+#define MACHINE_IS_VM  (machine_flags & MACHINE_FLAG_VM)
+#define MACHINE_IS_KVM (machine_flags & MACHINE_FLAG_KVM)
+#define MACHINE_IS_P390(machine_flags & MACHINE_FLAG_P390)
+#define MACHINE_HAS_MVPG   (machine_flags & MACHINE_FLAG_MVPG)
+#define MACHINE_HAS_IDTE   (machine_flags & MACHINE_FLAG_IDTE)
+#define MACHINE_HAS_DIAG9C (machine_flags & MACHINE_FLAG_DIAG9C)
 
 #ifndef __s390x__
-#define MACHINE_HAS_IEEE   (machine_flags & 2)
-#define MACHINE_HAS_CSP(machine_flags & 8)
+#define MACHINE_HAS_IEEE   (machine_flags & MACHINE_FLAG_IEEE)
+#define MACHINE_HAS_CSP(machine_flags & MACHINE_FLAG_CSP)
 #define MACHINE_HAS_DIAG44 (1)
 #define MACHINE_HAS_MVCOS  (0)
 #else /* __s390x__ */
 #define MACHINE_HAS_IEEE   (1)
 #define MACHINE_HAS_CSP(1)
-#define MACHINE_HAS_DIAG44 (machine_flags & 32)
-#define MACHINE_HAS_MVCOS  (machine_flags & 512)
+#define MACHINE_HAS_DIAG44 (machine_flags & MACHINE_FLAG_DIAG44)
+#define MACHINE_HAS_MVCOS  (machine_flags & MACHINE_FLAG_MVCOS)
 #endif /* __s390x__ */
 
 #define MACHINE_HAS_SCLP   (!MACHINE_IS_P390)



-
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 00/15] kvm on big iron

2008-03-21 Thread Carsten Otte
Avi Kivity wrote:
> Carsten Otte wrote:
>> This patch series introduces a backend for kvm to run on IBM System z
>> machines that uses the mainframe's sie virtualization capability. This
>> work runs 64bit guests on z800/z890/z900/z990/z9/z10 class machines with
>> a 64bit linux host. Userspace will follow once we're done brushing it
>> over.
>>   
> 
> I'm slightly worried about the changes to non arch code.  Perhaps Andrea 
> or Rik can look over the mm/ changes and ack?
Yea that's why I've copied linux-mm on the first two patches. 
Reallocating the page tables works sane and is simple, but whether or 
not we may export dup_mm is the real question.

> Other than that, and the few minor comments that popped up, this (very 
> nice) patchset will be very easy to merge.  IIRC you mentioned it is 
> possible for me to get an s390 account; this will be very useful in 
> avoiding breaking this port, as happens quite often with ppc and ia64.  
> I'd like to be able to do both build and run testing.
Glad to hear that you like the patchset. It would be cool if you could 
pull from Linus soon, because we do need a patch not yet in the 
kvm.git that the series is based upon. After that, we'll integrate the 
review feedback, rebase to latest git, and resubmit the series.

I'll see what I can do to get you access to a box. We'll also be 
following kvm.git closely during the kernel release cycles and report 
regressions or submit patches to clean them up.

-
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 12/15] kvm-s390: API documentation

2008-03-21 Thread Carsten Otte
Randy Dunlap wrote:
> This means that  [no comma]

Being a native speaker is cheating ;-). I've integrated your feedback, 
for the next round of sending out these patches. Thank you :-).

-
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 06/15] kvm-s390: sie intercept handling

2008-03-21 Thread Carsten Otte
Avi Kivity wrote:
> Carsten Otte wrote:
>>  
>>  /* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
>>  struct kvm_run {
>> @@ -138,6 +139,14 @@ struct kvm_run {
>>  __u32 is_write;
>>  __u32 pad;
>>  } tpr_access;
>> +/* KVM_EXIT_S390_SIEIC */
>> +struct {
>> +__u8 icptcode;
>> +__u64 mask; /* psw upper half */
>> +__u64 addr; /* psw lower half */
>> +__u16 ipa;
>> +__u32 ipb;
>> +} s390_sieic;
>>  /* Fix the size of the union. */
>>  char padding[256];
>>  };
>>
>>   
> 
> Do you support 32-bit userspace on 64-bit kernel?  If so, this is likely 
> badly aligned.
32bit userspace is not pracitcal, current enterprise distributions 
come with 64bit only on s390. Nevertheless, I don't get your point on 
allignment. What is the problem caused by the struct, and how can I 
solve it?

-
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 05/15] KVM_MAX_VCPUS

2008-03-21 Thread Carsten Otte
Avi Kivity wrote:
> Carsten Otte wrote:
>> Hollis Blanchard wrote:
>>  
>>> On Thu, 2008-03-20 at 17:24 +0100, Carsten Otte wrote:
>>>
>>>> Index: kvm/include/linux/kvm_host.h
>>>> ===
>>>> --- kvm.orig/include/linux/kvm_host.h
>>>> +++ kvm/include/linux/kvm_host.h
>>>> @@ -24,7 +24,11 @@
>>>>
>>>>  #include 
>>>>
>>>> +#ifdef CONFIG_S390
>>>> +#define KVM_MAX_VCPUS 64
>>>> +#else
>>>>  #define KVM_MAX_VCPUS 16
>>>> +#endif
>>>>  #define KVM_MEMORY_SLOTS 32
>>>>  /* memory slots that does not exposed to userspace */
>>>>  #define KVM_PRIVATE_MEM_SLOTS 4
>>>>
>>>>   
>>> Why don't we just define this in  ?
>>> 
>> No problem with that, I just wanted to keep impact on common code very 
>> low and things like this seperated from the actual port. I have a few 
>> things like this that can safely be taken care about later.
>>
>>   
> 
> Since there were a few other comments, I went ahead and moved those 
> #defines to asm-x86.
Great! I will rebase the patch series.

-
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-21 Thread Carsten Otte
[EMAIL PROTECTED] wrote:
> Since when do we have symbolic names for the bits?
> It was always on my todo list to do a cleanup and replace the numbers
> we use everywhere with names. Especially since we have clashes from time
> to time... but that didn't hurt enough yet, obviously.
> But now that you volunteered to take care of this... :)
Right. We only have defines for (machine_flags & bit). Looks to me 
like the bits really should have a name on them. I've created a patch 
that does this, but I want to talk it over with Martin before sending 
that one out.

-
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 15/15] guest: virtio device support, and kvm hypercalls

2008-03-21 Thread Carsten Otte
Rusty Russell wrote:
>> +static int __init kvm_devices_init(void)
>> +{
>> +if (!MACHINE_IS_KVM)
>> +return -ENODEV;
>> +
>> +if (device_register(&kvm_root) != 0)
>> +panic("Could not register kvm root");
>> +
>> +if (add_shared_memory((max_pfn) << PAGE_SHIFT, PAGE_SIZE)) {
>> +device_unregister(&kvm_root);
>> +return -ENOMEM;
>> +}
> 
> 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.
We can't tell whether or not this is an important device or not. Maybe 
the guest is running with ramdisk as rootfs and can have a happy life 
if we don't kill it here. Return the rc from device register seems to 
be the right thing to me, if it was an important device we'll see 
"panic: cannot mount rootfs" or something later.

-
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-20 Thread Carsten Otte
Christoph Hellwig wrote:
> On Thu, Mar 20, 2008 at 09:37:19PM +0100, Carsten Otte wrote:
>> Christoph Hellwig wrote:
>>> On Thu, Mar 20, 2008 at 05:25:26PM +0100, Carsten Otte wrote:
>>>> @@ -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;
>>> Shouldn't these have symbolic names?
>> You mean symbolics for machine_flags? Or symbolics for cpu ids?
> 
> Either.
Hmmh. For cpu id's did'nt make sense probably until now that kvm also 
uses them. Before, this was the only one place that uses them.

With kvm and 0xfe, this one is sort of temporary one. We intend to 
rework this code to use "store system information", which would give 
us way more information about the machine and it's hypervisor 
topology. Up until my todo list gets to that point, I think we'll have 
to cope with a temporary number. We'll aim for making that change 
before 2.6.26 gets released.

The machine flags do have symbolic names, defined in 
include/asm-s390/setup.h. And yea, they should be used here. Will 
change that.

-
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-20 Thread Carsten Otte
Christoph Hellwig wrote:
> On Thu, Mar 20, 2008 at 05:25:26PM +0100, Carsten Otte wrote:
>> @@ -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;
> 
> Shouldn't these have symbolic names?
You mean symbolics for machine_flags? Or symbolics for cpu ids?

-
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-20 Thread Carsten Otte
Dave Hansen wrote:
> Well, and more fundamentally: do we really want dup_mm() able to be
> called from other code?
> 
> Maybe we need a bit more detailed justification why fork() itself isn't
> good enough.  It looks to me like they basically need an arch-specific
> argument to fork, telling the new process's page tables to take the
> fancy new bit.
> 
> I'm really curious how this new stuff is going to get used.  Are you
> basically replacing fork() when creating kvm guests?
No. The trick is, that we do need bigger page tables when running 
guests: our page tables are usually 2k, but when running a guest 
they're 4k to track both guest and host dirty&reference information. 
This looks like this:
*--*
*2k PTE's  *
*--*
*2k PGSTE  *
*--*
We don't want to waste precious memory for all page tables. We'd like 
to have one kernel image that runs regular server workload _and_ 
guests. 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.


-
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-20 Thread Carsten Otte
Randy Dunlap wrote:
>> 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)
> 
> Hi,
> 
> Where are these magic numbers documented?  (0x7490, 0xfe, etc.)
> 
> 
>> +machine_flags |= 64;
>>  }
>>  
>>  #ifdef CONFIG_64BIT
The cpuid (and most other things about s390 arch) are documented in 
the principles of operation:
http://publibz.boulder.ibm.com/epubs/pdf/a2278324.pdf
http://publibz.boulder.ibm.com/epubs/pdf/dz9zs001.pdf

(see chapter "control instructions" - store cpu id)

The 0xfe however is convention, the kvm arch code sets this value 
where it implements that instruction. See "privileged instructions" patch.

-
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 05/15] KVM_MAX_VCPUS

2008-03-20 Thread Carsten Otte
Hollis Blanchard wrote:
> On Thu, 2008-03-20 at 17:24 +0100, Carsten Otte wrote:
>> Index: kvm/include/linux/kvm_host.h
>> ===
>> --- kvm.orig/include/linux/kvm_host.h
>> +++ kvm/include/linux/kvm_host.h
>> @@ -24,7 +24,11 @@
>>
>>  #include 
>>
>> +#ifdef CONFIG_S390
>> +#define KVM_MAX_VCPUS 64
>> +#else
>>  #define KVM_MAX_VCPUS 16
>> +#endif
>>  #define KVM_MEMORY_SLOTS 32
>>  /* memory slots that does not exposed to userspace */
>>  #define KVM_PRIVATE_MEM_SLOTS 4
>>
> Why don't we just define this in  ?
No problem with that, I just wanted to keep impact on common code very 
low and things like this seperated from the actual port. I have a few 
things like this that can safely be taken care about later.

-
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 06/15] kvm-s390: sie intercept handling

2008-03-20 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: kvm/arch/s390/kvm/Makefile
===
--- kvm.orig/arch/s390/kvm/Makefile
+++ kvm/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: kvm/arch/s390/kvm/intercept.c
===
--- /dev/null
+++ kvm/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 
+#include 
+#include 
+
+#include 
+
+#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: kvm/arch/s390/kvm/kvm-s390.c
===
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -23,12 +23,17 @@
 #include 
 #include 
 
+#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_

[kvm-devel] [RFC/PATCH 08/15] kvm-s390: intercepts for privileged instructions

2008-03-20 Thread Carsten Otte
From: Carsten Otte <[EMAIL PROTECTED]>
From: Christian Borntraeger <[EMAIL PROTECTED]>

This patch introduces in-kernel handling of some intercepts for privileged
instructions:
handle_set_prefix()sets the prefix register of the local cpu
handle_store_prefix()  stores the content of the prefix register to memory
handle_store_cpu_address() stores the cpu number of the current cpu to memory
handle_skey()  just decrements the instruction address and retries
handle_stsch() delivers condition code 3 "operation not supported"
handle_chsc()  same here
handle_stfl()  stores the facility list which contains the
   capabilities of the cpu
handle_stidp() stores cpu type/model/revision and such
handle_stsi()  stores information about the system topology

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   |1 
 arch/s390/kvm/kvm-s390.c|   11 +
 arch/s390/kvm/kvm-s390.h|3 
 arch/s390/kvm/priv.c|  322 
 include/asm-s390/kvm_host.h |   13 +
 6 files changed, 351 insertions(+), 1 deletion(-)

Index: kvm/arch/s390/kvm/Makefile
===
--- kvm.orig/arch/s390/kvm/Makefile
+++ kvm/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
+kvm-objs := $(common-objs) kvm-s390.o sie64a.o intercept.o interrupt.o priv.o
 obj-$(CONFIG_KVM) += kvm.o
Index: kvm/arch/s390/kvm/intercept.c
===
--- kvm.orig/arch/s390/kvm/intercept.c
+++ kvm/arch/s390/kvm/intercept.c
@@ -100,6 +100,7 @@ static int handle_lctl(struct kvm_vcpu *
 }
 
 static intercept_handler_t instruction_handlers[256] = {
+   [0xb2] = kvm_s390_handle_priv,
[0xb7] = handle_lctl,
[0xeb] = handle_lctg,
 };
Index: kvm/arch/s390/kvm/kvm-s390.c
===
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/arch/s390/kvm/kvm-s390.c
@@ -48,6 +48,15 @@ struct kvm_stats_debugfs_item debugfs_en
{ "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) },
{ "deliver_program_interruption", VCPU_STAT(deliver_program_int) },
{ "exit_wait_state", VCPU_STAT(exit_wait_state) },
+   { "instruction_stidp", VCPU_STAT(instruction_stidp) },
+   { "instruction_spx", VCPU_STAT(instruction_spx) },
+   { "instruction_stpx", VCPU_STAT(instruction_stpx) },
+   { "instruction_stap", VCPU_STAT(instruction_stap) },
+   { "instruction_storage_key", VCPU_STAT(instruction_storage_key) },
+   { "instruction_stsch", VCPU_STAT(instruction_stsch) },
+   { "instruction_chsc", VCPU_STAT(instruction_chsc) },
+   { "instruction_stsi", VCPU_STAT(instruction_stsi) },
+   { "instruction_stfl", VCPU_STAT(instruction_stfl) },
{ NULL }
 };
 
@@ -249,6 +258,8 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu 
vcpu->arch.sie_block->eca   = 0xC1002001U;
setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup,
 (unsigned long) vcpu);
+   get_cpu_id(&vcpu->arch.cpu_id);
+   vcpu->arch.cpu_id.version = 0xfe;
return 0;
 }
 
Index: kvm/arch/s390/kvm/kvm-s390.h
===
--- kvm.orig/arch/s390/kvm/kvm-s390.h
+++ kvm/arch/s390/kvm/kvm-s390.h
@@ -47,4 +47,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
 int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
struct kvm_s390_interrupt *s390int);
 int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code);
+
+/* implemented in priv.c */
+int kvm_s390_handle_priv(struct kvm_vcpu *vcpu);
 #endif
Index: kvm/arch/s390/kvm/priv.c
===
--- /dev/null
+++ kvm/arch/s390/kvm/priv.c
@@ -0,0 +1,322 @@
+/*
+ * priv.c - handling privileged 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "gaccess.h"
+#include "kvm-s390.h"
+
+static int handle_set_prefix(struct kvm_

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

2008-03-20 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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;
+}
+
+/*
+ * Reading and writing elements in 

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

2008-03-20 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  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 13/15] kvm-s390: update maintainers

2008-03-20 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 file changed, 10 insertions(+)

Index: kvm/MAINTAINERS
===
--- kvm.orig/MAINTAINERS
+++ kvm/MAINTAINERS
@@ -2296,6 +2296,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] kvm-s390: API documentation

2008-03-20 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 file changed, 125 insertions(+)

Index: kvm/Documentation/s390/kvm.txt
===
--- /dev/null
+++ kvm/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-visibe 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 does'nt 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 does'nt work proper 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 interrupt. The following interrupts are not considered
+to be useful as floating interrupt, 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

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

2008-03-20 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 10/15] kvm-s390: intercepts for diagnose instructions

2008-03-20 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: kvm/arch/s390/kvm/Makefile
===
--- kvm.orig/arch/s390/kvm/Makefile
+++ kvm/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: kvm/arch/s390/kvm/diag.c
===
--- /dev/null
+++ kvm/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 
+#include 
+#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: kvm/arch/s390/kvm/intercept.c
===
--- kvm.orig/arch/s390/kvm/intercept.c
+++ kvm/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: kvm/arch/s390/kvm/kvm-s390.c
===
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/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) },
{ &q

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

2008-03-20 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: kvm/arch/s390/kvm/Makefile
===
--- kvm.orig/arch/s390/kvm/Makefile
+++ kvm/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: kvm/arch/s390/kvm/intercept.c
===
--- kvm.orig/arch/s390/kvm/intercept.c
+++ kvm/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: kvm/arch/s390/kvm/kvm-s390.c
===
--- kvm.orig/arch/s390/kvm/kvm-s390.c
+++ kvm/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->ar

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

2008-03-20 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: kvm/arch/s390/kvm/Makefile
===
--- kvm.orig/arch/s390/kvm/Makefile
+++ kvm/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: kvm/arch/s390/kvm/intercept.c
===
--- kvm.orig/arch/s390/kvm/intercept.c
+++ kvm/arch/s390/kvm/intercept.c
@@ -18,6 +18,91 @@
 #include 
 
 #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.ins

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

2008-03-20 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 04/15] preparation: split sysinfo defintions for kvm use

2008-03-20 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 
 #include 
 #include 
+#include 
 
 /* Sigh, math-emu. Don't ask. */
 #include 
 #include 
 #include 
 
-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];
+   unsign

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

2008-03-20 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 |  119 +
 include/asm-s390/kvm_para.h |   30 ++
 include/linux/kvm.h |   15 +
 include/linux/kvm_host.h|4 
 13 files changed, 1159 insertions(+), 1 deletion(-)

Index: kvm/arch/s390/Makefile
===
--- kvm.orig/arch/s390/Makefile
+++ kvm/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: kvm/arch/s390/kernel/vtime.c
===
--- kvm.orig/arch/s390/kernel/vtime.c
+++ kvm/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: kvm/arch/s390/kvm/Makefile
===
--- /dev/null
+++ kvm/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: kvm/arch/s390/kvm/gaccess.h
===
--- /dev/null
+++ kvm/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 
+#include 
+#include 
+
+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 += 

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

2008-03-20 Thread Carsten Otte
This patch series introduces a backend for kvm to run on IBM System z
machines that uses the mainframe's sie virtualization capability. This
work runs 64bit guests on z800/z890/z900/z990/z9/z10 class machines with
a 64bit linux host. Userspace will follow once we're done brushing it
over.

The patch queue consists of the following patches, which can be applied
in sequence on top of kvm.git master as of 2008-03-20 hash g914bd66:
[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


Recommended reading:
If you're interrested in integration into kvm common code, you should
read patches 05-07, and 10.
If you're interrested in sie on s390, you should read patches 05-10.
If you're interrested in memory management, you should read patches
01-02.
If you're Rusty Russell, you should read patch 15.

We would kindly like to ask for review of our work for upstream
inclusion in kvm.git.

with kind regards,
Carsten


-
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] preparation: host memory management changes for s390 kvm

2008-03-20 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: kvm/include/asm-s390/pgtable.h
===
--- kvm.orig/include/asm-s390/pgtable.h
+++ kvm/include/asm-s390/pgtable.h
@@ -30,6 +30,7 @@
  */
 #ifndef __ASSEMBLY__
 #include 
+#include 
 #include 
 #include 
 
@@ -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 
+
+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 *ptep)
 {
+#ifde

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

2008-03-20 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.


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 |   55 ++---
 include/asm-s390/mmu.h |1 
 include/asm-s390/mmu_context.h |8 +
 include/asm-s390/pgtable.h |1 
 kernel/fork.c  |2 -
 7 files changed, 70 insertions(+), 5 deletions(-)

Index: kvm/arch/s390/Kconfig
===
--- kvm.orig/arch/s390/Kconfig
+++ kvm/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: kvm/arch/s390/kernel/setup.c
===
--- kvm.orig/arch/s390/kernel/setup.c
+++ kvm/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: kvm/arch/s390/mm/pgtable.c
===
--- kvm.orig/arch/s390/mm/pgtable.c
+++ kvm/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,33 @@ void disable_noexec(struct mm_struct *mm
mm->context.noexec = 0;
update_mm(mm, tsk);
 }
+
+struct mm_struct *dup_mm(struct task_struct *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 || 

Re: [kvm-devel] [PATCH 3 of 3] [POWERPC] Implement an ioctl that creates a vcpu of a particular type

2008-02-05 Thread Carsten Otte
Christian Ehrhardt wrote:
> This should work for other architectures too. While we need to specify 
> cpu cores here others might specify something completely different with 
> the same interface.
> So kvm_vcpu_create_type might be misleading while something like 
> kvm_vcpu_create_info might be more generic.
> Just to get some background - do anyone else see the need to specify a 
> detail on vcpu_create for their implementation in future ?
We do. For now, kvm_create_vcpu does create a cpu from a template. 
However our hardware control block allows to enable/disable various 
features. I would imagine that future userspace may want something 
different than the stock default values, and therefore a parameter 
would make sense for us too.

-
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] [PATCH 3 of 3] [POWERPC] Implement an ioctl that creates a vcpu of a particular type

2008-02-05 Thread Carsten Otte
Carsten Otte wrote:
> We do. For now, kvm_create_vcpu does create a cpu from a template. 
> However our hardware control block allows to enable/disable various 
> features. I would imagine that future userspace may want something 
> different than the stock default values, and therefore a parameter would 
> make sense for us too.
I suppose that parameter is supposed to show up in 
kvm_arch_vcpu_setup, not kvm_arch_vcpu_create?

-
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] swapping with MMU Notifiers V2

2008-01-30 Thread Carsten Otte
Avi Kivity wrote:
> Carsten Otte wrote:
>> We have similar restrictions than you're naming here. Our guest may 
>> start at a (userspace-) page boundary, and has a fixed 1:1 mapping to 
>> userspace for a given length. We do that by just having one memory 
>> slot which has to start at virtual address zero in kvm.
> 
> I thought you're using an offset to put the guest somewhere else?  
> Putting the guest at offset zero means that a qemu null pointer deref 
> causes a memory corruption instead of an abort.
At a page boundary in userspace (non-zero), that matches zero in guest 
physical. 1:1+n. Sorry for causing the confusion, my explanation was 
diffuse.

>> I have way to few knowledge about x86, but to me both the native page 
>> table layout and the nested one look very similar. I believe AMD has 
>> done a pretty good job designing that.
> 
> The page table formats are identical.
Looks like Andrea should start hacking then ;-).

-
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] swapping with MMU Notifiers V2

2008-01-30 Thread Carsten Otte
Andrea Arcangeli wrote:
> Oh I see! So when linux pte is cleared, the NPT equivalent is
> implicitly and atomically cleared too. That really requires _identical_
> semantics and formats for both pagetables.
Bingo. We have that on s390, and it seems workable on npt too.

> That problem is quite easily fixable by only sharing a 3rd level
> pagetable hand having the NPT-pgd filled with only that shared 3rd
> level linux pagetable. The guest ram can be allocated with MAP_FIXED
> at a proper 512G aligned address. That has the cons to reduce the max
> VM (_virtual_ adding more swap won't help) size to 512G. For the 64bit
> kernel that may not be really a problem, for 32bit it's likely a
> blocker instead. What worries me more are the details of the pte and
> tlbs, I don't know the NPT format well enough yet to comment, but I
> think when Avi just said we can't flush both tlbs in a single op
> through tlb tagging like s390, will still require mmu notifiers. Still
> if we can share the ptes it can save quite some memory for large VM,
> so even if the mmu notifiers only have to deal with tlb flush + unpin
> (without having to clear the NPT themself, anymore, because it was
> already cleared by ptep_clear_flush) that may be still interesting to
> consider. 
We have similar restrictions than you're naming here. Our guest may 
start at a (userspace-) page boundary, and has a fixed 1:1 mapping to 
userspace for a given length. We do that by just having one memory 
slot which has to start at virtual address zero in kvm. I have way to 
few knowledge about x86, but to me both the native page table layout 
and the nested one look very similar. I believe AMD has done a pretty 
good job designing that.

> Which pdf were you reading?
I believe it was 
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf


-
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] swapping with MMU Notifiers V2

2008-01-30 Thread Carsten Otte
Andrea Arcangeli wrote:
> By your conclusion I suppose you thought NPT maps guest physical to
> host virtual. If it was the case the cpu would to walk three layer of
> pagetables (each layer is an arrow): guest virtual -> guest physical
> -> host virtual -> host physical. Instead it's just guest virtual ->
> guest physical -> host physical. Or even less for shadow: guest
> virtual -> host physical, which is why shadow should be faster for
> number crunching still (and definitely slower for dbms).
No, I was assuming guest virtual -> guest physical -> host physical. 
We do the same. We just re-use the very same page table that maps gp 
to hp to map host userland to hp. The only tricky part for AMD64 is to 
hide host userland parts from the guest that are not supposed to be 
visible to the guest-os as far as I see.

-
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] swapping with MMU Notifiers V2

2008-01-30 Thread Carsten Otte
Joerg Roedel wrote:
> Since NPT uses the host page table format it is in theory possible to
> add the pagetable to the Linux MM rmap. In this case it would not be
> necessary to use MMU notifiers. But I think this would complicate the
> NPT support code significantly.
I was hoping for a "nearest neighbour" to s390 in kvm. You really 
should consider going that way in ends up way simpler :-). Maybe you 
should look over the s390 kvm port when we post it in a few weeks from 
now ;-).

Carsten

-
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] swapping with MMU Notifiers V2

2008-01-29 Thread Carsten Otte
Andrea Arcangeli wrote:
> Didn't realize s390 doesn't need those at all. Do you think
> mmu_notifier.h should also go in asm/mmu_notifier? We can always move
> them there later after merging with some compat code if needed.
No I think mmu_notifier.h is fine in include/linux. I just think kvm 
should only _use_ it on archs that do require assistence.

On s390, we use the same page table to translate host.user -> 
host.phys and guest.phys -> host.phys. Using storage keys, the host 
memory management takes into account dirty and reference operations 
done by the guest when doing it's swapping descitions. The host does 
invalidate a page table entry by using a magic "invalidate page table 
entry" instruction. Running virtual cpus are guaranteed not to rely on 
tlb data once the page table entry was invalidated by that 
instruction. Maybe we should just fix other hardware ;-).

-
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] swapping with MMU Notifiers V2

2008-01-29 Thread Carsten Otte
Andrea Arcangeli wrote:
> Well I already moved that bit to x86, at least that had a good reason
> for being moved there, it's really invisible code to s390. The memslot
> are all but invisible to s390 instead, and so the locking rules of the
> memslots should be common as long as memslots remains a common-code
> data structure too IMHO.
That makes sense to me.

-
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] swapping with MMU Notifiers V2

2008-01-29 Thread Carsten Otte
Avi Kivity wrote:
> Every arch except s390 needs it.  An ugly #ifndef 
> CONFIG_KVM_HARDWARE_TLB_SYNC is preferred to duplicating the code.
BTW, from reading AMDs spec I don't expect NPT to need this vehicle 
for swapping either. They can just let core-vm page out guest pages 
and will receive a proper page fault in the host. Jörg can you confirm 
that?


-
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] swapping with MMU Notifiers V2

2008-01-29 Thread Carsten Otte
Avi Kivity wrote:
> Every arch except s390 needs it.  An ugly #ifndef 
> CONFIG_KVM_HARDWARE_TLB_SYNC is preferred to duplicating the code.
Yea I guess you've got a point there. The struct should be in struct 
kvm, but the call to initialize/destroy it should go out to arch_init.

-
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] swapping with MMU Notifiers V2

2008-01-29 Thread Carsten Otte
Andrea Arcangeli wrote:
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index ea4764b..9349160 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -15,6 +15,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
> 
>  #include 
> @@ -118,6 +119,7 @@ struct kvm {
>   struct kvm_io_bus pio_bus;
>   struct kvm_vm_stat stat;
>   struct kvm_arch arch;
> + struct mmu_notifier mmu_notifier;
>  };
> 
>  /* The guest did something we don't support. */
This should not be in struct kvm, it should go to x86's kvm_arch. This 
is x86 specific, we don't need a notifier since the core-vm will just 
page out our guest memory like regular userspace mem.

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 8fc12dc..bb4747c 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -165,6 +165,7 @@ static struct kvm *kvm_create_vm(void)
> 
>   kvm->mm = current->mm;
>   atomic_inc(&kvm->mm->mm_count);
> + mmu_notifier_register(&kvm->mmu_notifier, kvm->mm);
>   spin_lock_init(&kvm->mmu_lock);
>   kvm_io_bus_init(&kvm->pio_bus);
>   mutex_init(&kvm->lock);
to kvm_arch_create_vm please

> @@ -1265,7 +1266,11 @@ static int kvm_resume(struct sys_device *dev)
>  }
> 
>  static struct sysdev_class kvm_sysdev_class = {
> +#ifdef set_kset_name
>   set_kset_name("kvm"),
> +#else
> + .name = "kvm",
> +#endif
>   .suspend = kvm_suspend,
>   .resume = kvm_resume,
>  };

> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 4295623..a67e38f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -298,7 +299,15 @@ int __kvm_set_memory_region(struct kvm *kvm,
>   memset(new.rmap, 0, npages * sizeof(*new.rmap));
> 
>   new.user_alloc = user_alloc;
> - new.userspace_addr = mem->userspace_addr;
> + /*
> +  * hva_to_rmmap() serialzies with the mmu_lock and to be
> +  * safe it has to ignore memslots with !user_alloc &&
> +  * !userspace_addr.
> +  */
> + if (user_alloc)
> + new.userspace_addr = mem->userspace_addr;
> + else
> + new.userspace_addr = 0;
>   }
> 
>   /* Allocate page dirty bitmap if needed */
> @@ -311,14 +320,18 @@ int __kvm_set_memory_region(struct kvm *kvm,
>   memset(new.dirty_bitmap, 0, dirty_bytes);
>   }
> 
> + spin_lock(&kvm->mmu_lock);
>   if (mem->slot >= kvm->nmemslots)
>   kvm->nmemslots = mem->slot + 1;
> 
>   *memslot = new;
> + spin_unlock(&kvm->mmu_lock);
> 
>   r = kvm_arch_set_memory_region(kvm, mem, old, user_alloc);
>   if (r) {
> + spin_lock(&kvm->mmu_lock);
>   *memslot = old;
> + spin_unlock(&kvm->mmu_lock);
>   goto out_free;
>   }
> 
> 
> 
This needs to go to arch too.

-
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


  1   2   3   4   >