Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-18 Thread Paolo Bonzini
Il 11/07/2013 12:41, Christian Borntraeger ha scritto:
 On 11/07/13 11:04, Gleb Natapov wrote:
 On Wed, Jul 10, 2013 at 02:59:55PM +0200, Dominik Dingel wrote:
 This patch enables async page faults for s390 kvm guests.
 It provides the userspace API to enable, disable or get the status of this
 feature. Also it includes the diagnose code, called by the guest to enable
 async page faults.

 The async page faults will use an already existing guest interface for this
 purpose, as described in CP Programming Services (SC24-6084).

 Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
 Christian, looks good now?
 
 Looks good, but I just had a  discussion with Dominik about several other 
 cases 
 (guest driven reboot, qemu driven reboot, life migration). This patch should 
 allow all these cases (independent from this patch we need an ioctl to flush 
 the
 list of pending interrupts to do so, but reboot is currently broken in that
 regard anyway - patch is currently being looked at)
 
 We are currently discussion if we should get rid of the APF_STATUS and let 
 the kernel wait for outstanding page faults before returning from KVM_RUN
 or if we go with this patch and let userspace wait for completion. 
 
 Will discuss this with Dominik, Conny and Alex. So lets defer that till next
 week, ok?

Let us know if we should wait for a v5. :)

Paolo

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


Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-18 Thread Christian Borntraeger
On 18/07/13 15:57, Paolo Bonzini wrote:
 Il 11/07/2013 12:41, Christian Borntraeger ha scritto:
 On 11/07/13 11:04, Gleb Natapov wrote:
 On Wed, Jul 10, 2013 at 02:59:55PM +0200, Dominik Dingel wrote:
 This patch enables async page faults for s390 kvm guests.
 It provides the userspace API to enable, disable or get the status of this
 feature. Also it includes the diagnose code, called by the guest to enable
 async page faults.

 The async page faults will use an already existing guest interface for this
 purpose, as described in CP Programming Services (SC24-6084).

 Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
 Christian, looks good now?

 Looks good, but I just had a  discussion with Dominik about several other 
 cases 
 (guest driven reboot, qemu driven reboot, life migration). This patch should 
 allow all these cases (independent from this patch we need an ioctl to flush 
 the
 list of pending interrupts to do so, but reboot is currently broken in that
 regard anyway - patch is currently being looked at)

 We are currently discussion if we should get rid of the APF_STATUS and let 
 the kernel wait for outstanding page faults before returning from KVM_RUN
 or if we go with this patch and let userspace wait for completion. 

 Will discuss this with Dominik, Conny and Alex. So lets defer that till next
 week, ok?
 
 Let us know if we should wait for a v5. :)

Yes, there will be a v5


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


Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-11 Thread Gleb Natapov
On Wed, Jul 10, 2013 at 02:59:55PM +0200, Dominik Dingel wrote:
 This patch enables async page faults for s390 kvm guests.
 It provides the userspace API to enable, disable or get the status of this
 feature. Also it includes the diagnose code, called by the guest to enable
 async page faults.
 
 The async page faults will use an already existing guest interface for this
 purpose, as described in CP Programming Services (SC24-6084).
 
 Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
