Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 06/17/2013 12:46 PM, Alexander Graf wrote:

On 06/17/2013 10:51 AM, Alexey Kardashevskiy wrote:

On 06/17/2013 06:40 PM, Alexander Graf wrote:

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:


On 06/17/2013 06:02 PM, Alexander Graf wrote:

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:


On 06/17/2013 08:06 AM, Alexander Graf wrote:

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:


This adds real mode handlers for the H_PUT_TCE_INDIRECT and
H_STUFF_TCE hypercalls for QEMU emulated devices such as
IBMVIO devices or emulated PCI.  These calls allow adding
multiple entries (up to 512) into the TCE table in one call
which saves time on transition to/from real mode.

This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
(copied from user and verified) before writing the whole list
into the TCE table. This cache will be utilized more in the
upcoming VFIO/IOMMU support to continue TCE list processing in
the virtual mode in the case if the real mode handler failed
for some reason.

This adds a guest physical to host real address converter and
calls the existing H_PUT_TCE handler. The converting function
is going to be fully utilized by upcoming VFIO supporting
patches.

This also implements the KVM_CAP_PPC_MULTITCE capability, so
in order to support the functionality of this patch, QEMU
needs to query for this capability and set the
"hcall-multi-tce" hypertas property only if the capability is
present, otherwise there will be serious performance
degradation.

Cc: David Gibson  Signed-off-by:
Alexey Kardashevskiy  Signed-off-by: Paul
Mackerras

Only a few minor nits. Ben already commented on implementation
details.


--- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
commit message * updated doc and moved it to another section *
changed capability number

2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
if put_indirect failed, instead we do not even start writing
to TCE table if we cannot get TCEs from the user and they are
invalid * kvmppc_emulated_h_put_tce is split to
kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
the previous item) * fixed bug with failthrough for H_IPI *
removed all get_user() from real mode handlers *
kvmppc_lookup_pte() added (instead of making lookup_linux_pte
public) --- Documentation/virtual/kvm/api.txt   |   17 ++
arch/powerpc/include/asm/kvm_host.h |2 +
arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
arch/powerpc/kvm/book3s_64_vio.c|  118 ++
arch/powerpc/kvm/book3s_64_vio_hv.c |  266
+++ arch/powerpc/kvm/book3s_hv.c
|   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
arch/powerpc/kvm/powerpc.c  |3 +
include/uapi/linux/kvm.h|1 + 10 files
changed, 473 insertions(+), 32 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt
b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
100644 --- a/Documentation/virtual/kvm/api.txt +++
b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
calls by the guest for that service will be passed to
userspace to be handled.


+4.83 KVM_CAP_PPC_MULTITCE + +Capability:
KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
capability tells the guest that multiple TCE entry add/remove
hypercalls +handling is supported by the kernel. This
significanly accelerates DMA +operations for PPC KVM guests.
+ +Unlike other capabilities in this section, this one does
not have an ioctl. +Instead, when the capability is present,
the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
handled in the host kernel and not passed to +the guest.
Othwerwise it might be better for the guest to continue using
H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of
the patches, it does not describe properly what the CAP actually
expresses. The CAP only says "this kernel is able to handle
H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly". All
other consequences are nice to document, but the semantics of
the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm<->  qemu interface. You describe some
decisions qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu
(or kvmtool could do that) just adds "hcall-multi-tce" to
"ibm,hypertas-functions" but this is for pseries linux and AIX could
always do it (no idea about it). Does it really have to be in this
file?
Ok, let's go back a step. What does this CAP describe? Don't look at 
the

description you wrote above. Just write a new one.

The CAP means the kernel is capable of handling hcalls A and B without
passing those into the user space. That accelerates DMA.



What exactly can user space expect when it finds this CAP?
The user space can expect that its handlers for A and B are not 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 06/17/2013 10:51 AM, Alexey Kardashevskiy wrote:

On 06/17/2013 06:40 PM, Alexander Graf wrote:

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:


On 06/17/2013 06:02 PM, Alexander Graf wrote:

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:


On 06/17/2013 08:06 AM, Alexander Graf wrote:

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:


This adds real mode handlers for the H_PUT_TCE_INDIRECT and
H_STUFF_TCE hypercalls for QEMU emulated devices such as
IBMVIO devices or emulated PCI.  These calls allow adding
multiple entries (up to 512) into the TCE table in one call
which saves time on transition to/from real mode.

This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
(copied from user and verified) before writing the whole list
into the TCE table. This cache will be utilized more in the
upcoming VFIO/IOMMU support to continue TCE list processing in
the virtual mode in the case if the real mode handler failed
for some reason.

This adds a guest physical to host real address converter and
calls the existing H_PUT_TCE handler. The converting function
is going to be fully utilized by upcoming VFIO supporting
patches.

This also implements the KVM_CAP_PPC_MULTITCE capability, so
in order to support the functionality of this patch, QEMU
needs to query for this capability and set the
"hcall-multi-tce" hypertas property only if the capability is
present, otherwise there will be serious performance
degradation.

Cc: David Gibson  Signed-off-by:
Alexey Kardashevskiy  Signed-off-by: Paul
Mackerras

Only a few minor nits. Ben already commented on implementation
details.


--- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
commit message * updated doc and moved it to another section *
changed capability number

2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
if put_indirect failed, instead we do not even start writing
to TCE table if we cannot get TCEs from the user and they are
invalid * kvmppc_emulated_h_put_tce is split to
kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
the previous item) * fixed bug with failthrough for H_IPI *
removed all get_user() from real mode handlers *
kvmppc_lookup_pte() added (instead of making lookup_linux_pte
public) --- Documentation/virtual/kvm/api.txt   |   17 ++
arch/powerpc/include/asm/kvm_host.h |2 +
arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
arch/powerpc/kvm/book3s_64_vio.c|  118 ++
arch/powerpc/kvm/book3s_64_vio_hv.c |  266
+++ arch/powerpc/kvm/book3s_hv.c
|   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
arch/powerpc/kvm/powerpc.c  |3 +
include/uapi/linux/kvm.h|1 + 10 files
changed, 473 insertions(+), 32 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt
b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
100644 --- a/Documentation/virtual/kvm/api.txt +++
b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
calls by the guest for that service will be passed to
userspace to be handled.


+4.83 KVM_CAP_PPC_MULTITCE + +Capability:
KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
capability tells the guest that multiple TCE entry add/remove
hypercalls +handling is supported by the kernel. This
significanly accelerates DMA +operations for PPC KVM guests.
+ +Unlike other capabilities in this section, this one does
not have an ioctl. +Instead, when the capability is present,
the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
handled in the host kernel and not passed to +the guest.
Othwerwise it might be better for the guest to continue using
H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of
the patches, it does not describe properly what the CAP actually
expresses. The CAP only says "this kernel is able to handle
H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly". All
other consequences are nice to document, but the semantics of
the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm<->  qemu interface. You describe some
decisions qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu
(or kvmtool could do that) just adds "hcall-multi-tce" to
"ibm,hypertas-functions" but this is for pseries linux and AIX could
always do it (no idea about it). Does it really have to be in this
file?

Ok, let's go back a step. What does this CAP describe? Don't look at the
description you wrote above. Just write a new one.

The CAP means the kernel is capable of handling hcalls A and B without
passing those into the user space. That accelerates DMA.



What exactly can user space expect when it finds this CAP?

The user space can expect that its handlers for A and B are not going to be
called if it configures the guest 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 06:40 PM, Alexander Graf wrote:
> 
> On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:
> 
>> On 06/17/2013 06:02 PM, Alexander Graf wrote:
>>> 
>>> On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
>>> 
 On 06/17/2013 08:06 AM, Alexander Graf wrote:
> 
> On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
> 
>> This adds real mode handlers for the H_PUT_TCE_INDIRECT and 
>> H_STUFF_TCE hypercalls for QEMU emulated devices such as
>> IBMVIO devices or emulated PCI.  These calls allow adding
>> multiple entries (up to 512) into the TCE table in one call
>> which saves time on transition to/from real mode.
>> 
>> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs 
>> (copied from user and verified) before writing the whole list
>> into the TCE table. This cache will be utilized more in the
>> upcoming VFIO/IOMMU support to continue TCE list processing in
>> the virtual mode in the case if the real mode handler failed
>> for some reason.
>> 
>> This adds a guest physical to host real address converter and
>> calls the existing H_PUT_TCE handler. The converting function 
>> is going to be fully utilized by upcoming VFIO supporting
>> patches.
>> 
>> This also implements the KVM_CAP_PPC_MULTITCE capability, so
>> in order to support the functionality of this patch, QEMU 
>> needs to query for this capability and set the
>> "hcall-multi-tce" hypertas property only if the capability is
>> present, otherwise there will be serious performance
>> degradation.
>> 
>> Cc: David Gibson  Signed-off-by:
>> Alexey Kardashevskiy  Signed-off-by: Paul
>> Mackerras 
> 
> Only a few minor nits. Ben already commented on implementation
> details.
> 
>> 
>> --- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
>> commit message * updated doc and moved it to another section *
>> changed capability number
>> 
>> 2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
>> if put_indirect failed, instead we do not even start writing
>> to TCE table if we cannot get TCEs from the user and they are 
>> invalid * kvmppc_emulated_h_put_tce is split to
>> kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
>> the previous item) * fixed bug with failthrough for H_IPI *
>> removed all get_user() from real mode handlers *
>> kvmppc_lookup_pte() added (instead of making lookup_linux_pte
>> public) --- Documentation/virtual/kvm/api.txt   |   17 ++ 
>> arch/powerpc/include/asm/kvm_host.h |2 + 
>> arch/powerpc/include/asm/kvm_ppc.h  |   16 +- 
>> arch/powerpc/kvm/book3s_64_vio.c|  118 ++ 
>> arch/powerpc/kvm/book3s_64_vio_hv.c |  266
>> +++ arch/powerpc/kvm/book3s_hv.c
>> |   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 + 
>> arch/powerpc/kvm/book3s_pr_papr.c   |   37 - 
>> arch/powerpc/kvm/powerpc.c  |3 + 
>> include/uapi/linux/kvm.h|1 + 10 files
>> changed, 473 insertions(+), 32 deletions(-)
>> 
>> diff --git a/Documentation/virtual/kvm/api.txt
>> b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
>> 100644 --- a/Documentation/virtual/kvm/api.txt +++
>> b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
>> calls by the guest for that service will be passed to
>> userspace to be handled.
>> 
>> 
>> +4.83 KVM_CAP_PPC_MULTITCE + +Capability:
>> KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
>> capability tells the guest that multiple TCE entry add/remove
>> hypercalls +handling is supported by the kernel. This
>> significanly accelerates DMA +operations for PPC KVM guests. 
>> + +Unlike other capabilities in this section, this one does
>> not have an ioctl. +Instead, when the capability is present,
>> the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
>> handled in the host kernel and not passed to +the guest.
>> Othwerwise it might be better for the guest to continue using
>> H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
>> KVM_CAP_SPAPR_TCE_IOMMU are present).
> 
 
> While this describes perfectly well what the consequences are of
> the patches, it does not describe properly what the CAP actually
> expresses. The CAP only says "this kernel is able to handle
> H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly". All
> other consequences are nice to document, but the semantics of
> the CAP are missing.
 
 
 ? It expresses ability to handle 2 hcalls. What is missing?
>>> 
>>> You don't describe the kvm <-> qemu interface. You describe some
>>> decisions qemu can take from this cap.
>> 
>> 
>> This file does not mention qemu at all. And the interface is - qemu
>> (or 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 10:37, Benjamin Herrenschmidt wrote:

> On Mon, 2013-06-17 at 17:55 +1000, Alexey Kardashevskiy wrote:
>> David:
>> ===
>> So, in the case of MULTITCE, that's not quite right.  PR KVM can
>> emulate a PAPR system on a BookE machine, and there's no reason not to
>> allow TCE acceleration as well.  We can't make it dependent on PAPR
>> mode being selected, because that's enabled per-vcpu, whereas these
>> capabilities are queried on the VM before the vcpus are created.
>> ===
>> 
>> Wrong?
> 
> The capability just tells qemu the kernel supports it, it doesn't have
> to depend on PAPR mode, qemu can sort things out no ?

Yes, this goes hand-in-hand with the documentation bit I'm trying to get 
through to Alexey atm. The CAP merely says that if in PAPR mode the kernel can 
handle hypercalls X and Y itself.

This is true for all book3s implementations as the patches stand. It is not 
true for BookE as the patches stand. Hence the CAP should be limited to book3s, 
regardless of its mode :).


Alex

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:

> On 06/17/2013 06:02 PM, Alexander Graf wrote:
>> 
>> On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
>> 
>>> On 06/17/2013 08:06 AM, Alexander Graf wrote:
 
 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
 
> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
> H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
> devices or emulated PCI.  These calls allow adding multiple entries
> (up to 512) into the TCE table in one call which saves time on
> transition to/from real mode.
> 
> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
> (copied from user and verified) before writing the whole list into
> the TCE table. This cache will be utilized more in the upcoming
> VFIO/IOMMU support to continue TCE list processing in the virtual
> mode in the case if the real mode handler failed for some reason.
> 
> This adds a guest physical to host real address converter
> and calls the existing H_PUT_TCE handler. The converting function
> is going to be fully utilized by upcoming VFIO supporting patches.
> 
> This also implements the KVM_CAP_PPC_MULTITCE capability,
> so in order to support the functionality of this patch, QEMU
> needs to query for this capability and set the "hcall-multi-tce"
> hypertas property only if the capability is present, otherwise
> there will be serious performance degradation.
> 
> Cc: David Gibson 
> Signed-off-by: Alexey Kardashevskiy 
> Signed-off-by: Paul Mackerras 
 
 Only a few minor nits. Ben already commented on implementation details.
 
> 
> ---
> Changelog:
> 2013/06/05:
> * fixed mistype about IBMVIO in the commit message
> * updated doc and moved it to another section
> * changed capability number
> 
> 2013/05/21:
> * added kvm_vcpu_arch::tce_tmp
> * removed cleanup if put_indirect failed, instead we do not even start
> writing to TCE table if we cannot get TCEs from the user and they are
> invalid
> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
> and kvmppc_emulated_validate_tce (for the previous item)
> * fixed bug with failthrough for H_IPI
> * removed all get_user() from real mode handlers
> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
> ---
> Documentation/virtual/kvm/api.txt   |   17 ++
> arch/powerpc/include/asm/kvm_host.h |2 +
> arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
> arch/powerpc/kvm/book3s_64_vio.c|  118 ++
> arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
> +++
> arch/powerpc/kvm/book3s_hv.c|   39 +
> arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
> arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
> arch/powerpc/kvm/powerpc.c  |3 +
> include/uapi/linux/kvm.h|1 +
> 10 files changed, 473 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index 5f91eda..6c082ff 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
> to userspace to be
> handled.
> 
> 
> +4.83 KVM_CAP_PPC_MULTITCE
> +
> +Capability: KVM_CAP_PPC_MULTITCE
> +Architectures: ppc
> +Type: vm
> +
> +This capability tells the guest that multiple TCE entry add/remove 
> hypercalls
> +handling is supported by the kernel. This significanly accelerates DMA
> +operations for PPC KVM guests.
> +
> +Unlike other capabilities in this section, this one does not have an 
> ioctl.
> +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
> +H_STUFF_TCE hypercalls are to be handled in the host kernel and not 
> passed to
> +the guest. Othwerwise it might be better for the guest to continue using 
> H_PUT_TCE
> +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
 
>>> 
 While this describes perfectly well what the consequences are of the
 patches, it does not describe properly what the CAP actually expresses.
 The CAP only says "this kernel is able to handle H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls directly". All other consequences are nice to
 document, but the semantics of the CAP are missing.
>>> 
>>> 
>>> ? It expresses ability to handle 2 hcalls. What is missing?
>> 
>> You don't describe the kvm <-> qemu interface. You describe some decisions 
>> qemu can take from this cap.
> 
> 
> This file does not mention qemu at all. And the interface is - qemu (or
> kvmtool could do that) just adds "hcall-multi-tce" to
> "ibm,hypertas-functions" but 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Benjamin Herrenschmidt
On Mon, 2013-06-17 at 17:55 +1000, Alexey Kardashevskiy wrote:
> David:
> ===
> So, in the case of MULTITCE, that's not quite right.  PR KVM can
> emulate a PAPR system on a BookE machine, and there's no reason not to
> allow TCE acceleration as well.  We can't make it dependent on PAPR
> mode being selected, because that's enabled per-vcpu, whereas these
> capabilities are queried on the VM before the vcpus are created.
> ===
> 
> Wrong?

The capability just tells qemu the kernel supports it, it doesn't have
to depend on PAPR mode, qemu can sort things out no ?

Cheers,
Ben.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 06:02 PM, Alexander Graf wrote:
> 
> On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
> 
>> On 06/17/2013 08:06 AM, Alexander Graf wrote:
>>>
>>> On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
>>>
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.

 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.

 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.

 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the "hcall-multi-tce"
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.

 Cc: David Gibson 
 Signed-off-by: Alexey Kardashevskiy 
 Signed-off-by: Paul Mackerras 
