diff mbox series

[RFC,v2,11/14] linux-headers/kvm.h: add capability to forward hypercall

Message ID 20191105091056.9541-12-guoheyi@huawei.com (mailing list archive)
State New, archived
Headers show
Series Add SDEI support for arm64 | expand

Commit Message

Heyi Guo Nov. 5, 2019, 9:10 a.m. UTC
To keep backward compatibility, we add new KVM capability
"KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
hypercall to userspace.

The capability should be enabled explicitly, for we don't want user
space application to deal with unexpected hypercall exits. After
enabling this cap, all HVC calls unhandled by kvm will be forwarded to
user space.

Signed-off-by: Heyi Guo <guoheyi@huawei.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: James Morse <james.morse@arm.com>
---
 linux-headers/linux/kvm.h |  1 +
 target/arm/sdei.c         | 16 ++++++++++++++++
 target/arm/sdei.h         |  2 ++
 3 files changed, 19 insertions(+)

Comments

Cornelia Huck Nov. 6, 2019, 5:55 p.m. UTC | #1
On Tue, 5 Nov 2019 17:10:53 +0800
Heyi Guo <guoheyi@huawei.com> wrote:

> To keep backward compatibility, we add new KVM capability
> "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
> hypercall to userspace.
> 
> The capability should be enabled explicitly, for we don't want user
> space application to deal with unexpected hypercall exits. After
> enabling this cap, all HVC calls unhandled by kvm will be forwarded to
> user space.
> 
> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> Cc: Cornelia Huck <cohuck@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Dave Martin <Dave.Martin@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: James Morse <james.morse@arm.com>
> ---
>  linux-headers/linux/kvm.h |  1 +
>  target/arm/sdei.c         | 16 ++++++++++++++++
>  target/arm/sdei.h         |  2 ++
>  3 files changed, 19 insertions(+)
> 
> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
> index 3d9b18f7f8..36c9b3859f 100644
> --- a/linux-headers/linux/kvm.h
> +++ b/linux-headers/linux/kvm.h
> @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
>  #define KVM_CAP_PMU_EVENT_FILTER 173
>  #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
>  #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
> +#define KVM_CAP_FORWARD_HYPERCALL 176
>  
>  #ifdef KVM_CAP_IRQ_ROUTING

Is this cap upstream already? I would have thought your header sync
would have brought it in, then. (Saying this, that header sync looks
awfully small.)

If it is not upstream yet, please split off this hunk into a separate
patch -- it's a bit annoying, but makes life easier for merging.
Heyi Guo Nov. 7, 2019, 1:44 a.m. UTC | #2
On 2019/11/7 1:55, Cornelia Huck wrote:
> On Tue, 5 Nov 2019 17:10:53 +0800
> Heyi Guo <guoheyi@huawei.com> wrote:
>
>> To keep backward compatibility, we add new KVM capability
>> "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
>> hypercall to userspace.
>>
>> The capability should be enabled explicitly, for we don't want user
>> space application to deal with unexpected hypercall exits. After
>> enabling this cap, all HVC calls unhandled by kvm will be forwarded to
>> user space.
>>
>> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
>> Cc: Peter Maydell <peter.maydell@linaro.org>
>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
>> Cc: Cornelia Huck <cohuck@redhat.com>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Dave Martin <Dave.Martin@arm.com>
>> Cc: Marc Zyngier <marc.zyngier@arm.com>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: James Morse <james.morse@arm.com>
>> ---
>>   linux-headers/linux/kvm.h |  1 +
>>   target/arm/sdei.c         | 16 ++++++++++++++++
>>   target/arm/sdei.h         |  2 ++
>>   3 files changed, 19 insertions(+)
>>
>> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
>> index 3d9b18f7f8..36c9b3859f 100644
>> --- a/linux-headers/linux/kvm.h
>> +++ b/linux-headers/linux/kvm.h
>> @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
>>   #define KVM_CAP_PMU_EVENT_FILTER 173
>>   #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
>>   #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
>> +#define KVM_CAP_FORWARD_HYPERCALL 176
>>   
>>   #ifdef KVM_CAP_IRQ_ROUTING
> Is this cap upstream already? I would have thought your header sync
> would have brought it in, then. (Saying this, that header sync looks
> awfully small.)
>
> If it is not upstream yet, please split off this hunk into a separate
> patch -- it's a bit annoying, but makes life easier for merging.
No, it is not upstream yet. The whole framework and interfaces between 
KVM and qemu are still under discussion. I'll keep in mind of this when 
moving forward to next steps...