Christian, looks good now?

 ---
  Documentation/s390/kvm.txt   |  24 +
  arch/s390/include/asm/kvm_host.h |  22 
  arch/s390/include/uapi/asm/kvm.h |  10 
  arch/s390/kvm/Kconfig|   2 +
  arch/s390/kvm/Makefile   |   2 +-
  arch/s390/kvm/diag.c |  63 +++
  arch/s390/kvm/interrupt.c|  43 +---
  arch/s390/kvm/kvm-s390.c | 107 
 ++-
  arch/s390/kvm/kvm-s390.h |   4 ++
  arch/s390/kvm/sigp.c |   6 +++
  include/uapi/linux/kvm.h |   2 +
  11 files changed, 276 insertions(+), 9 deletions(-)
 
 diff --git a/Documentation/s390/kvm.txt b/Documentation/s390/kvm.txt
 index 85f3280..707b7e9 100644
 --- a/Documentation/s390/kvm.txt
 +++ b/Documentation/s390/kvm.txt
 @@ -70,6 +70,30 @@ floating interrupts are:
  KVM_S390_INT_VIRTIO
  KVM_S390_INT_SERVICE
  
 +ioctl:  KVM_S390_APF_ENABLE:
 +args:   none
 +This ioctl is used to enable the async page fault interface. So in a
 +host page fault case the host can now submit pfault tokens to the guest.
 +
 +ioctl:  KVM_S390_APF_DISABLE:
 +args:   none
 +This ioctl is used to disable the async page fault interface. From this point
 +on no new pfault tokens will be issued to the guest. Already existing async
 +page faults are not covered by this and will be normally handled.
 +
 +ioctl:  KVM_S390_APF_STATUS:
 +args:   none
 +This ioctl allows the userspace to get the current status of the APF feature.
 +The main purpose for this, is to ensure that no pfault tokens will be lost
 +during live migration or similar management operations.
 +The possible return values are:
 +KVM_S390_APF_DISABLED_NON_PENDING
 +KVM_S390_APF_DISABLED_PENDING
 +KVM_S390_APF_ENABLED_NON_PENDING
 +KVM_S390_APF_ENABLED_PENDING
 +Caution: if KVM_S390_APF is enabled the PENDING status could be already 
 changed
 +as soon as the ioctl returns to userspace.
 +
  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:
 diff --git a/arch/s390/include/asm/kvm_host.h 
 b/arch/s390/include/asm/kvm_host.h
 index cd30c3d..e8012fc 100644
 --- a/arch/s390/include/asm/kvm_host.h
 +++ b/arch/s390/include/asm/kvm_host.h
 @@ -257,6 +257,10 @@ struct kvm_vcpu_arch {
   u64 stidp_data;
   };
   struct gmap *gmap;
 +#define KVM_S390_PFAULT_TOKEN_INVALID(-1UL)
 + unsigned long pfault_token;
 + unsigned long pfault_select;
 + unsigned long pfault_compare;
  };
  
  struct kvm_vm_stat {
 @@ -282,6 +286,24 @@ static inline bool kvm_is_error_hva(unsigned long addr)
   return addr == KVM_HVA_ERR_BAD;
  }
  
 +#define ASYNC_PF_PER_VCPU64
 +struct kvm_vcpu;
 +struct kvm_async_pf;
 +struct kvm_arch_async_pf {
 + unsigned long pfault_token;
 +};
 +
 +bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
 +
 +void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
 +struct kvm_async_pf *work);
 +
 +void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
 +  struct kvm_async_pf *work);
 +
 +void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
 +  struct kvm_async_pf *work);
 +
  extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  extern char sie_exit;
  #endif
 diff --git a/arch/s390/include/uapi/asm/kvm.h 
 b/arch/s390/include/uapi/asm/kvm.h
 index d25da59..b6c83e0 100644
 --- a/arch/s390/include/uapi/asm/kvm.h
 +++ b/arch/s390/include/uapi/asm/kvm.h
 @@ -57,4 +57,14 @@ struct kvm_sync_regs {
  #define KVM_REG_S390_EPOCHDIFF   (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x2)
  #define KVM_REG_S390_CPU_TIMER  (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x3)
  #define KVM_REG_S390_CLOCK_COMP (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x4)
 +
 +/* ioctls used for setting/getting status of APF on s390x */
 +#define KVM_S390_APF_ENABLE  1
 +#define KVM_S390_APF_DISABLE 2
 +#define KVM_S390_APF_STATUS  3
 +#define KVM_S390_APF_DISABLED_NON_PENDING0
 +#define KVM_S390_APF_DISABLED_PENDING1
 +#define KVM_S390_APF_ENABLED_NON_PENDING 2
 +#define KVM_S390_APF_ENABLED_PENDING 3
 +
  #endif
 diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
 index 70b46ea..4993eed 100644
 --- a/arch/s390/kvm/Kconfig
 +++ b/arch/s390/kvm/Kconfig
 @@ -23,6 +23,8 @@ config KVM
   select 

Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-11 Thread Christian Borntraeger
On 11/07/13 11:04, Gleb Natapov wrote:
 On Wed, Jul 10, 2013 at 02:59:55PM +0200, Dominik Dingel wrote:
 This patch enables async page faults for s390 kvm guests.
 It provides the userspace API to enable, disable or get the status of this
 feature. Also it includes the diagnose code, called by the guest to enable
 async page faults.

 The async page faults will use an already existing guest interface for this
 purpose, as described in CP Programming Services (SC24-6084).

 Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
 Christian, looks good now?

Looks good, but I just had a  discussion with Dominik about several other cases 
(guest driven reboot, qemu driven reboot, life migration). This patch should 
allow all these cases (independent from this patch we need an ioctl to flush the
list of pending interrupts to do so, but reboot is currently broken in that
regard anyway - patch is currently being looked at)

We are currently discussion if we should get rid of the APF_STATUS and let 
the kernel wait for outstanding page faults before returning from KVM_RUN
or if we go with this patch and let userspace wait for completion. 

Will discuss this with Dominik, Conny and Alex. So lets defer that till next
week, ok?


 
 ---
  Documentation/s390/kvm.txt   |  24 +
  arch/s390/include/asm/kvm_host.h |  22 
  arch/s390/include/uapi/asm/kvm.h |  10 
  arch/s390/kvm/Kconfig|   2 +
  arch/s390/kvm/Makefile   |   2 +-
  arch/s390/kvm/diag.c |  63 +++
  arch/s390/kvm/interrupt.c|  43 +---
  arch/s390/kvm/kvm-s390.c | 107 
 ++-
  arch/s390/kvm/kvm-s390.h |   4 ++
  arch/s390/kvm/sigp.c |   6 +++
  include/uapi/linux/kvm.h |   2 +
  11 files changed, 276 insertions(+), 9 deletions(-)

 diff --git a/Documentation/s390/kvm.txt b/Documentation/s390/kvm.txt
 index 85f3280..707b7e9 100644
 --- a/Documentation/s390/kvm.txt
 +++ b/Documentation/s390/kvm.txt
 @@ -70,6 +70,30 @@ floating interrupts are:
  KVM_S390_INT_VIRTIO
  KVM_S390_INT_SERVICE
  
 +ioctl:  KVM_S390_APF_ENABLE:
 +args:   none
 +This ioctl is used to enable the async page fault interface. So in a
 +host page fault case the host can now submit pfault tokens to the guest.
 +
 +ioctl:  KVM_S390_APF_DISABLE:
 +args:   none
 +This ioctl is used to disable the async page fault interface. From this 
 point
 +on no new pfault tokens will be issued to the guest. Already existing async
 +page faults are not covered by this and will be normally handled.
 +
 +ioctl:  KVM_S390_APF_STATUS:
 +args:   none
 +This ioctl allows the userspace to get the current status of the APF 
 feature.
 +The main purpose for this, is to ensure that no pfault tokens will be lost
 +during live migration or similar management operations.
 +The possible return values are:
 +KVM_S390_APF_DISABLED_NON_PENDING
 +KVM_S390_APF_DISABLED_PENDING
 +KVM_S390_APF_ENABLED_NON_PENDING
 +KVM_S390_APF_ENABLED_PENDING
 +Caution: if KVM_S390_APF is enabled the PENDING status could be already 
 changed
 +as soon as the ioctl returns to userspace.
 +
  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:
 diff --git a/arch/s390/include/asm/kvm_host.h 
 b/arch/s390/include/asm/kvm_host.h
 index cd30c3d..e8012fc 100644
 --- a/arch/s390/include/asm/kvm_host.h
 +++ b/arch/s390/include/asm/kvm_host.h
 @@ -257,6 +257,10 @@ struct kvm_vcpu_arch {
  u64 stidp_data;
  };
  struct gmap *gmap;
 +#define KVM_S390_PFAULT_TOKEN_INVALID   (-1UL)
 +unsigned long pfault_token;
 +unsigned long pfault_select;
 +unsigned long pfault_compare;
  };
  
  struct kvm_vm_stat {
 @@ -282,6 +286,24 @@ static inline bool kvm_is_error_hva(unsigned long addr)
  return addr == KVM_HVA_ERR_BAD;
  }
  
 +#define ASYNC_PF_PER_VCPU   64
 +struct kvm_vcpu;
 +struct kvm_async_pf;
 +struct kvm_arch_async_pf {
 +unsigned long pfault_token;
 +};
 +
 +bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
 +
 +void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
 +   struct kvm_async_pf *work);
 +
 +void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
 + struct kvm_async_pf *work);
 +
 +void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
 + struct kvm_async_pf *work);
 +
  extern int sie64a(struct kvm_s390_sie_block *, u64 *);
  extern char sie_exit;
  #endif
 diff --git a/arch/s390/include/uapi/asm/kvm.h 
 b/arch/s390/include/uapi/asm/kvm.h
 index d25da59..b6c83e0 100644
 --- a/arch/s390/include/uapi/asm/kvm.h
 +++ b/arch/s390/include/uapi/asm/kvm.h
 @@ -57,4 +57,14 @@ struct kvm_sync_regs {
  #define KVM_REG_S390_EPOCHDIFF  (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x2)
  #define 

Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-11 Thread Gleb Natapov
On Thu, Jul 11, 2013 at 12:41:37PM +0200, Christian Borntraeger wrote:
 On 11/07/13 11:04, Gleb Natapov wrote:
  On Wed, Jul 10, 2013 at 02:59:55PM +0200, Dominik Dingel wrote:
  This patch enables async page faults for s390 kvm guests.
  It provides the userspace API to enable, disable or get the status of this
  feature. Also it includes the diagnose code, called by the guest to enable
  async page faults.
 
  The async page faults will use an already existing guest interface for this
  purpose, as described in CP Programming Services (SC24-6084).
 
  Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
  Christian, looks good now?
 
 Looks good, but I just had a  discussion with Dominik about several other 
 cases 
 (guest driven reboot, qemu driven reboot, life migration). This patch should 
 allow all these cases (independent from this patch we need an ioctl to flush 
 the
 list of pending interrupts to do so, but reboot is currently broken in that
 regard anyway - patch is currently being looked at)
 
 We are currently discussion if we should get rid of the APF_STATUS and let 
 the kernel wait for outstanding page faults before returning from KVM_RUN
 or if we go with this patch and let userspace wait for completion. 
 
 Will discuss this with Dominik, Conny and Alex. So lets defer that till next
 week, ok?
 
Sure.

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


Re: [PATCH 4/4] PF: Async page fault support on s390

2013-07-10 Thread Christian Borntraeger
On 09/07/13 15:56, Dominik Dingel wrote:
 This patch enables async page faults for s390 kvm guests.
 It provides the userspace API to enable, disable or get the status of this
 feature. Also it includes the diagnose code, called by the guest to enable
 async page faults.
 
 The async page faults will use an already existing guest interface for this
 purpose, as described in CP Programming Services (SC24-6084).
 
 Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com

Re-reading this patch again, found some thing that you should take 
care of (nothing major, just small details). Sorry for not seeing them
earlier.

[...]
 + case 1: /* CANCEL */
 + if (vcpu-run-s.regs.gprs[rx]  7)
 + return kvm_s390_inject_program_int(vcpu, 
 PGM_ADDRESSING);
 +
 + vcpu-run-s.regs.gprs[ry] = 0;
 +
 + if (vcpu-arch.pfault_token == KVM_S390_PFAULT_TOKEN_INVALID)
 + vcpu-run-s.regs.gprs[ry] = 1;
 +
 + vcpu-arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
 + rc = 0;
 + break;

Dont we need a kvm_clear_async_pf_completion_queue(vcpu) or similar here as 
well?
The cancel function is supposed to purge all outstanding requests (those were 
no 
completion signal was made pending yet)

[...]
 @@ -264,6 +292,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
  {
   VCPU_EVENT(vcpu, 3, %s, free cpu);
   trace_kvm_s390_destroy_vcpu(vcpu-vcpu_id);
 + kvm_clear_async_pf_completion_queue(vcpu);
   if (!kvm_is_ucontrol(vcpu-kvm)) {
   clear_bit(63 - vcpu-vcpu_id,
 (unsigned long *) vcpu-kvm-arch.sca-mcn);
 @@ -313,6 +342,9 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
  /* Section: vcpu related */
  int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
  {
 + vcpu-arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
 + kvm_clear_async_pf_completion_queue(vcpu);
 + kvm_async_pf_wakeup_all(vcpu);
   if (kvm_is_ucontrol(vcpu-kvm)) {
   vcpu-arch.gmap = gmap_alloc(current-mm);
   if (!vcpu-arch.gmap)

We should also reset pfault handling for CPU reset, no?

 @@ -691,10 +723,75 @@ static void kvm_arch_fault_in_sync(struct kvm_vcpu 
 *vcpu)
   up_read(mm-mmap_sem);
  }
 
 +static void __kvm_inject_pfault_token(struct kvm_vcpu *vcpu, bool 
 start_token,
 +   unsigned long token)
 +{
 + struct kvm_s390_interrupt inti;
 + inti.type = start_token ? KVM_S390_INT_PFAULT_INIT :
 +   KVM_S390_INT_PFAULT_DONE;
 + inti.parm64 = token;
 + if (kvm_s390_inject_vcpu(vcpu, inti))
 + WARN(1, pfault interrupt injection failed);
 +}

The PFAULT_DONE is architectured as a floating interrupt (can happen
on other CPUs).

[...]
 --- a/arch/s390/kvm/sigp.c
 +++ b/arch/s390/kvm/sigp.c
 @@ -187,6 +187,8 @@ static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 
 parameter)
  {
   int rc;
 
 + vcpu-arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
 +

sigp set architecture affects all cpus, so we must reset pfault via
kvm_for_each_vcpu, I guess.

Otherwise patch looks good. I guess only one more iteration
Christian



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


[PATCH 4/4] PF: Async page fault support on s390

2013-07-10 Thread Dominik Dingel
This patch enables async page faults for s390 kvm guests.
It provides the userspace API to enable, disable or get the status of this
feature. Also it includes the diagnose code, called by the guest to enable
async page faults.

The async page faults will use an already existing guest interface for this
purpose, as described in CP Programming Services (SC24-6084).

Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
---
 Documentation/s390/kvm.txt   |  24 +
 arch/s390/include/asm/kvm_host.h |  22 
 arch/s390/include/uapi/asm/kvm.h |  10 
 arch/s390/kvm/Kconfig|   2 +
 arch/s390/kvm/Makefile   |   2 +-
 arch/s390/kvm/diag.c |  63 +++
 arch/s390/kvm/interrupt.c|  43 +---
 arch/s390/kvm/kvm-s390.c | 107 ++-
 arch/s390/kvm/kvm-s390.h |   4 ++
 arch/s390/kvm/sigp.c |   6 +++
 include/uapi/linux/kvm.h |   2 +
 11 files changed, 276 insertions(+), 9 deletions(-)

diff --git a/Documentation/s390/kvm.txt b/Documentation/s390/kvm.txt
index 85f3280..707b7e9 100644
--- a/Documentation/s390/kvm.txt
+++ b/Documentation/s390/kvm.txt
@@ -70,6 +70,30 @@ floating interrupts are:
 KVM_S390_INT_VIRTIO
 KVM_S390_INT_SERVICE
 
+ioctl:  KVM_S390_APF_ENABLE:
+args:   none
+This ioctl is used to enable the async page fault interface. So in a
+host page fault case the host can now submit pfault tokens to the guest.
+
+ioctl:  KVM_S390_APF_DISABLE:
+args:   none
+This ioctl is used to disable the async page fault interface. From this point
+on no new pfault tokens will be issued to the guest. Already existing async
+page faults are not covered by this and will be normally handled.
+
+ioctl:  KVM_S390_APF_STATUS:
+args:   none
+This ioctl allows the userspace to get the current status of the APF feature.
+The main purpose for this, is to ensure that no pfault tokens will be lost
+during live migration or similar management operations.
+The possible return values are:
+KVM_S390_APF_DISABLED_NON_PENDING
+KVM_S390_APF_DISABLED_PENDING
+KVM_S390_APF_ENABLED_NON_PENDING
+KVM_S390_APF_ENABLED_PENDING
+Caution: if KVM_S390_APF is enabled the PENDING status could be already changed
+as soon as the ioctl returns to userspace.
+
 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:
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index cd30c3d..e8012fc 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -257,6 +257,10 @@ struct kvm_vcpu_arch {
u64 stidp_data;
};
struct gmap *gmap;
+#define KVM_S390_PFAULT_TOKEN_INVALID  (-1UL)
+   unsigned long pfault_token;
+   unsigned long pfault_select;
+   unsigned long pfault_compare;
 };
 
 struct kvm_vm_stat {
@@ -282,6 +286,24 @@ static inline bool kvm_is_error_hva(unsigned long addr)
return addr == KVM_HVA_ERR_BAD;
 }
 
+#define ASYNC_PF_PER_VCPU  64
+struct kvm_vcpu;
+struct kvm_async_pf;
+struct kvm_arch_async_pf {
+   unsigned long pfault_token;
+};
+
+bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
+
+void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
+  struct kvm_async_pf *work);
+
+void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
+void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
 extern char sie_exit;
 #endif
diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index d25da59..b6c83e0 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -57,4 +57,14 @@ struct kvm_sync_regs {
 #define KVM_REG_S390_EPOCHDIFF (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x2)
 #define KVM_REG_S390_CPU_TIMER  (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x3)
 #define KVM_REG_S390_CLOCK_COMP (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x4)
+
+/* ioctls used for setting/getting status of APF on s390x */
+#define KVM_S390_APF_ENABLE1
+#define KVM_S390_APF_DISABLE   2
+#define KVM_S390_APF_STATUS3
+#define KVM_S390_APF_DISABLED_NON_PENDING  0
+#define KVM_S390_APF_DISABLED_PENDING  1
+#define KVM_S390_APF_ENABLED_NON_PENDING   2
+#define KVM_S390_APF_ENABLED_PENDING   3
+
 #endif
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index 70b46ea..4993eed 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -23,6 +23,8 @@ config KVM
select ANON_INODES
select HAVE_KVM_CPU_RELAX_INTERCEPT
select HAVE_KVM_EVENTFD
+   select KVM_ASYNC_PF
+   select KVM_ASYNC_PF_DIRECT
---help---
  Support hosting 

[PATCH 4/4] PF: Async page fault support on s390

2013-07-09 Thread Dominik Dingel
This patch enables async page faults for s390 kvm guests.
It provides the userspace API to enable, disable or get the status of this
feature. Also it includes the diagnose code, called by the guest to enable
async page faults.

The async page faults will use an already existing guest interface for this
purpose, as described in CP Programming Services (SC24-6084).

Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
---
 Documentation/s390/kvm.txt   |  24 ++
 arch/s390/include/asm/kvm_host.h |  22 +
 arch/s390/include/uapi/asm/kvm.h |  10 
 arch/s390/kvm/Kconfig|   2 +
 arch/s390/kvm/Makefile   |   2 +-
 arch/s390/kvm/diag.c |  57 ++
 arch/s390/kvm/interrupt.c|  38 ---
 arch/s390/kvm/kvm-s390.c | 100 ++-
 arch/s390/kvm/kvm-s390.h |   4 ++
 arch/s390/kvm/sigp.c |   2 +
 include/uapi/linux/kvm.h |   2 +
 11 files changed, 254 insertions(+), 9 deletions(-)

diff --git a/Documentation/s390/kvm.txt b/Documentation/s390/kvm.txt
index 85f3280..707b7e9 100644
--- a/Documentation/s390/kvm.txt
+++ b/Documentation/s390/kvm.txt
@@ -70,6 +70,30 @@ floating interrupts are:
 KVM_S390_INT_VIRTIO
 KVM_S390_INT_SERVICE
 
+ioctl:  KVM_S390_APF_ENABLE:
+args:   none
+This ioctl is used to enable the async page fault interface. So in a
+host page fault case the host can now submit pfault tokens to the guest.
+
+ioctl:  KVM_S390_APF_DISABLE:
+args:   none
+This ioctl is used to disable the async page fault interface. From this point
+on no new pfault tokens will be issued to the guest. Already existing async
+page faults are not covered by this and will be normally handled.
+
+ioctl:  KVM_S390_APF_STATUS:
+args:   none
+This ioctl allows the userspace to get the current status of the APF feature.
+The main purpose for this, is to ensure that no pfault tokens will be lost
+during live migration or similar management operations.
+The possible return values are:
+KVM_S390_APF_DISABLED_NON_PENDING
+KVM_S390_APF_DISABLED_PENDING
+KVM_S390_APF_ENABLED_NON_PENDING
+KVM_S390_APF_ENABLED_PENDING
+Caution: if KVM_S390_APF is enabled the PENDING status could be already changed
+as soon as the ioctl returns to userspace.
+
 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:
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 3238d40..ae75104 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -257,6 +257,10 @@ struct kvm_vcpu_arch {
u64 stidp_data;
};
struct gmap *gmap;
+#define KVM_S390_PFAULT_TOKEN_INVALID  (-1UL)
+   unsigned long pfault_token;
+   unsigned long pfault_select;
+   unsigned long pfault_compare;
 };
 
 struct kvm_vm_stat {
@@ -274,6 +278,24 @@ struct kvm_arch{
int css_support;
 };
 
+#define ASYNC_PF_PER_VCPU  64
+struct kvm_vcpu;
+struct kvm_async_pf;
+struct kvm_arch_async_pf {
+   unsigned long pfault_token;
+};
+
+bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
+
+void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
+  struct kvm_async_pf *work);
+
+void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
+void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
 extern int sie64a(struct kvm_s390_sie_block *, u64 *);
 extern char sie_exit;
 #endif
diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index d25da59..b6c83e0 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -57,4 +57,14 @@ struct kvm_sync_regs {
 #define KVM_REG_S390_EPOCHDIFF (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x2)
 #define KVM_REG_S390_CPU_TIMER  (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x3)
 #define KVM_REG_S390_CLOCK_COMP (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x4)
+
+/* ioctls used for setting/getting status of APF on s390x */
+#define KVM_S390_APF_ENABLE1
+#define KVM_S390_APF_DISABLE   2
+#define KVM_S390_APF_STATUS3
+#define KVM_S390_APF_DISABLED_NON_PENDING  0
+#define KVM_S390_APF_DISABLED_PENDING  1
+#define KVM_S390_APF_ENABLED_NON_PENDING   2
+#define KVM_S390_APF_ENABLED_PENDING   3
+
 #endif
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index 70b46ea..4993eed 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -23,6 +23,8 @@ config KVM
select ANON_INODES
select HAVE_KVM_CPU_RELAX_INTERCEPT
select HAVE_KVM_EVENTFD
+   select KVM_ASYNC_PF
+   select KVM_ASYNC_PF_DIRECT
---help---
  Support hosting paravirtualized guest machines using the SIE
  

[PATCH 4/4] PF: Async page fault support on s390

2013-07-05 Thread Dominik Dingel
This patch enables async pfage faults for s390 kvm guests.
It proviedes the userspace API to enable, disable or get the status of this
feature. Also it includes the diagnose code, called by the guest to enable
async page faults from guest point.

The async page faults will use an already existing guest interface for this
purpose, as described in CP Programming Services (SC24-6084).

Signed-off-by: Dominik Dingel din...@linux.vnet.ibm.com
---
 Documentation/s390/kvm.txt   |  24 ++
 arch/s390/include/asm/kvm_host.h |  22 +
 arch/s390/include/uapi/asm/kvm.h |  10 
 arch/s390/kvm/Kconfig|   2 +
 arch/s390/kvm/Makefile   |   2 +-
 arch/s390/kvm/diag.c |  57 ++
 arch/s390/kvm/interrupt.c|  38 ---
 arch/s390/kvm/kvm-s390.c | 100 ++-
 arch/s390/kvm/kvm-s390.h |   4 ++
 arch/s390/kvm/sigp.c |   2 +
 include/uapi/linux/kvm.h |   2 +
 11 files changed, 254 insertions(+), 9 deletions(-)

diff --git a/Documentation/s390/kvm.txt b/Documentation/s390/kvm.txt
index 85f3280..707b7e9 100644
--- a/Documentation/s390/kvm.txt
+++ b/Documentation/s390/kvm.txt
@@ -70,6 +70,30 @@ floating interrupts are:
 KVM_S390_INT_VIRTIO
 KVM_S390_INT_SERVICE
 
+ioctl:  KVM_S390_APF_ENABLE:
+args:   none
+This ioctl is used to enable the async page fault interface. So in a
+host page fault case the host can now submit pfault tokens to the guest.
+
+ioctl:  KVM_S390_APF_DISABLE:
+args:   none
+This ioctl is used to disable the async page fault interface. From this point
+on no new pfault tokens will be issued to the guest. Already existing async
+page faults are not covered by this and will be normally handled.
+
+ioctl:  KVM_S390_APF_STATUS:
+args:   none
+This ioctl allows the userspace to get the current status of the APF feature.
+The main purpose for this, is to ensure that no pfault tokens will be lost
+during live migration or similar management operations.
+The possible return values are:
+KVM_S390_APF_DISABLED_NON_PENDING
+KVM_S390_APF_DISABLED_PENDING
+KVM_S390_APF_ENABLED_NON_PENDING
+KVM_S390_APF_ENABLED_PENDING
+Caution: if KVM_S390_APF is enabled the PENDING status could be already changed
+as soon as the ioctl returns to userspace.
+
 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:
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 152..ed57362 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -257,6 +257,10 @@ struct kvm_vcpu_arch {
u64 stidp_data;
};
struct gmap *gmap;
+#define KVM_S390_PFAULT_TOKEN_INVALID  (-1UL)
+   unsigned long pfault_token;
+   unsigned long pfault_select;
+   unsigned long pfault_compare;
 };
 
 struct kvm_vm_stat {
@@ -277,6 +281,24 @@ struct kvm_arch{
 #define KVM_HVA_ERR_BAD(-1UL)
 #define KVM_HVA_ERR_RO_BAD (-1UL)
 
+#define ASYNC_PF_PER_VCPU  64
+struct kvm_vcpu;
+struct kvm_async_pf;
+struct kvm_arch_async_pf {
+   unsigned long pfault_token;
+};
+
+bool kvm_arch_can_inject_async_page_present(struct kvm_vcpu *vcpu);
+
+void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu,
+  struct kvm_async_pf *work);
+
+void kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
+void kvm_arch_async_page_present(struct kvm_vcpu *vcpu,
+struct kvm_async_pf *work);
+
 static inline bool kvm_is_error_hva(unsigned long addr)
 {
/*
diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h
index d25da59..b6c83e0 100644
--- a/arch/s390/include/uapi/asm/kvm.h
+++ b/arch/s390/include/uapi/asm/kvm.h
@@ -57,4 +57,14 @@ struct kvm_sync_regs {
 #define KVM_REG_S390_EPOCHDIFF (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x2)
 #define KVM_REG_S390_CPU_TIMER  (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x3)
 #define KVM_REG_S390_CLOCK_COMP (KVM_REG_S390 | KVM_REG_SIZE_U64 | 0x4)
+
+/* ioctls used for setting/getting status of APF on s390x */
+#define KVM_S390_APF_ENABLE1
+#define KVM_S390_APF_DISABLE   2
+#define KVM_S390_APF_STATUS3
+#define KVM_S390_APF_DISABLED_NON_PENDING  0
+#define KVM_S390_APF_DISABLED_PENDING  1
+#define KVM_S390_APF_ENABLED_NON_PENDING   2
+#define KVM_S390_APF_ENABLED_PENDING   3
+
 #endif
diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig
index 70b46ea..4993eed 100644
--- a/arch/s390/kvm/Kconfig
+++ b/arch/s390/kvm/Kconfig
@@ -23,6 +23,8 @@ config KVM
select ANON_INODES
select HAVE_KVM_CPU_RELAX_INTERCEPT
select HAVE_KVM_EVENTFD
+   select KVM_ASYNC_PF
+   select KVM_ASYNC_PF_DIRECT
---help---
  Support hosting