[RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2014-11-24 Thread Nikolay Nikolaev
On IO memory abort, try to handle the MMIO access thorugh the KVM
registered read/write callbacks. This is done by invoking the relevant
kvm_io_bus_* API.

Signed-off-by: Nikolay Nikolaev 
---
 arch/arm/kvm/mmio.c |   33 +
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
index 4cb5a93..81230da 100644
--- a/arch/arm/kvm/mmio.c
+++ b/arch/arm/kvm/mmio.c
@@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t 
fault_ipa,
return 0;
 }
 
+/**
+ * kvm_handle_mmio - handle an in-kernel MMIO access
+ * @vcpu:  pointer to the vcpu performing the access
+ * @run:   pointer to the kvm_run structure
+ * @mmio:  pointer to the data describing the access
+ *
+ * returns true if the MMIO access has been performed in kernel space,
+ * and false if it needs to be emulated in user space.
+ */
+static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
+   struct kvm_exit_mmio *mmio)
+{
+   int ret;
+
+   if (mmio->is_write) {
+   ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
+   mmio->len, &mmio->data);
+
+   } else {
+   ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
+   mmio->len, &mmio->data);
+   }
+   if (!ret) {
+   kvm_prepare_mmio(run, mmio);
+   kvm_handle_mmio_return(vcpu, run);
+   }
+
+   return !ret;
+}
+
 int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
 phys_addr_t fault_ipa)
 {
@@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
if (vgic_handle_mmio(vcpu, run, &mmio))
return 1;
 
+   if (handle_kernel_mmio(vcpu, run, &mmio))
+   return 1;
+
kvm_prepare_mmio(run, &mmio);
return 0;
 }

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


Re: [RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2015-01-23 Thread Nikolay Nikolaev
On Mon, Jan 12, 2015 at 6:21 PM, Eric Auger  wrote:
>
> On 12/05/2014 01:06 PM, Nikolay Nikolaev wrote:
> > On Sat, Nov 29, 2014 at 1:28 PM, Christoffer Dall
> >  wrote:
> >> On Mon, Nov 24, 2014 at 11:26:51PM +0200, Nikolay Nikolaev wrote:
> >>> On IO memory abort, try to handle the MMIO access thorugh the KVM
> >>> registered read/write callbacks. This is done by invoking the relevant
> >>> kvm_io_bus_* API.
> >>>
> >>> Signed-off-by: Nikolay Nikolaev 
> >>> ---
> >>>  arch/arm/kvm/mmio.c |   33 +
> >>>  1 file changed, 33 insertions(+)
> >>>
> >>> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
> >>> index 4cb5a93..81230da 100644
> >>> --- a/arch/arm/kvm/mmio.c
> >>> +++ b/arch/arm/kvm/mmio.c
> >>> @@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, 
> >>> phys_addr_t fault_ipa,
> >>>   return 0;
> >>>  }
> >>>
> >>> +/**
> >>> + * kvm_handle_mmio - handle an in-kernel MMIO access
> >>> + * @vcpu:pointer to the vcpu performing the access
> >>> + * @run: pointer to the kvm_run structure
> >>> + * @mmio:pointer to the data describing the access
> >>> + *
> >>> + * returns true if the MMIO access has been performed in kernel space,
> >>> + * and false if it needs to be emulated in user space.
> >>> + */
> >>> +static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run 
> >>> *run,
> >>> + struct kvm_exit_mmio *mmio)
> >>> +{
> >>> + int ret;
> >>> +
> >>> + if (mmio->is_write) {
> >>> + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> >>> + mmio->len, &mmio->data);
> >>> +
> >>> + } else {
> >>> + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> >>> + mmio->len, &mmio->data);
> >>> + }
> >>> + if (!ret) {
> >>> + kvm_prepare_mmio(run, mmio);
> >>> + kvm_handle_mmio_return(vcpu, run);
> >>> + }
> >>> +
> >>> + return !ret;
> >>> +}
> >>> +
> >>>  int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
> >>>phys_addr_t fault_ipa)
> >>>  {
> >>> @@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct 
> >>> kvm_run *run,
> >>>   if (vgic_handle_mmio(vcpu, run, &mmio))
> >>>   return 1;
> >>>
> >>> + if (handle_kernel_mmio(vcpu, run, &mmio))
> >>> + return 1;
> >>> +
> >>
> >> Is this stuff always synchronously handled so that the mmio is properly
> >> populated upon handle_kernel_mmio on reads?
> >
> > If I get it right the kvm_io_bus_ API is intended to work
> > synchronously. Of course it probably depends
> > on how the registered device handles the read/write call.
> > Or maybe I misunderstand your question? Please clarify in that case.
>
> in case of ioeventfd implementation it is not the case since the write
> is deferred in the kernel thread which handles the eventfd.

Christofer was asking about reads. I guess about writes it does not
make any diiference as long as the needed values are copied into the
new thread.

regards,
Nikolay Nikolaev

>
> Best Regards
>
> Eric
> >
> > regards,
> > Nikolay Nikolaev
> >
> >>
> >> -Christoffer
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2014-11-27 Thread Eric Auger
On 11/24/2014 10:26 PM, Nikolay Nikolaev wrote:
> On IO memory abort, try to handle the MMIO access thorugh the KVM
typo
> registered read/write callbacks. This is done by invoking the relevant
> kvm_io_bus_* API.
> 
> Signed-off-by: Nikolay Nikolaev 
> ---
>  arch/arm/kvm/mmio.c |   33 +
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
> index 4cb5a93..81230da 100644
> --- a/arch/arm/kvm/mmio.c
> +++ b/arch/arm/kvm/mmio.c
> @@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t 
> fault_ipa,
>   return 0;
>  }
>  
> +/**
> + * kvm_handle_mmio - handle an in-kernel MMIO access
handle_kernel_mmio
> + * @vcpu:pointer to the vcpu performing the access
> + * @run: pointer to the kvm_run structure
> + * @mmio:pointer to the data describing the access
> + *
> + * returns true if the MMIO access has been performed in kernel space,
> + * and false if it needs to be emulated in user space.
> + */
> +static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
> + struct kvm_exit_mmio *mmio)
> +{
> + int ret;
> +
> + if (mmio->is_write) {
> + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);
> +
> + } else {
> + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);