>>>
>>> Only a few minor nits. Ben already commented on implementation details.
>>>

 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number

 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)

 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
 to userspace to be
 handled.


 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove 
 hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an 
 ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not 
 passed to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
>>>
>>
>>> While this describes perfectly well what the consequences are of the
>>> patches, it does not describe properly what the CAP actually expresses.
>>> The CAP only says "this kernel is able to handle H_PUT_TCE_INDIRECT and
>>> H_STUFF_TCE hypercalls directly". All other consequences are nice to
>>> document, but the semantics of the CAP are missing.
>>
>>
>> ? It expresses ability to handle 2 hcalls. What is missing?
> 
> You don't describe the kvm <-> qemu interface. You describe some decisions 
> qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu (or
kvmtool could do that) just adds "hcall-multi-tce" to
"ibm,hypertas-functions" but this is for pseries linux and AIX could always
do it (no idea about it). Does it really have to be in this file?



>>> We also usually try to keep KVM behavior unchanged with regards to older

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:

> On 06/17/2013 08:06 AM, Alexander Graf wrote:
>> 
>> On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
>> 
>>> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
>>> H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
>>> devices or emulated PCI.  These calls allow adding multiple entries
>>> (up to 512) into the TCE table in one call which saves time on
>>> transition to/from real mode.
>>> 
>>> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
>>> (copied from user and verified) before writing the whole list into
>>> the TCE table. This cache will be utilized more in the upcoming
>>> VFIO/IOMMU support to continue TCE list processing in the virtual
>>> mode in the case if the real mode handler failed for some reason.
>>> 
>>> This adds a guest physical to host real address converter
>>> and calls the existing H_PUT_TCE handler. The converting function
>>> is going to be fully utilized by upcoming VFIO supporting patches.
>>> 
>>> This also implements the KVM_CAP_PPC_MULTITCE capability,
>>> so in order to support the functionality of this patch, QEMU
>>> needs to query for this capability and set the "hcall-multi-tce"
>>> hypertas property only if the capability is present, otherwise
>>> there will be serious performance degradation.
>>> 
>>> Cc: David Gibson 
>>> Signed-off-by: Alexey Kardashevskiy 
>>> Signed-off-by: Paul Mackerras 
>> 
>> Only a few minor nits. Ben already commented on implementation details.
>> 
>>> 
>>> ---
>>> Changelog:
>>> 2013/06/05:
>>> * fixed mistype about IBMVIO in the commit message
>>> * updated doc and moved it to another section
>>> * changed capability number
>>> 
>>> 2013/05/21:
>>> * added kvm_vcpu_arch::tce_tmp
>>> * removed cleanup if put_indirect failed, instead we do not even start
>>> writing to TCE table if we cannot get TCEs from the user and they are
>>> invalid
>>> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
>>> and kvmppc_emulated_validate_tce (for the previous item)
>>> * fixed bug with failthrough for H_IPI
>>> * removed all get_user() from real mode handlers
>>> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
>>> ---
>>> Documentation/virtual/kvm/api.txt   |   17 ++
>>> arch/powerpc/include/asm/kvm_host.h |2 +
>>> arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
>>> arch/powerpc/kvm/book3s_64_vio.c|  118 ++
>>> arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
>>> +++
>>> arch/powerpc/kvm/book3s_hv.c|   39 +
>>> arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
>>> arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
>>> arch/powerpc/kvm/powerpc.c  |3 +
>>> include/uapi/linux/kvm.h|1 +
>>> 10 files changed, 473 insertions(+), 32 deletions(-)
>>> 
>>> diff --git a/Documentation/virtual/kvm/api.txt 
>>> b/Documentation/virtual/kvm/api.txt
>>> index 5f91eda..6c082ff 100644
>>> --- a/Documentation/virtual/kvm/api.txt
>>> +++ b/Documentation/virtual/kvm/api.txt
>>> @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
>>> to userspace to be
>>> handled.
>>> 
>>> 
>>> +4.83 KVM_CAP_PPC_MULTITCE
>>> +
>>> +Capability: KVM_CAP_PPC_MULTITCE
>>> +Architectures: ppc
>>> +Type: vm
>>> +
>>> +This capability tells the guest that multiple TCE entry add/remove 
>>> hypercalls
>>> +handling is supported by the kernel. This significanly accelerates DMA
>>> +operations for PPC KVM guests.
>>> +
>>> +Unlike other capabilities in this section, this one does not have an ioctl.
>>> +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
>>> +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed 
>>> to
>>> +the guest. Othwerwise it might be better for the guest to continue using 
>>> H_PUT_TCE
>>> +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
>> 
> 
>> While this describes perfectly well what the consequences are of the
>> patches, it does not describe properly what the CAP actually expresses.
>> The CAP only says "this kernel is able to handle H_PUT_TCE_INDIRECT and
>> H_STUFF_TCE hypercalls directly". All other consequences are nice to
>> document, but the semantics of the CAP are missing.
> 
> 
> ? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm <-> qemu interface. You describe some decisions qemu 
can take from this cap.

> 
> 
>> We also usually try to keep KVM behavior unchanged with regards to older
>> versions until a CAP is enabled. In this case I don't think it matters
>> all that much, so I'm fine with declaring it as enabled by default.
>> Please document that this is a change in behavior versus older KVM
>> versions though.
> 
> 
> Ok!
> 
> 
>>> +
>>> +
>>> 5. The kvm_run structure
>>> 
>>> 
>>> diff --git a/arch/powerpc/include/asm/kvm_host.h 
>>> 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 08:06 AM, Alexander Graf wrote:
> 
> On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
> 
>> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
>> H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
>> devices or emulated PCI.  These calls allow adding multiple entries
>> (up to 512) into the TCE table in one call which saves time on
>> transition to/from real mode.
>>
>> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
>> (copied from user and verified) before writing the whole list into
>> the TCE table. This cache will be utilized more in the upcoming
>> VFIO/IOMMU support to continue TCE list processing in the virtual
>> mode in the case if the real mode handler failed for some reason.
>>
>> This adds a guest physical to host real address converter
>> and calls the existing H_PUT_TCE handler. The converting function
>> is going to be fully utilized by upcoming VFIO supporting patches.
>>
>> This also implements the KVM_CAP_PPC_MULTITCE capability,
>> so in order to support the functionality of this patch, QEMU
>> needs to query for this capability and set the "hcall-multi-tce"
>> hypertas property only if the capability is present, otherwise
>> there will be serious performance degradation.
>>
>> Cc: David Gibson 
>> Signed-off-by: Alexey Kardashevskiy 
>> Signed-off-by: Paul Mackerras 
> 
> Only a few minor nits. Ben already commented on implementation details.
> 
>>
>> ---
>> Changelog:
>> 2013/06/05:
>> * fixed mistype about IBMVIO in the commit message
>> * updated doc and moved it to another section
>> * changed capability number
>>
>> 2013/05/21:
>> * added kvm_vcpu_arch::tce_tmp
>> * removed cleanup if put_indirect failed, instead we do not even start
>> writing to TCE table if we cannot get TCEs from the user and they are
>> invalid
>> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
>> and kvmppc_emulated_validate_tce (for the previous item)
>> * fixed bug with failthrough for H_IPI
>> * removed all get_user() from real mode handlers
>> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
>> ---
>> Documentation/virtual/kvm/api.txt   |   17 ++
>> arch/powerpc/include/asm/kvm_host.h |2 +
>> arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
>> arch/powerpc/kvm/book3s_64_vio.c|  118 ++
>> arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
>> +++
>> arch/powerpc/kvm/book3s_hv.c|   39 +
>> arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
>> arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
>> arch/powerpc/kvm/powerpc.c  |3 +
>> include/uapi/linux/kvm.h|1 +
>> 10 files changed, 473 insertions(+), 32 deletions(-)
>>
>> diff --git a/Documentation/virtual/kvm/api.txt 
>> b/Documentation/virtual/kvm/api.txt
>> index 5f91eda..6c082ff 100644
>> --- a/Documentation/virtual/kvm/api.txt
>> +++ b/Documentation/virtual/kvm/api.txt
>> @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
>> userspace to be
>> handled.
>>
>>
>> +4.83 KVM_CAP_PPC_MULTITCE
>> +
>> +Capability: KVM_CAP_PPC_MULTITCE
>> +Architectures: ppc
>> +Type: vm
>> +
>> +This capability tells the guest that multiple TCE entry add/remove 
>> hypercalls
>> +handling is supported by the kernel. This significanly accelerates DMA
>> +operations for PPC KVM guests.
>> +
>> +Unlike other capabilities in this section, this one does not have an ioctl.
>> +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
>> +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed 
>> to
>> +the guest. Othwerwise it might be better for the guest to continue using 
>> H_PUT_TCE
>> +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
> 