Thanks,
HG
>
>
> .
>
Michael S. Tsirkin Nov. 7, 2019, 8:57 a.m. UTC | #3
On Thu, Nov 07, 2019 at 09:44:36AM +0800, Guoheyi wrote:
> 
> 
> On 2019/11/7 1:55, Cornelia Huck wrote:
> > On Tue, 5 Nov 2019 17:10:53 +0800
> > Heyi Guo <guoheyi@huawei.com> wrote:
> > 
> > > To keep backward compatibility, we add new KVM capability
> > > "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
> > > hypercall to userspace.
> > > 
> > > The capability should be enabled explicitly, for we don't want user
> > > space application to deal with unexpected hypercall exits. After
> > > enabling this cap, all HVC calls unhandled by kvm will be forwarded to
> > > user space.
> > > 
> > > Signed-off-by: Heyi Guo <guoheyi@huawei.com>
> > > Cc: Peter Maydell <peter.maydell@linaro.org>
> > > Cc: "Michael S. Tsirkin" <mst@redhat.com>
> > > Cc: Cornelia Huck <cohuck@redhat.com>
> > > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > > Cc: Dave Martin <Dave.Martin@arm.com>
> > > Cc: Marc Zyngier <marc.zyngier@arm.com>
> > > Cc: Mark Rutland <mark.rutland@arm.com>
> > > Cc: James Morse <james.morse@arm.com>
> > > ---
> > >   linux-headers/linux/kvm.h |  1 +
> > >   target/arm/sdei.c         | 16 ++++++++++++++++
> > >   target/arm/sdei.h         |  2 ++
> > >   3 files changed, 19 insertions(+)
> > > 
> > > diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
> > > index 3d9b18f7f8..36c9b3859f 100644
> > > --- a/linux-headers/linux/kvm.h
> > > +++ b/linux-headers/linux/kvm.h
> > > @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
> > >   #define KVM_CAP_PMU_EVENT_FILTER 173
> > >   #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
> > >   #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
> > > +#define KVM_CAP_FORWARD_HYPERCALL 176
> > >   #ifdef KVM_CAP_IRQ_ROUTING
> > Is this cap upstream already? I would have thought your header sync
> > would have brought it in, then. (Saying this, that header sync looks
> > awfully small.)
> > 
> > If it is not upstream yet, please split off this hunk into a separate
> > patch -- it's a bit annoying, but makes life easier for merging.
> No, it is not upstream yet. The whole framework and interfaces between KVM
> and qemu are still under discussion. I'll keep in mind of this when moving
> forward to next steps...
> 
> Thanks,
> HG

It's best to add it in some other place meanwhile.
Then we can drop it when it's in an upstream header.