> + }
> + if (!ret) {
> + kvm_prepare_mmio(run, mmio);
> + kvm_handle_mmio_return(vcpu, run);
Shouldn't the comment associated to kvm_handle_mmio_return saying
the function "should only be called after returning from userspace for
MMIO load emulation" be updated? Here we did kernel emulation and we
call it. also in vgic it is called. Must aknowledge I do not fully
understand what the .rt is.
> + }
> +
> + return !ret;
what if kvm_io_bus_read returned -EOPNOTSUPP?
> +}
> +
>  int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
>phys_addr_t fault_ipa)
>  {
> @@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run 
> *run,
>   if (vgic_handle_mmio(vcpu, run, &mmio))
>   return 1;
>  
> + if (handle_kernel_mmio(vcpu, run, &mmio))
> + return 1;
> +

>   kvm_prepare_mmio(run, &mmio);
>   return 0;
>  }
> 

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


Re: [RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2014-11-29 Thread Christoffer Dall
The subject could use a KVM: prefix.

On Mon, Nov 24, 2014 at 11:26:51PM +0200, Nikolay Nikolaev wrote:
> On IO memory abort, try to handle the MMIO access thorugh the KVM
> registered read/write callbacks. This is done by invoking the relevant
> kvm_io_bus_* API.
> 
> Signed-off-by: Nikolay Nikolaev 
> ---
>  arch/arm/kvm/mmio.c |   33 +
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
> index 4cb5a93..81230da 100644
> --- a/arch/arm/kvm/mmio.c
> +++ b/arch/arm/kvm/mmio.c
> @@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t 
> fault_ipa,
>   return 0;
>  }
>  
> +/**
> + * kvm_handle_mmio - handle an in-kernel MMIO access
> + * @vcpu:pointer to the vcpu performing the access
> + * @run: pointer to the kvm_run structure
> + * @mmio:pointer to the data describing the access
> + *
> + * returns true if the MMIO access has been performed in kernel space,
> + * and false if it needs to be emulated in user space.
> + */
> +static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
> + struct kvm_exit_mmio *mmio)
> +{
> + int ret;
> +
> + if (mmio->is_write) {
> + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);
> +
> + } else {
> + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);
> + }
> + if (!ret) {
> + kvm_prepare_mmio(run, mmio);
> + kvm_handle_mmio_return(vcpu, run);
> + }
> +
> + return !ret;
> +}
> +
>  int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
>phys_addr_t fault_ipa)
>  {
> @@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run 
> *run,
>   if (vgic_handle_mmio(vcpu, run, &mmio))
>   return 1;
>  
> + if (handle_kernel_mmio(vcpu, run, &mmio))
> + return 1;
> +
>   kvm_prepare_mmio(run, &mmio);
>   return 0;
>  }
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2014-11-29 Thread Christoffer Dall
On Mon, Nov 24, 2014 at 11:26:51PM +0200, Nikolay Nikolaev wrote:
> On IO memory abort, try to handle the MMIO access thorugh the KVM
> registered read/write callbacks. This is done by invoking the relevant
> kvm_io_bus_* API.
> 
> Signed-off-by: Nikolay Nikolaev 
> ---
>  arch/arm/kvm/mmio.c |   33 +
>  1 file changed, 33 insertions(+)
> 
> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
> index 4cb5a93..81230da 100644
> --- a/arch/arm/kvm/mmio.c
> +++ b/arch/arm/kvm/mmio.c
> @@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t 
> fault_ipa,
>   return 0;
>  }
>  
> +/**
> + * kvm_handle_mmio - handle an in-kernel MMIO access
> + * @vcpu:pointer to the vcpu performing the access
> + * @run: pointer to the kvm_run structure
> + * @mmio:pointer to the data describing the access
> + *
> + * returns true if the MMIO access has been performed in kernel space,
> + * and false if it needs to be emulated in user space.
> + */
> +static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
> + struct kvm_exit_mmio *mmio)
> +{
> + int ret;
> +
> + if (mmio->is_write) {
> + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);
> +
> + } else {
> + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
> + mmio->len, &mmio->data);
> + }
> + if (!ret) {
> + kvm_prepare_mmio(run, mmio);
> + kvm_handle_mmio_return(vcpu, run);
> + }
> +
> + return !ret;
> +}
> +
>  int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
>phys_addr_t fault_ipa)
>  {
> @@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run 
> *run,
>   if (vgic_handle_mmio(vcpu, run, &mmio))
>   return 1;
>  
> + if (handle_kernel_mmio(vcpu, run, &mmio))
> + return 1;
> +

Is this stuff always synchronously handled so that the mmio is properly
populated upon handle_kernel_mmio on reads?

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


Re: [RFC PATCH 2/5] ARM: on IO mem abort - route the call to KVM MMIO bus

2014-12-05 Thread Nikolay Nikolaev
On Sat, Nov 29, 2014 at 1:28 PM, Christoffer Dall
 wrote:
> On Mon, Nov 24, 2014 at 11:26:51PM +0200, Nikolay Nikolaev wrote:
>> On IO memory abort, try to handle the MMIO access thorugh the KVM
>> registered read/write callbacks. This is done by invoking the relevant
>> kvm_io_bus_* API.
>>
>> Signed-off-by: Nikolay Nikolaev 
>> ---
>>  arch/arm/kvm/mmio.c |   33 +
>>  1 file changed, 33 insertions(+)
>>
>> diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c
>> index 4cb5a93..81230da 100644
>> --- a/arch/arm/kvm/mmio.c
>> +++ b/arch/arm/kvm/mmio.c
>> @@ -162,6 +162,36 @@ static int decode_hsr(struct kvm_vcpu *vcpu, 
>> phys_addr_t fault_ipa,
>>   return 0;
>>  }
>>
>> +/**
>> + * kvm_handle_mmio - handle an in-kernel MMIO access
>> + * @vcpu:pointer to the vcpu performing the access
>> + * @run: pointer to the kvm_run structure
>> + * @mmio:pointer to the data describing the access
>> + *
>> + * returns true if the MMIO access has been performed in kernel space,
>> + * and false if it needs to be emulated in user space.
>> + */
>> +static bool handle_kernel_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
>> + struct kvm_exit_mmio *mmio)
>> +{
>> + int ret;
>> +
>> + if (mmio->is_write) {
>> + ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
>> + mmio->len, &mmio->data);
>> +
>> + } else {
>> + ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, mmio->phys_addr,
>> + mmio->len, &mmio->data);
>> + }
>> + if (!ret) {
>> + kvm_prepare_mmio(run, mmio);
>> + kvm_handle_mmio_return(vcpu, run);
>> + }
>> +
>> + return !ret;
>> +}
>> +
>>  int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
>>phys_addr_t fault_ipa)
>>  {
>> @@ -200,6 +230,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run 
>> *run,
>>   if (vgic_handle_mmio(vcpu, run, &mmio))
>>   return 1;
>>
>> + if (handle_kernel_mmio(vcpu, run, &mmio))
>> + return 1;
>> +
>
> Is this stuff always synchronously handled so that the mmio is properly
> populated upon handle_kernel_mmio on reads?

If I get it right the kvm_io_bus_ API is intended to work
synchronously. Of course it probably depends
on how the registered device handles the read/write call.
Or maybe I misunderstand your question? Please clarify in that case.

regards,
Nikolay Nikolaev

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