> While this describes perfectly well what the consequences are of the
> patches, it does not describe properly what the CAP actually expresses.
> The CAP only says "this kernel is able to handle H_PUT_TCE_INDIRECT and
> H_STUFF_TCE hypercalls directly". All other consequences are nice to
> document, but the semantics of the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?


> We also usually try to keep KVM behavior unchanged with regards to older
> versions until a CAP is enabled. In this case I don't think it matters
> all that much, so I'm fine with declaring it as enabled by default.
> Please document that this is a change in behavior versus older KVM
> versions though.


Ok!


>> +
>> +
>> 5. The kvm_run structure
>> 
>>
>> diff --git a/arch/powerpc/include/asm/kvm_host.h 
>> b/arch/powerpc/include/asm/kvm_host.h
>> index af326cd..85d8f26 100644
>> --- a/arch/powerpc/include/asm/kvm_host.h
>> +++ b/arch/powerpc/include/asm/kvm_host.h
>> @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
>>  spinlock_t tbacct_lock;
>>  u64 busy_stolen;
>>  u64 busy_preempt;
>> +
>> +unsigned long *tce_tmp;/* 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 08:06 AM, Alexander Graf wrote:
 
 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
 
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.

 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.

 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.

 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.

 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org
 
 Only a few minor nits. Ben already commented on implementation details.
 

 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number

 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)

 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
 userspace to be
 handled.


 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove 
 hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed 
 to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
 

 While this describes perfectly well what the consequences are of the
 patches, it does not describe properly what the CAP actually expresses.
 The CAP only says this kernel is able to handle H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls directly. All other consequences are nice to
 document, but the semantics of the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?


 We also usually try to keep KVM behavior unchanged with regards to older
 versions until a CAP is enabled. In this case I don't think it matters
 all that much, so I'm fine with declaring it as enabled by default.
 Please document that this is a change in behavior versus older KVM
 versions though.


Ok!


 +
 +
 5. The kvm_run structure
 

 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index af326cd..85d8f26 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
  spinlock_t tbacct_lock;
  u64 busy_stolen;
  u64 busy_preempt;
 +
 +unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
 #endif
 };
 
 [...]


 
 [...]
 
 diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
 index 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:

 On 06/17/2013 08:06 AM, Alexander Graf wrote:
 
 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
 
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.
 
 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org
 
 Only a few minor nits. Ben already commented on implementation details.
 
 
 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number
 
 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
 to userspace to be
 handled.
 
 
 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove 
 hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed 
 to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
 
 
 While this describes perfectly well what the consequences are of the
 patches, it does not describe properly what the CAP actually expresses.
 The CAP only says this kernel is able to handle H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls directly. All other consequences are nice to
 document, but the semantics of the CAP are missing.
 
 
 ? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm - qemu interface. You describe some decisions qemu 
can take from this cap.

 
 
 We also usually try to keep KVM behavior unchanged with regards to older
 versions until a CAP is enabled. In this case I don't think it matters
 all that much, so I'm fine with declaring it as enabled by default.
 Please document that this is a change in behavior versus older KVM
 versions though.
 
 
 Ok!
 
 
 +
 +
 5. The kvm_run structure
 
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index af326cd..85d8f26 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
 spinlock_t tbacct_lock;
 u64 busy_stolen;
 u64 busy_preempt;
 +
 +   unsigned long 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 06:02 PM, Alexander Graf wrote:
 
 On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
 
 On 06/17/2013 08:06 AM, Alexander Graf wrote:

 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:

 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.

 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.

 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.

 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.

 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org

 Only a few minor nits. Ben already commented on implementation details.


 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number

 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)

 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
 to userspace to be
 handled.


 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove 
 hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an 
 ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not 
 passed to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).


 While this describes perfectly well what the consequences are of the
 patches, it does not describe properly what the CAP actually expresses.
 The CAP only says this kernel is able to handle H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls directly. All other consequences are nice to
 document, but the semantics of the CAP are missing.


 ? It expresses ability to handle 2 hcalls. What is missing?
 
 You don't describe the kvm - qemu interface. You describe some decisions 
 qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu (or
kvmtool could do that) just adds hcall-multi-tce to
ibm,hypertas-functions but this is for pseries linux and AIX could always
do it (no idea about it). Does it really have to be in this file?



 We also usually try to keep KVM behavior unchanged with regards to older
 versions until a CAP is enabled. In this case I don't think it matters
 all that much, so I'm fine with declaring it as enabled by default.
 Please document that this is a change in behavior versus older KVM
 versions though.


 Ok!


 +
 +
 5. The kvm_run structure
 

 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Benjamin Herrenschmidt
On Mon, 2013-06-17 at 17:55 +1000, Alexey Kardashevskiy wrote:
 David:
 ===
 So, in the case of MULTITCE, that's not quite right.  PR KVM can
 emulate a PAPR system on a BookE machine, and there's no reason not to
 allow TCE acceleration as well.  We can't make it dependent on PAPR
 mode being selected, because that's enabled per-vcpu, whereas these
 capabilities are queried on the VM before the vcpus are created.
 ===
 
 Wrong?

The capability just tells qemu the kernel supports it, it doesn't have
to depend on PAPR mode, qemu can sort things out no ?

Cheers,
Ben.


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:

 On 06/17/2013 06:02 PM, Alexander Graf wrote:
 
 On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
 
 On 06/17/2013 08:06 AM, Alexander Graf wrote:
 
 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
 
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.
 
 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org
 
 Only a few minor nits. Ben already commented on implementation details.
 
 
 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number
 
 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed 
 to userspace to be
 handled.
 
 
 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove 
 hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an 
 ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not 
 passed to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
 
 
 While this describes perfectly well what the consequences are of the
 patches, it does not describe properly what the CAP actually expresses.
 The CAP only says this kernel is able to handle H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls directly. All other consequences are nice to
 document, but the semantics of the CAP are missing.
 
 
 ? It expresses ability to handle 2 hcalls. What is missing?
 
 You don't describe the kvm - qemu interface. You describe some decisions 
 qemu can take from this cap.
 
 
 This file does not mention qemu at all. And the interface is - qemu (or
 kvmtool could do that) just adds hcall-multi-tce to
 ibm,hypertas-functions but this is for pseries linux and AIX could always
 do it (no idea about it). Does it really have to be in this file?

Ok, let's go back a step. What does this CAP describe? Don't look at the 
description you wrote above. Just write a new one. What exactly can user space 
expect when it finds this CAP?

 
 
 
 We also usually try to keep KVM behavior unchanged with regards to older
 versions until a CAP is enabled. In this case I don't think it matters
 all that 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 17.06.2013, at 10:37, Benjamin Herrenschmidt wrote:

 On Mon, 2013-06-17 at 17:55 +1000, Alexey Kardashevskiy wrote:
 David:
 ===
 So, in the case of MULTITCE, that's not quite right.  PR KVM can
 emulate a PAPR system on a BookE machine, and there's no reason not to
 allow TCE acceleration as well.  We can't make it dependent on PAPR
 mode being selected, because that's enabled per-vcpu, whereas these
 capabilities are queried on the VM before the vcpus are created.
 ===
 
 Wrong?
 
 The capability just tells qemu the kernel supports it, it doesn't have
 to depend on PAPR mode, qemu can sort things out no ?

Yes, this goes hand-in-hand with the documentation bit I'm trying to get 
through to Alexey atm. The CAP merely says that if in PAPR mode the kernel can 
handle hypercalls X and Y itself.

This is true for all book3s implementations as the patches stand. It is not 
true for BookE as the patches stand. Hence the CAP should be limited to book3s, 
regardless of its mode :).


Alex

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexey Kardashevskiy
On 06/17/2013 06:40 PM, Alexander Graf wrote:
 
 On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:
 
 On 06/17/2013 06:02 PM, Alexander Graf wrote:
 
 On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:
 
 On 06/17/2013 08:06 AM, Alexander Graf wrote:
 
 On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:
 
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and 
 H_STUFF_TCE hypercalls for QEMU emulated devices such as
 IBMVIO devices or emulated PCI.  These calls allow adding
 multiple entries (up to 512) into the TCE table in one call
 which saves time on transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs 
 (copied from user and verified) before writing the whole list
 into the TCE table. This cache will be utilized more in the
 upcoming VFIO/IOMMU support to continue TCE list processing in
 the virtual mode in the case if the real mode handler failed
 for some reason.
 
 This adds a guest physical to host real address converter and
 calls the existing H_PUT_TCE handler. The converting function 
 is going to be fully utilized by upcoming VFIO supporting
 patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability, so
 in order to support the functionality of this patch, QEMU 
 needs to query for this capability and set the
 hcall-multi-tce hypertas property only if the capability is
 present, otherwise there will be serious performance
 degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au Signed-off-by:
 Alexey Kardashevskiy a...@ozlabs.ru Signed-off-by: Paul
 Mackerras pau...@samba.org
 
 Only a few minor nits. Ben already commented on implementation
 details.
 
 
 --- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
 commit message * updated doc and moved it to another section *
 changed capability number
 
 2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
 if put_indirect failed, instead we do not even start writing
 to TCE table if we cannot get TCEs from the user and they are 
 invalid * kvmppc_emulated_h_put_tce is split to
 kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
 the previous item) * fixed bug with failthrough for H_IPI *
 removed all get_user() from real mode handlers *
 kvmppc_lookup_pte() added (instead of making lookup_linux_pte
 public) --- Documentation/virtual/kvm/api.txt   |   17 ++ 
 arch/powerpc/include/asm/kvm_host.h |2 + 
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +- 
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++ 
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266
 +++ arch/powerpc/kvm/book3s_hv.c
 |   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 + 
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 - 
 arch/powerpc/kvm/powerpc.c  |3 + 
 include/uapi/linux/kvm.h|1 + 10 files
 changed, 473 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt
 b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
 100644 --- a/Documentation/virtual/kvm/api.txt +++
 b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
 calls by the guest for that service will be passed to
 userspace to be handled.
 
 
 +4.83 KVM_CAP_PPC_MULTITCE + +Capability:
 KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
 capability tells the guest that multiple TCE entry add/remove
 hypercalls +handling is supported by the kernel. This
 significanly accelerates DMA +operations for PPC KVM guests. 
 + +Unlike other capabilities in this section, this one does
 not have an ioctl. +Instead, when the capability is present,
 the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
 handled in the host kernel and not passed to +the guest.
 Othwerwise it might be better for the guest to continue using
 H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
 KVM_CAP_SPAPR_TCE_IOMMU are present).
 
 
 While this describes perfectly well what the consequences are of
 the patches, it does not describe properly what the CAP actually
 expresses. The CAP only says this kernel is able to handle
 H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly. All
 other consequences are nice to document, but the semantics of
 the CAP are missing.
 
 
 ? It expresses ability to handle 2 hcalls. What is missing?
 
 You don't describe the kvm - qemu interface. You describe some
 decisions qemu can take from this cap.
 
 
 This file does not mention qemu at all. And the interface is - qemu
 (or kvmtool could do that) just adds hcall-multi-tce to 
 ibm,hypertas-functions but this is for pseries linux and AIX could
 always do it (no idea about it). Does it really have to be in this
 file?
 

 Ok, let's go back a step. What does this CAP describe? Don't look at the
 description you wrote above. Just write a new one.

The CAP means the kernel is capable of handling hcalls A and B without
passing those into the user space. That accelerates DMA.


 What exactly can user space expect when it finds this 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 06/17/2013 10:51 AM, Alexey Kardashevskiy wrote:

On 06/17/2013 06:40 PM, Alexander Graf wrote:

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:


On 06/17/2013 06:02 PM, Alexander Graf wrote:

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:


On 06/17/2013 08:06 AM, Alexander Graf wrote:

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:


This adds real mode handlers for the H_PUT_TCE_INDIRECT and
H_STUFF_TCE hypercalls for QEMU emulated devices such as
IBMVIO devices or emulated PCI.  These calls allow adding
multiple entries (up to 512) into the TCE table in one call
which saves time on transition to/from real mode.

This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
(copied from user and verified) before writing the whole list
into the TCE table. This cache will be utilized more in the
upcoming VFIO/IOMMU support to continue TCE list processing in
the virtual mode in the case if the real mode handler failed
for some reason.

This adds a guest physical to host real address converter and
calls the existing H_PUT_TCE handler. The converting function
is going to be fully utilized by upcoming VFIO supporting
patches.

This also implements the KVM_CAP_PPC_MULTITCE capability, so
in order to support the functionality of this patch, QEMU
needs to query for this capability and set the
hcall-multi-tce hypertas property only if the capability is
present, otherwise there will be serious performance
degradation.

Cc: David Gibsonda...@gibson.dropbear.id.au  Signed-off-by:
Alexey Kardashevskiya...@ozlabs.ru  Signed-off-by: Paul
Mackerraspau...@samba.org

Only a few minor nits. Ben already commented on implementation
details.


--- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
commit message * updated doc and moved it to another section *
changed capability number

2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
if put_indirect failed, instead we do not even start writing
to TCE table if we cannot get TCEs from the user and they are
invalid * kvmppc_emulated_h_put_tce is split to
kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
the previous item) * fixed bug with failthrough for H_IPI *
removed all get_user() from real mode handlers *
kvmppc_lookup_pte() added (instead of making lookup_linux_pte
public) --- Documentation/virtual/kvm/api.txt   |   17 ++
arch/powerpc/include/asm/kvm_host.h |2 +
arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
arch/powerpc/kvm/book3s_64_vio.c|  118 ++
arch/powerpc/kvm/book3s_64_vio_hv.c |  266
+++ arch/powerpc/kvm/book3s_hv.c
|   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
arch/powerpc/kvm/powerpc.c  |3 +
include/uapi/linux/kvm.h|1 + 10 files
changed, 473 insertions(+), 32 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt
b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
100644 --- a/Documentation/virtual/kvm/api.txt +++
b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
calls by the guest for that service will be passed to
userspace to be handled.


+4.83 KVM_CAP_PPC_MULTITCE + +Capability:
KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
capability tells the guest that multiple TCE entry add/remove
hypercalls +handling is supported by the kernel. This
significanly accelerates DMA +operations for PPC KVM guests.
+ +Unlike other capabilities in this section, this one does
not have an ioctl. +Instead, when the capability is present,
the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
handled in the host kernel and not passed to +the guest.
Othwerwise it might be better for the guest to continue using
H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of
the patches, it does not describe properly what the CAP actually
expresses. The CAP only says this kernel is able to handle
H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly. All
other consequences are nice to document, but the semantics of
the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm-  qemu interface. You describe some
decisions qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu
(or kvmtool could do that) just adds hcall-multi-tce to
ibm,hypertas-functions but this is for pseries linux and AIX could
always do it (no idea about it). Does it really have to be in this
file?

Ok, let's go back a step. What does this CAP describe? Don't look at the
description you wrote above. Just write a new one.

The CAP means the kernel is capable of handling hcalls A and B without
passing those into the user space. That accelerates DMA.



What exactly can user space expect when it finds this CAP?

The user space can expect that its handlers for A and B are not 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-17 Thread Alexander Graf

On 06/17/2013 12:46 PM, Alexander Graf wrote:

On 06/17/2013 10:51 AM, Alexey Kardashevskiy wrote:

On 06/17/2013 06:40 PM, Alexander Graf wrote:

On 17.06.2013, at 10:34, Alexey Kardashevskiy wrote:


On 06/17/2013 06:02 PM, Alexander Graf wrote:

On 17.06.2013, at 09:55, Alexey Kardashevskiy wrote:


On 06/17/2013 08:06 AM, Alexander Graf wrote:

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:


This adds real mode handlers for the H_PUT_TCE_INDIRECT and
H_STUFF_TCE hypercalls for QEMU emulated devices such as
IBMVIO devices or emulated PCI.  These calls allow adding
multiple entries (up to 512) into the TCE table in one call
which saves time on transition to/from real mode.

This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
(copied from user and verified) before writing the whole list
into the TCE table. This cache will be utilized more in the
upcoming VFIO/IOMMU support to continue TCE list processing in
the virtual mode in the case if the real mode handler failed
for some reason.

This adds a guest physical to host real address converter and
calls the existing H_PUT_TCE handler. The converting function
is going to be fully utilized by upcoming VFIO supporting
patches.

This also implements the KVM_CAP_PPC_MULTITCE capability, so
in order to support the functionality of this patch, QEMU
needs to query for this capability and set the
hcall-multi-tce hypertas property only if the capability is
present, otherwise there will be serious performance
degradation.

Cc: David Gibsonda...@gibson.dropbear.id.au  Signed-off-by:
Alexey Kardashevskiya...@ozlabs.ru  Signed-off-by: Paul
Mackerraspau...@samba.org

Only a few minor nits. Ben already commented on implementation
details.


--- Changelog: 2013/06/05: * fixed mistype about IBMVIO in the
commit message * updated doc and moved it to another section *
changed capability number

2013/05/21: * added kvm_vcpu_arch::tce_tmp * removed cleanup
if put_indirect failed, instead we do not even start writing
to TCE table if we cannot get TCEs from the user and they are
invalid * kvmppc_emulated_h_put_tce is split to
kvmppc_emulated_put_tce and kvmppc_emulated_validate_tce (for
the previous item) * fixed bug with failthrough for H_IPI *
removed all get_user() from real mode handlers *
kvmppc_lookup_pte() added (instead of making lookup_linux_pte
public) --- Documentation/virtual/kvm/api.txt   |   17 ++
arch/powerpc/include/asm/kvm_host.h |2 +
arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
arch/powerpc/kvm/book3s_64_vio.c|  118 ++
arch/powerpc/kvm/book3s_64_vio_hv.c |  266
+++ arch/powerpc/kvm/book3s_hv.c
|   39 + arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
arch/powerpc/kvm/powerpc.c  |3 +
include/uapi/linux/kvm.h|1 + 10 files
changed, 473 insertions(+), 32 deletions(-)

diff --git a/Documentation/virtual/kvm/api.txt
b/Documentation/virtual/kvm/api.txt index 5f91eda..6c082ff
100644 --- a/Documentation/virtual/kvm/api.txt +++
b/Documentation/virtual/kvm/api.txt @@ -2362,6 +2362,23 @@
calls by the guest for that service will be passed to
userspace to be handled.


+4.83 KVM_CAP_PPC_MULTITCE + +Capability:
KVM_CAP_PPC_MULTITCE +Architectures: ppc +Type: vm + +This
capability tells the guest that multiple TCE entry add/remove
hypercalls +handling is supported by the kernel. This
significanly accelerates DMA +operations for PPC KVM guests.
+ +Unlike other capabilities in this section, this one does
not have an ioctl. +Instead, when the capability is present,
the H_PUT_TCE_INDIRECT and +H_STUFF_TCE hypercalls are to be
handled in the host kernel and not passed to +the guest.
Othwerwise it might be better for the guest to continue using
H_PUT_TCE +hypercall (if KVM_CAP_SPAPR_TCE or
KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of
the patches, it does not describe properly what the CAP actually
expresses. The CAP only says this kernel is able to handle
H_PUT_TCE_INDIRECT and H_STUFF_TCE hypercalls directly. All
other consequences are nice to document, but the semantics of
the CAP are missing.


? It expresses ability to handle 2 hcalls. What is missing?

You don't describe the kvm-  qemu interface. You describe some
decisions qemu can take from this cap.


This file does not mention qemu at all. And the interface is - qemu
(or kvmtool could do that) just adds hcall-multi-tce to
ibm,hypertas-functions but this is for pseries linux and AIX could
always do it (no idea about it). Does it really have to be in this
file?
Ok, let's go back a step. What does this CAP describe? Don't look at 
the

description you wrote above. Just write a new one.

The CAP means the kernel is capable of handling hcalls A and B without
passing those into the user space. That accelerates DMA.



What exactly can user space expect when it finds this CAP?
The user space can 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-16 Thread Alexander Graf

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:

> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
> H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
> devices or emulated PCI.  These calls allow adding multiple entries
> (up to 512) into the TCE table in one call which saves time on
> transition to/from real mode.
> 
> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
> (copied from user and verified) before writing the whole list into
> the TCE table. This cache will be utilized more in the upcoming
> VFIO/IOMMU support to continue TCE list processing in the virtual
> mode in the case if the real mode handler failed for some reason.
> 
> This adds a guest physical to host real address converter
> and calls the existing H_PUT_TCE handler. The converting function
> is going to be fully utilized by upcoming VFIO supporting patches.
> 
> This also implements the KVM_CAP_PPC_MULTITCE capability,
> so in order to support the functionality of this patch, QEMU
> needs to query for this capability and set the "hcall-multi-tce"
> hypertas property only if the capability is present, otherwise
> there will be serious performance degradation.
> 
> Cc: David Gibson 
> Signed-off-by: Alexey Kardashevskiy 
> Signed-off-by: Paul Mackerras 

Only a few minor nits. Ben already commented on implementation details.

> 
> ---
> Changelog:
> 2013/06/05:
> * fixed mistype about IBMVIO in the commit message
> * updated doc and moved it to another section
> * changed capability number
> 
> 2013/05/21:
> * added kvm_vcpu_arch::tce_tmp
> * removed cleanup if put_indirect failed, instead we do not even start
> writing to TCE table if we cannot get TCEs from the user and they are
> invalid
> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
> and kvmppc_emulated_validate_tce (for the previous item)
> * fixed bug with failthrough for H_IPI
> * removed all get_user() from real mode handlers
> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
> ---
> Documentation/virtual/kvm/api.txt   |   17 ++
> arch/powerpc/include/asm/kvm_host.h |2 +
> arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
> arch/powerpc/kvm/book3s_64_vio.c|  118 ++
> arch/powerpc/kvm/book3s_64_vio_hv.c |  266 +++
> arch/powerpc/kvm/book3s_hv.c|   39 +
> arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
> arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
> arch/powerpc/kvm/powerpc.c  |3 +
> include/uapi/linux/kvm.h|1 +
> 10 files changed, 473 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index 5f91eda..6c082ff 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
> userspace to be
> handled.
> 
> 
> +4.83 KVM_CAP_PPC_MULTITCE
> +
> +Capability: KVM_CAP_PPC_MULTITCE
> +Architectures: ppc
> +Type: vm
> +
> +This capability tells the guest that multiple TCE entry add/remove hypercalls
> +handling is supported by the kernel. This significanly accelerates DMA
> +operations for PPC KVM guests.
> +
> +Unlike other capabilities in this section, this one does not have an ioctl.
> +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
> +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed to
> +the guest. Othwerwise it might be better for the guest to continue using 
> H_PUT_TCE
> +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of the patches, 
it does not describe properly what the CAP actually expresses. The CAP only 
says "this kernel is able to handle H_PUT_TCE_INDIRECT and H_STUFF_TCE 
hypercalls directly". All other consequences are nice to document, but the 
semantics of the CAP are missing.

We also usually try to keep KVM behavior unchanged with regards to older 
versions until a CAP is enabled. In this case I don't think it matters all that 
much, so I'm fine with declaring it as enabled by default. Please document that 
this is a change in behavior versus older KVM versions though.

> +
> +
> 5. The kvm_run structure
> 
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index af326cd..85d8f26 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
>   spinlock_t tbacct_lock;
>   u64 busy_stolen;
>   u64 busy_preempt;
> +
> + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
> #endif
> };

[...]
> 
> 

[...]

> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 550f592..a39039a 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-16 Thread Alexander Graf

On 05.06.2013, at 08:11, Alexey Kardashevskiy wrote:

 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.
 
 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org

Only a few minor nits. Ben already commented on implementation details.

 
 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number
 
 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
 Documentation/virtual/kvm/api.txt   |   17 ++
 arch/powerpc/include/asm/kvm_host.h |2 +
 arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
 arch/powerpc/kvm/book3s_64_vio.c|  118 ++
 arch/powerpc/kvm/book3s_64_vio_hv.c |  266 +++
 arch/powerpc/kvm/book3s_hv.c|   39 +
 arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
 arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
 arch/powerpc/kvm/powerpc.c  |3 +
 include/uapi/linux/kvm.h|1 +
 10 files changed, 473 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
 userspace to be
 handled.
 
 
 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).

While this describes perfectly well what the consequences are of the patches, 
it does not describe properly what the CAP actually expresses. The CAP only 
says this kernel is able to handle H_PUT_TCE_INDIRECT and H_STUFF_TCE 
hypercalls directly. All other consequences are nice to document, but the 
semantics of the CAP are missing.

We also usually try to keep KVM behavior unchanged with regards to older 
versions until a CAP is enabled. In this case I don't think it matters all that 
much, so I'm fine with declaring it as enabled by default. Please document that 
this is a change in behavior versus older KVM versions though.

 +
 +
 5. The kvm_run structure
 
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index af326cd..85d8f26 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
   spinlock_t tbacct_lock;
   u64 busy_stolen;
   u64 busy_preempt;
 +
 + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
 #endif
 };

[...]
 
 

[...]

 diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
 index 550f592..a39039a 100644
 --- a/arch/powerpc/kvm/book3s_hv.c
 +++ b/arch/powerpc/kvm/book3s_hv.c
 @@ -568,6 +568,30 @@ int 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-15 Thread Benjamin Herrenschmidt
On Wed, 2013-06-05 at 16:11 +1000, Alexey Kardashevskiy wrote:
> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
> H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
> devices or emulated PCI.  These calls allow adding multiple entries
> (up to 512) into the TCE table in one call which saves time on
> transition to/from real mode.
> 
> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
> (copied from user and verified) before writing the whole list into
> the TCE table. This cache will be utilized more in the upcoming
> VFIO/IOMMU support to continue TCE list processing in the virtual
> mode in the case if the real mode handler failed for some reason.
> 
> This adds a guest physical to host real address converter
> and calls the existing H_PUT_TCE handler. The converting function
> is going to be fully utilized by upcoming VFIO supporting patches.
> 
> This also implements the KVM_CAP_PPC_MULTITCE capability,
> so in order to support the functionality of this patch, QEMU
> needs to query for this capability and set the "hcall-multi-tce"
> hypertas property only if the capability is present, otherwise
> there will be serious performance degradation.
> 
> Cc: David Gibson 
> Signed-off-by: Alexey Kardashevskiy 
> Signed-off-by: Paul Mackerras 
> 
> ---
> Changelog:
> 2013/06/05:
> * fixed mistype about IBMVIO in the commit message
> * updated doc and moved it to another section
> * changed capability number
> 
> 2013/05/21:
> * added kvm_vcpu_arch::tce_tmp
> * removed cleanup if put_indirect failed, instead we do not even start
> writing to TCE table if we cannot get TCEs from the user and they are
> invalid
> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
> and kvmppc_emulated_validate_tce (for the previous item)
> * fixed bug with failthrough for H_IPI
> * removed all get_user() from real mode handlers
> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
> ---
>  Documentation/virtual/kvm/api.txt   |   17 ++
>  arch/powerpc/include/asm/kvm_host.h |2 +
>  arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
>  arch/powerpc/kvm/book3s_64_vio.c|  118 ++
>  arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
> +++
>  arch/powerpc/kvm/book3s_hv.c|   39 +
>  arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
>  arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
>  arch/powerpc/kvm/powerpc.c  |3 +
>  include/uapi/linux/kvm.h|1 +
>  10 files changed, 473 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index 5f91eda..6c082ff 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
> userspace to be
>  handled.
>  
> 
> +4.83 KVM_CAP_PPC_MULTITCE
> +
> +Capability: KVM_CAP_PPC_MULTITCE
> +Architectures: ppc
> +Type: vm
> +
> +This capability tells the guest that multiple TCE entry add/remove hypercalls
> +handling is supported by the kernel. This significanly accelerates DMA
> +operations for PPC KVM guests.
> +
> +Unlike other capabilities in this section, this one does not have an ioctl.
> +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
> +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed to
> +the guest. Othwerwise it might be better for the guest to continue using 
> H_PUT_TCE
> +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
> +
> +
>  5. The kvm_run structure
>  
>  
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index af326cd..85d8f26 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
>   spinlock_t tbacct_lock;
>   u64 busy_stolen;
>   u64 busy_preempt;
> +
> + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
>  #endif
>  };
>  
> diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> b/arch/powerpc/include/asm/kvm_ppc.h
> index a5287fe..e852921b 100644
> --- a/arch/powerpc/include/asm/kvm_ppc.h
> +++ b/arch/powerpc/include/asm/kvm_ppc.h
> @@ -133,8 +133,20 @@ extern int kvmppc_pseries_do_hcall(struct kvm_vcpu 
> *vcpu);
>  
>  extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
>   struct kvm_create_spapr_tce *args);
> -extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
> -  unsigned long ioba, unsigned long tce);
> +extern struct kvmppc_spapr_tce_table *kvmppc_find_tce_table(
> + struct kvm_vcpu *vcpu, unsigned long liobn);
> +extern long kvmppc_emulated_validate_tce(unsigned long tce);
> +extern void kvmppc_emulated_put_tce(struct kvmppc_spapr_tce_table *tt,
> + unsigned long 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-06-15 Thread Benjamin Herrenschmidt
On Wed, 2013-06-05 at 16:11 +1000, Alexey Kardashevskiy wrote:
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as IBMVIO
 devices or emulated PCI.  These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.
 
 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org
 
 ---
 Changelog:
 2013/06/05:
 * fixed mistype about IBMVIO in the commit message
 * updated doc and moved it to another section
 * changed capability number
 
 2013/05/21:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
  Documentation/virtual/kvm/api.txt   |   17 ++
  arch/powerpc/include/asm/kvm_host.h |2 +
  arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
  arch/powerpc/kvm/book3s_64_vio.c|  118 ++
  arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
  arch/powerpc/kvm/book3s_hv.c|   39 +
  arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
  arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
  arch/powerpc/kvm/powerpc.c  |3 +
  include/uapi/linux/kvm.h|1 +
  10 files changed, 473 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..6c082ff 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2362,6 +2362,23 @@ calls by the guest for that service will be passed to 
 userspace to be
  handled.
  
 
 +4.83 KVM_CAP_PPC_MULTITCE
 +
 +Capability: KVM_CAP_PPC_MULTITCE
 +Architectures: ppc
 +Type: vm
 +
 +This capability tells the guest that multiple TCE entry add/remove hypercalls
 +handling is supported by the kernel. This significanly accelerates DMA
 +operations for PPC KVM guests.
 +
 +Unlike other capabilities in this section, this one does not have an ioctl.
 +Instead, when the capability is present, the H_PUT_TCE_INDIRECT and
 +H_STUFF_TCE hypercalls are to be handled in the host kernel and not passed to
 +the guest. Othwerwise it might be better for the guest to continue using 
 H_PUT_TCE
 +hypercall (if KVM_CAP_SPAPR_TCE or KVM_CAP_SPAPR_TCE_IOMMU are present).
 +
 +
  5. The kvm_run structure
  
  
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index af326cd..85d8f26 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
   spinlock_t tbacct_lock;
   u64 busy_stolen;
   u64 busy_preempt;
 +
 + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
  #endif
  };
  
 diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
 b/arch/powerpc/include/asm/kvm_ppc.h
 index a5287fe..e852921b 100644
 --- a/arch/powerpc/include/asm/kvm_ppc.h
 +++ b/arch/powerpc/include/asm/kvm_ppc.h
 @@ -133,8 +133,20 @@ extern int kvmppc_pseries_do_hcall(struct kvm_vcpu 
 *vcpu);
  
  extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
   struct kvm_create_spapr_tce *args);
 -extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
 -  unsigned long ioba, unsigned long tce);
 +extern struct kvmppc_spapr_tce_table *kvmppc_find_tce_table(
 + struct kvm_vcpu *vcpu, unsigned long liobn);
 +extern long kvmppc_emulated_validate_tce(unsigned long tce);
 +extern void kvmppc_emulated_put_tce(struct kvmppc_spapr_tce_table *tt,
 + unsigned long ioba, unsigned long tce);
 +extern long 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-05-27 Thread Alexey Kardashevskiy
On 05/27/2013 08:08 PM, Paolo Bonzini wrote:
> Il 21/05/2013 05:06, Alexey Kardashevskiy ha scritto:
>> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
>> H_STUFF_TCE hypercalls for QEMU emulated devices such as virtio
>> devices or emulated PCI.
> 
> Do you mean vio?  virtio (without getting into whether that's good or
> bad) will bypass the iommu.

yes, mistake, should be VIO. thanks!


-- 
Alexey
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-05-27 Thread Paolo Bonzini
Il 21/05/2013 05:06, Alexey Kardashevskiy ha scritto:
> This adds real mode handlers for the H_PUT_TCE_INDIRECT and
> H_STUFF_TCE hypercalls for QEMU emulated devices such as virtio
> devices or emulated PCI.

Do you mean vio?  virtio (without getting into whether that's good or
bad) will bypass the iommu.

Paolo

> These calls allow adding multiple entries
> (up to 512) into the TCE table in one call which saves time on
> transition to/from real mode.
> 
> This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
> (copied from user and verified) before writing the whole list into
> the TCE table. This cache will be utilized more in the upcoming
> VFIO/IOMMU support to continue TCE list processing in the virtual
> mode in the case if the real mode handler failed for some reason.
> 
> This adds a guest physical to host real address converter
> and calls the existing H_PUT_TCE handler. The converting function
> is going to be fully utilized by upcoming VFIO supporting patches.
> 
> This also implements the KVM_CAP_PPC_MULTITCE capability,
> so in order to support the functionality of this patch, QEMU
> needs to query for this capability and set the "hcall-multi-tce"
> hypertas property only if the capability is present, otherwise
> there will be serious performance degradation.
> 
> Cc: David Gibson 
> Signed-off-by: Alexey Kardashevskiy 
> Signed-off-by: Paul Mackerras 
> 
> ---
> Changelog:
> * added kvm_vcpu_arch::tce_tmp
> * removed cleanup if put_indirect failed, instead we do not even start
> writing to TCE table if we cannot get TCEs from the user and they are
> invalid
> * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
> and kvmppc_emulated_validate_tce (for the previous item)
> * fixed bug with failthrough for H_IPI
> * removed all get_user() from real mode handlers
> * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
> ---
>  Documentation/virtual/kvm/api.txt   |   14 ++
>  arch/powerpc/include/asm/kvm_host.h |2 +
>  arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
>  arch/powerpc/kvm/book3s_64_vio.c|  118 ++
>  arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
> +++
>  arch/powerpc/kvm/book3s_hv.c|   39 +
>  arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
>  arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
>  arch/powerpc/kvm/powerpc.c  |3 +
>  include/uapi/linux/kvm.h|1 +
>  10 files changed, 470 insertions(+), 32 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index 5f91eda..3c7c7ea 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -2780,3 +2780,17 @@ Parameters: args[0] is the XICS device fd
>  args[1] is the XICS CPU number (server ID) for this vcpu
>  
>  This capability connects the vcpu to an in-kernel XICS device.
> +
> +6.8 KVM_CAP_PPC_MULTITCE
> +
> +Architectures: ppc
> +Parameters: none
> +Returns: 0 on success; -1 on error
> +
> +This capability enables the guest to put/remove multiple TCE entries
> +per hypercall which significanly accelerates DMA operations for PPC KVM
> +guests.
> +
> +When this capability is enabled, H_PUT_TCE_INDIRECT and H_STUFF_TCE are
> +expected to occur rather than H_PUT_TCE which supports only one TCE entry
> +per call.
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index af326cd..85d8f26 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
>   spinlock_t tbacct_lock;
>   u64 busy_stolen;
>   u64 busy_preempt;
> +
> + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
>  #endif
>  };
>  
> diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> b/arch/powerpc/include/asm/kvm_ppc.h
> index a5287fe..e852921b 100644
> --- a/arch/powerpc/include/asm/kvm_ppc.h
> +++ b/arch/powerpc/include/asm/kvm_ppc.h
> @@ -133,8 +133,20 @@ extern int kvmppc_pseries_do_hcall(struct kvm_vcpu 
> *vcpu);
>  
>  extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
>   struct kvm_create_spapr_tce *args);
> -extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
> -  unsigned long ioba, unsigned long tce);
> +extern struct kvmppc_spapr_tce_table *kvmppc_find_tce_table(
> + struct kvm_vcpu *vcpu, unsigned long liobn);
> +extern long kvmppc_emulated_validate_tce(unsigned long tce);
> +extern void kvmppc_emulated_put_tce(struct kvmppc_spapr_tce_table *tt,
> + unsigned long ioba, unsigned long tce);
> +extern long kvmppc_virtmode_h_put_tce(struct kvm_vcpu *vcpu,
> + unsigned long liobn, unsigned long ioba,
> + unsigned long tce);
> +extern long kvmppc_virtmode_h_put_tce_indirect(struct kvm_vcpu *vcpu,
> + unsigned long liobn, 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-05-27 Thread Paolo Bonzini
Il 21/05/2013 05:06, Alexey Kardashevskiy ha scritto:
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as virtio
 devices or emulated PCI.

Do you mean vio?  virtio (without getting into whether that's good or
bad) will bypass the iommu.

Paolo

 These calls allow adding multiple entries
 (up to 512) into the TCE table in one call which saves time on
 transition to/from real mode.
 
 This adds a tce_tmp cache to kvm_vcpu_arch to save valid TCEs
 (copied from user and verified) before writing the whole list into
 the TCE table. This cache will be utilized more in the upcoming
 VFIO/IOMMU support to continue TCE list processing in the virtual
 mode in the case if the real mode handler failed for some reason.
 
 This adds a guest physical to host real address converter
 and calls the existing H_PUT_TCE handler. The converting function
 is going to be fully utilized by upcoming VFIO supporting patches.
 
 This also implements the KVM_CAP_PPC_MULTITCE capability,
 so in order to support the functionality of this patch, QEMU
 needs to query for this capability and set the hcall-multi-tce
 hypertas property only if the capability is present, otherwise
 there will be serious performance degradation.
 
 Cc: David Gibson da...@gibson.dropbear.id.au
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru
 Signed-off-by: Paul Mackerras pau...@samba.org
 
 ---
 Changelog:
 * added kvm_vcpu_arch::tce_tmp
 * removed cleanup if put_indirect failed, instead we do not even start
 writing to TCE table if we cannot get TCEs from the user and they are
 invalid
 * kvmppc_emulated_h_put_tce is split to kvmppc_emulated_put_tce
 and kvmppc_emulated_validate_tce (for the previous item)
 * fixed bug with failthrough for H_IPI
 * removed all get_user() from real mode handlers
 * kvmppc_lookup_pte() added (instead of making lookup_linux_pte public)
 ---
  Documentation/virtual/kvm/api.txt   |   14 ++
  arch/powerpc/include/asm/kvm_host.h |2 +
  arch/powerpc/include/asm/kvm_ppc.h  |   16 +-
  arch/powerpc/kvm/book3s_64_vio.c|  118 ++
  arch/powerpc/kvm/book3s_64_vio_hv.c |  266 
 +++
  arch/powerpc/kvm/book3s_hv.c|   39 +
  arch/powerpc/kvm/book3s_hv_rmhandlers.S |6 +
  arch/powerpc/kvm/book3s_pr_papr.c   |   37 -
  arch/powerpc/kvm/powerpc.c  |3 +
  include/uapi/linux/kvm.h|1 +
  10 files changed, 470 insertions(+), 32 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index 5f91eda..3c7c7ea 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2780,3 +2780,17 @@ Parameters: args[0] is the XICS device fd
  args[1] is the XICS CPU number (server ID) for this vcpu
  
  This capability connects the vcpu to an in-kernel XICS device.
 +
 +6.8 KVM_CAP_PPC_MULTITCE
 +
 +Architectures: ppc
 +Parameters: none
 +Returns: 0 on success; -1 on error
 +
 +This capability enables the guest to put/remove multiple TCE entries
 +per hypercall which significanly accelerates DMA operations for PPC KVM
 +guests.
 +
 +When this capability is enabled, H_PUT_TCE_INDIRECT and H_STUFF_TCE are
 +expected to occur rather than H_PUT_TCE which supports only one TCE entry
 +per call.
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index af326cd..85d8f26 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -609,6 +609,8 @@ struct kvm_vcpu_arch {
   spinlock_t tbacct_lock;
   u64 busy_stolen;
   u64 busy_preempt;
 +
 + unsigned long *tce_tmp;/* TCE cache for TCE_PUT_INDIRECT hall */
  #endif
  };
  
 diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
 b/arch/powerpc/include/asm/kvm_ppc.h
 index a5287fe..e852921b 100644
 --- a/arch/powerpc/include/asm/kvm_ppc.h
 +++ b/arch/powerpc/include/asm/kvm_ppc.h
 @@ -133,8 +133,20 @@ extern int kvmppc_pseries_do_hcall(struct kvm_vcpu 
 *vcpu);
  
  extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
   struct kvm_create_spapr_tce *args);
 -extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
 -  unsigned long ioba, unsigned long tce);
 +extern struct kvmppc_spapr_tce_table *kvmppc_find_tce_table(
 + struct kvm_vcpu *vcpu, unsigned long liobn);
 +extern long kvmppc_emulated_validate_tce(unsigned long tce);
 +extern void kvmppc_emulated_put_tce(struct kvmppc_spapr_tce_table *tt,
 + unsigned long ioba, unsigned long tce);
 +extern long kvmppc_virtmode_h_put_tce(struct kvm_vcpu *vcpu,
 + unsigned long liobn, unsigned long ioba,
 + unsigned long tce);
 +extern long kvmppc_virtmode_h_put_tce_indirect(struct kvm_vcpu *vcpu,
 + unsigned long liobn, unsigned long ioba,
 + unsigned long 

Re: [PATCH 1/4] KVM: PPC: Add support for multiple-TCE hcalls

2013-05-27 Thread Alexey Kardashevskiy
On 05/27/2013 08:08 PM, Paolo Bonzini wrote:
 Il 21/05/2013 05:06, Alexey Kardashevskiy ha scritto:
 This adds real mode handlers for the H_PUT_TCE_INDIRECT and
 H_STUFF_TCE hypercalls for QEMU emulated devices such as virtio
 devices or emulated PCI.
 
 Do you mean vio?  virtio (without getting into whether that's good or
 bad) will bypass the iommu.

yes, mistake, should be VIO. thanks!


-- 
Alexey
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/