> > 
> > 
> > .
> > 
>
Heyi Guo Nov. 7, 2019, 11:57 a.m. UTC | #4
On 2019/11/7 16:57, Michael S. Tsirkin wrote:
> On Thu, Nov 07, 2019 at 09:44:36AM +0800, Guoheyi wrote:
>>
>> On 2019/11/7 1:55, Cornelia Huck wrote:
>>> On Tue, 5 Nov 2019 17:10:53 +0800
>>> Heyi Guo <guoheyi@huawei.com> wrote:
>>>
>>>> To keep backward compatibility, we add new KVM capability
>>>> "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
>>>> hypercall to userspace.
>>>>
>>>> The capability should be enabled explicitly, for we don't want user
>>>> space application to deal with unexpected hypercall exits. After
>>>> enabling this cap, all HVC calls unhandled by kvm will be forwarded to
>>>> user space.
>>>>
>>>> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
>>>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
>>>> Cc: Cornelia Huck <cohuck@redhat.com>
>>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>>>> Cc: Dave Martin <Dave.Martin@arm.com>
>>>> Cc: Marc Zyngier <marc.zyngier@arm.com>
>>>> Cc: Mark Rutland <mark.rutland@arm.com>
>>>> Cc: James Morse <james.morse@arm.com>
>>>> ---
>>>>    linux-headers/linux/kvm.h |  1 +
>>>>    target/arm/sdei.c         | 16 ++++++++++++++++
>>>>    target/arm/sdei.h         |  2 ++
>>>>    3 files changed, 19 insertions(+)
>>>>
>>>> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
>>>> index 3d9b18f7f8..36c9b3859f 100644
>>>> --- a/linux-headers/linux/kvm.h
>>>> +++ b/linux-headers/linux/kvm.h
>>>> @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
>>>>    #define KVM_CAP_PMU_EVENT_FILTER 173
>>>>    #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
>>>>    #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
>>>> +#define KVM_CAP_FORWARD_HYPERCALL 176
>>>>    #ifdef KVM_CAP_IRQ_ROUTING
>>> Is this cap upstream already? I would have thought your header sync
>>> would have brought it in, then. (Saying this, that header sync looks
>>> awfully small.)
>>>
>>> If it is not upstream yet, please split off this hunk into a separate
>>> patch -- it's a bit annoying, but makes life easier for merging.
>> No, it is not upstream yet. The whole framework and interfaces between KVM
>> and qemu are still under discussion. I'll keep in mind of this when moving
>> forward to next steps...
>>
>> Thanks,
>> HG
> It's best to add it in some other place meanwhile.
Do you mean to split this patch from the whole patch set and send it 
separately? Sorry I'm not clear about maintainers' work and may bring 
you some trouble...

Thanks,
HG

> Then we can drop it when it's in an upstream header.
>
>
>>>
>>> .
>>>
> .
>
Cornelia Huck Nov. 7, 2019, 12:12 p.m. UTC | #5
On Thu, 7 Nov 2019 19:57:22 +0800
Guoheyi <guoheyi@huawei.com> wrote:

> On 2019/11/7 16:57, Michael S. Tsirkin wrote:
> > On Thu, Nov 07, 2019 at 09:44:36AM +0800, Guoheyi wrote:  
> >>
> >> On 2019/11/7 1:55, Cornelia Huck wrote:  
> >>> On Tue, 5 Nov 2019 17:10:53 +0800
> >>> Heyi Guo <guoheyi@huawei.com> wrote:
> >>>  
> >>>> To keep backward compatibility, we add new KVM capability
> >>>> "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
> >>>> hypercall to userspace.
> >>>>
> >>>> The capability should be enabled explicitly, for we don't want user
> >>>> space application to deal with unexpected hypercall exits. After
> >>>> enabling this cap, all HVC calls unhandled by kvm will be forwarded to
> >>>> user space.
> >>>>
> >>>> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
> >>>> Cc: Peter Maydell <peter.maydell@linaro.org>
> >>>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
> >>>> Cc: Cornelia Huck <cohuck@redhat.com>
> >>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
> >>>> Cc: Dave Martin <Dave.Martin@arm.com>
> >>>> Cc: Marc Zyngier <marc.zyngier@arm.com>
> >>>> Cc: Mark Rutland <mark.rutland@arm.com>
> >>>> Cc: James Morse <james.morse@arm.com>
> >>>> ---
> >>>>    linux-headers/linux/kvm.h |  1 +
> >>>>    target/arm/sdei.c         | 16 ++++++++++++++++
> >>>>    target/arm/sdei.h         |  2 ++
> >>>>    3 files changed, 19 insertions(+)
> >>>>
> >>>> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
> >>>> index 3d9b18f7f8..36c9b3859f 100644
> >>>> --- a/linux-headers/linux/kvm.h
> >>>> +++ b/linux-headers/linux/kvm.h
> >>>> @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
> >>>>    #define KVM_CAP_PMU_EVENT_FILTER 173
> >>>>    #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
> >>>>    #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
> >>>> +#define KVM_CAP_FORWARD_HYPERCALL 176
> >>>>    #ifdef KVM_CAP_IRQ_ROUTING  
> >>> Is this cap upstream already? I would have thought your header sync
> >>> would have brought it in, then. (Saying this, that header sync looks
> >>> awfully small.)
> >>>
> >>> If it is not upstream yet, please split off this hunk into a separate
> >>> patch -- it's a bit annoying, but makes life easier for merging.  
> >> No, it is not upstream yet. The whole framework and interfaces between KVM
> >> and qemu are still under discussion. I'll keep in mind of this when moving
> >> forward to next steps...
> >>
> >> Thanks,
> >> HG  
> > It's best to add it in some other place meanwhile.  
> Do you mean to split this patch from the whole patch set and send it 
> separately? Sorry I'm not clear about maintainers' work and may bring 
> you some trouble...

My preferred approach:

- add a commit entitled "placeholder for headers update" that contains
  the not-yet-upstream changes in the header files you need
- base the rest of your work on that
...
<review happens, series looks good>
...
- if kernel changes are upstream: replace the placeholder patch with a
  real update (may include separate patches, if you need an additional
  header); maintainer merges
- if kernel changes are not yet upstream: maintainer merges with
  placeholder to a feature branch, replaces with real update and merges
  once kernel patches hit upstream
(not every maintainer does the second approach; they may ask you
instead to resend with a proper headers update once the kernel changes
are upstream)
Heyi Guo Nov. 8, 2019, 1:54 a.m. UTC | #6
On 2019/11/7 20:12, Cornelia Huck wrote:
> On Thu, 7 Nov 2019 19:57:22 +0800
> Guoheyi <guoheyi@huawei.com> wrote:
>
>> On 2019/11/7 16:57, Michael S. Tsirkin wrote:
>>> On Thu, Nov 07, 2019 at 09:44:36AM +0800, Guoheyi wrote:
>>>> On 2019/11/7 1:55, Cornelia Huck wrote:
>>>>> On Tue, 5 Nov 2019 17:10:53 +0800
>>>>> Heyi Guo <guoheyi@huawei.com> wrote:
>>>>>   
>>>>>> To keep backward compatibility, we add new KVM capability
>>>>>> "KVM_CAP_FORWARD_HYPERCALL" to probe whether KVM supports forwarding
>>>>>> hypercall to userspace.
>>>>>>
>>>>>> The capability should be enabled explicitly, for we don't want user
>>>>>> space application to deal with unexpected hypercall exits. After
>>>>>> enabling this cap, all HVC calls unhandled by kvm will be forwarded to
>>>>>> user space.
>>>>>>
>>>>>> Signed-off-by: Heyi Guo <guoheyi@huawei.com>
>>>>>> Cc: Peter Maydell <peter.maydell@linaro.org>
>>>>>> Cc: "Michael S. Tsirkin" <mst@redhat.com>
>>>>>> Cc: Cornelia Huck <cohuck@redhat.com>
>>>>>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>>>>>> Cc: Dave Martin <Dave.Martin@arm.com>
>>>>>> Cc: Marc Zyngier <marc.zyngier@arm.com>
>>>>>> Cc: Mark Rutland <mark.rutland@arm.com>
>>>>>> Cc: James Morse <james.morse@arm.com>
>>>>>> ---
>>>>>>     linux-headers/linux/kvm.h |  1 +
>>>>>>     target/arm/sdei.c         | 16 ++++++++++++++++
>>>>>>     target/arm/sdei.h         |  2 ++
>>>>>>     3 files changed, 19 insertions(+)
>>>>>>
>>>>>> diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
>>>>>> index 3d9b18f7f8..36c9b3859f 100644
>>>>>> --- a/linux-headers/linux/kvm.h
>>>>>> +++ b/linux-headers/linux/kvm.h
>>>>>> @@ -1000,6 +1000,7 @@ struct kvm_ppc_resize_hpt {
>>>>>>     #define KVM_CAP_PMU_EVENT_FILTER 173
>>>>>>     #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
>>>>>>     #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
>>>>>> +#define KVM_CAP_FORWARD_HYPERCALL 176
>>>>>>     #ifdef KVM_CAP_IRQ_ROUTING
>>>>> Is this cap upstream already? I would have thought your header sync
>>>>> would have brought it in, then. (Saying this, that header sync looks
>>>>> awfully small.)
>>>>>
>>>>> If it is not upstream yet, please split off this hunk into a separate
>>>>> patch -- it's a bit annoying, but makes life easier for merging.
>>>> No, it is not upstream yet. The whole framework and interfaces between KVM
>>>> and qemu are still under discussion. I'll keep in mind of this when moving
>>>> forward to next steps...
>>>>
>>>> Thanks,
>>>> HG
>>> It's best to add it in some other place meanwhile.
>> Do you mean to split this patch from the whole patch set and send it
>> separately? Sorry I'm not clear about maintainers' work and may bring
>> you some trouble...
> My preferred approach:
>
> - add a commit entitled "placeholder for headers update" that contains
>    the not-yet-upstream changes in the header files you need
> - base the rest of your work on that
> ...
> <review happens, series looks good>
> ...
> - if kernel changes are upstream: replace the placeholder patch with a
>    real update (may include separate patches, if you need an additional
>    header); maintainer merges
> - if kernel changes are not yet upstream: maintainer merges with
>    placeholder to a feature branch, replaces with real update and merges
>    once kernel patches hit upstream
> (not every maintainer does the second approach; they may ask you
> instead to resend with a proper headers update once the kernel changes
> are upstream)

Thanks a lot. I'll do that in the next version.
HG

>
> .
>
diff mbox series

Patch

diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 3d9b18f7f8..36c9b3859f 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1000,6 +1000,7 @@  struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PMU_EVENT_FILTER 173
 #define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
 #define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
+#define KVM_CAP_FORWARD_HYPERCALL 176
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/target/arm/sdei.c b/target/arm/sdei.c
index 4cc68e4acf..56e6874f6f 100644
--- a/target/arm/sdei.c
+++ b/target/arm/sdei.c
@@ -46,6 +46,7 @@ 
 #define SMCCC_RETURN_REG_COUNT 4
 #define PSTATE_M_EL_SHIFT      2
 
+bool sdei_enabled;
 static QemuSDEState *sde_state;
 
 typedef struct QemuSDEIBindNotifyEntry {
@@ -1524,6 +1525,7 @@  static const VMStateDescription vmstate_sde_state = {
 static void sdei_initfn(Object *obj)
 {
     QemuSDEState *s = QEMU_SDEI(obj);
+    KVMState *kvm = KVM_STATE(current_machine->accelerator);
 
     if (sde_state) {
         error_report("Only one SDEI dispatcher is allowed!");
@@ -1533,6 +1535,20 @@  static void sdei_initfn(Object *obj)
 
     qemu_sde_init(s);
     qemu_register_reset(qemu_sde_reset, s);
+
+    if (kvm_check_extension(kvm, KVM_CAP_FORWARD_HYPERCALL)) {
+        int ret;
+        ret = kvm_vm_enable_cap(kvm, KVM_CAP_FORWARD_HYPERCALL, 0, 0);
+        if (ret < 0) {
+            error_report("Enable hypercall forwarding failed: %s",
+                         strerror(-ret));
+            abort();
+        }
+        sdei_enabled = true;
+        info_report("qemu sdei enabled");
+    } else {
+        info_report("KVM does not support forwarding hypercall.");
+    }
 }
 
 static void qemu_sde_class_init(ObjectClass *klass, void *data)
diff --git a/target/arm/sdei.h b/target/arm/sdei.h
index 9c15cf3186..9f683ca2a0 100644
--- a/target/arm/sdei.h
+++ b/target/arm/sdei.h
@@ -29,6 +29,8 @@ 
 
 #define SDEI_MAX_REQ        SDEI_1_0_FN(0x12)
 
+extern bool sdei_enabled;
+
 void sdei_handle_request(CPUState *cs, struct kvm_run *run);
 
 /*