[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] x86/xen: Add support for HVMOP_set_evtchn_upcall_vector


  • To: Julien Grall <julien@xxxxxxx>, LKML <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Jane Malalane <Jane.Malalane@xxxxxxxxxx>
  • Date: Wed, 27 Jul 2022 15:43:29 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lmlnHnArL5v80qKyMZxUKO3fUF2TRhOSDyN3EhMWdb4=; b=Z48fT7NFStzGeEWfJxJEminx9rGITdKcHUixM3Hz4rpVWzxt2fGDhNYDiaMxg1fx/02O12LvpOL00UmNMctrDVMteahzO8thcksSY8th9wwf+8eLZwnqN0wBMzHDb8tmOGAIxNTF6OKjk/YnwUcl3+tkFt4mmVFIWpBQNzkXCXN4MzdQDZjcFxgDbC2p3AL24pMeajWeyIZZIOsALlwfAtDv/D7QW6A8/ieObR7pr7PnStJKcrWk90TShSQW0GYmd3o4nxibiMeeGfhF5d/oYw5dwczxrWJxX8XfeRiQ/yqw4lkoCq2aaTP4WZDGgdgEZ8iDcJ3N1Rk/vck3XpWo5g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L20fj5+G8DQqAVfiDEDzSA4jJp4ARy59J7N5eThtmCupTHsXJFrrX76RBfECQHo7O3TrRAILkvCYQWKdiK7fRw9/LfKhAfXuTRhme4tnDyPH9kbZQbmnI04GePGSJU2+23xEsMA4CCw/y0rcfAVnxAMmK6FhvaY6LuLmM6+VFJoGDlHm9uchqKpCsqjEUg256GAYPpD82A2gPVFMy/Us+eBctukbUAXFEQx1yP4TnBEPkIWT599eO+Oiab3lGQTeTfn15AvYejptfGc0nftuT58zL+ZfP/6q7H9aj7N/mHNuKSS1wB3Iu+zvOixaAmJjGgNasHRJk3w/9gZ57J4opA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Juergen Gross <jgross@xxxxxxxx>, Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, "x86@xxxxxxxxxx" <x86@xxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>, Maximilian Heyne <mheyne@xxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Colin Ian King <colin.king@xxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 27 Jul 2022 15:43:40 +0000
  • Ironport-data: A9a23:cGuzb6nLvUM3QxzrwbS6JRTo5mJPLRN5O6RN2KgSYk/6f7AAGkVYHNDTQj8QOYZgVIWol2/guFWZSjo8ma2h7z6V58zBmKLovMHZLz/hCwAjLFrumKVI1MYEijjmPTMeGCDMwYJHjcJ4hTM8yHf7I9go6H95Ym4D+coK4wL/vp92hpslD/CcOo0iTCjEeD7LRE03QJR7k4hxYSy2ynPwDMIB7Yc2rRYlHjFXn3EHS/2jeaZwGCri9WChcjAt3GOYxiobk9pZHGqom3mgc298I9bnPcGthddnImpEkKiO1GxVb+5kiVcUhbufMay+/YvHNhabBeoxqrSjg7gxbsBMzdm+6S/PcIv7zb5ue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p0DuelkeXCz+G+Z5dK5F8vpMUpAlKcBha/Pt++g4JjgmYyb2AcwoMR19c7J8YiuotIJhAnLSlASEWtaiZMP9o5Oez2nq+D0rOS8EOTZS8PnjFE7m3TQd+yUwkDIAppM0oYWpcQV6/AwkHCUljwkzh0M57VtWdyv5u3A4cYJjt/5BsIoHaZHD65m9YPA7nw1CyMLZ7cp4IqNoxUdXeaT9TA9j7O3dClLiuY2u+V0LmL2LF9wxGGuS6W/oGoA4DBqGLlaSpaJ7aGGW7FoptIPTPxwIaDf2I56OkdifLZ3HCiIGbPUNmoWOipiewuwwqsuLaAMnyAX/U6LKyFOyF4zyXIlBM7lOt2sE18zDpgIZdir9W72Q9BXXcLwzII48ado0/e1gcyJGJN+BgGG0rGKBU9U5kYiFr2khmLwr9wU3NW9PK+yvukxjrIqhBqAr9wS2nQlPImMFN1p5CQLZ18mcPi64kMAO+JR1poHxqG+H+a+14BAIzC3tRW8QXSFh1PhGk5w/+2znYFRUykijU7fs77glHlUjY75k8OvK30p2HvjFk65rPgGvDJY3luGKZxB2LC6diq2tbE9OlqrOB7+Eo1JDV8FaUaZBFOFd4OAMoo2flcbvgcbYFGeSfE9I+6vg==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHYoO9LZ/coQoD4ekyAV2OZDcw3862SKA0AgAA1ToA=
  • Thread-topic: [PATCH v2] x86/xen: Add support for HVMOP_set_evtchn_upcall_vector

On 27/07/2022 13:32, Julien Grall wrote:
> [CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open 
> attachments unless you have verified the sender and know the content is 
> safe.
> 
> Hi Jane,
> 
> On 26/07/2022 13:56, Jane Malalane wrote:
>> diff --git a/arch/x86/xen/suspend_hvm.c b/arch/x86/xen/suspend_hvm.c
>> index 9d548b0c772f..0c4f7554b7cc 100644
>> --- a/arch/x86/xen/suspend_hvm.c
>> +++ b/arch/x86/xen/suspend_hvm.c
>> @@ -5,6 +5,7 @@
>>   #include <xen/hvm.h>
>>   #include <xen/features.h>
>>   #include <xen/interface/features.h>
>> +#include <xen/events.h>
>>   #include "xen-ops.h"
>> @@ -14,6 +15,13 @@ void xen_hvm_post_suspend(int suspend_cancelled)
>>           xen_hvm_init_shared_info();
>>           xen_vcpu_restore();
>>       }
>> -    xen_setup_callback_vector();
>> +    if (xen_percpu_upcall) {
>> +        unsigned int cpu;
>> +
>> +        for_each_online_cpu(cpu)
>> +            BUG_ON(xen_set_upcall_vector(cpu));
>> +    } else {
>> +        xen_setup_callback_vector();
>> +    }
>>       xen_unplug_emulated_devices();
>>   }
>> diff --git a/drivers/xen/events/events_base.c 
>> b/drivers/xen/events/events_base.c
>> index 46d9295d9a6e..2ad93595d03a 100644
>> --- a/drivers/xen/events/events_base.c
>> +++ b/drivers/xen/events/events_base.c
>> @@ -48,6 +48,7 @@
>>   #include <asm/xen/pci.h>
>>   #endif
>>   #include <asm/sync_bitops.h>
>> +#include <asm/xen/cpuid.h>
> 
> This include doesn't exist on Arm and will result to a build failure:
> 
> linux/drivers/xen/events/events_base.c:51:10: fatal error: 
> asm/xen/cpuid.h: No such file or directory
>     51 | #include <asm/xen/cpuid.h>
>        |          ^~~~~~~~~~~~~~~~~
Thanks, will place it inside the #ifdef CONFIG_X86.
> 
>>   #include <asm/xen/hypercall.h>
>>   #include <asm/xen/hypervisor.h>
>>   #include <xen/page.h>
>> @@ -2195,11 +2196,48 @@ void xen_setup_callback_vector(void)
>>           callback_via = HVM_CALLBACK_VECTOR(HYPERVISOR_CALLBACK_VECTOR);
>>           if (xen_set_callback_via(callback_via)) {
>>               pr_err("Request for Xen HVM callback vector failed\n");
>> -            xen_have_vector_callback = 0;
>> +            xen_have_vector_callback = false;
>>           }
>>       }
>>   }
>> +/* Setup per-vCPU vector-type callbacks and trick toolstack to think
>> + * we are enlightened. If this setup is unavailable, fallback to the
>> + * global vector-type callback. */
>> +static __init void xen_init_setup_upcall_vector(void)
>> +{
>> +    unsigned int cpu = 0;
>> +
>> +    if (!xen_have_vector_callback)
>> +        return;
>> +
>> +    if ((cpuid_eax(xen_cpuid_base() + 4) & 
>> XEN_HVM_CPUID_UPCALL_VECTOR) &&
>> +        !xen_set_upcall_vector(cpu) && !xen_set_callback_via(1))
> 
> xen_cpuid_base() is an x86-ism. This is going to build because 
> CONFIG_XEN_PVHVM is only set for x86. However, I think this is quite 
> fragile.
> 
> You are also using more variable defined only on x86. So it feels to me 
> that these functions should be implemented in x86 code.
I can surround those 4 callback/upcall functions with an ##ifdef.>> 
+        xen_percpu_upcall = true;
>> +    else if (xen_feature(XENFEAT_hvm_callback_vector))
>> +        xen_setup_callback_vector();
>> +    else
>> +        xen_have_vector_callback = false;
>> +}
>> +
>> +int xen_set_upcall_vector(unsigned int cpu)
>> +{
>> +    int rc;
>> +    xen_hvm_evtchn_upcall_vector_t op = {
>> +        .vector = HYPERVISOR_CALLBACK_VECTOR,
>> +        .vcpu = per_cpu(xen_vcpu_id, cpu),
>> +    };
>> +
>> +    rc = HYPERVISOR_hvm_op(HVMOP_set_evtchn_upcall_vector, &op);
>> +    if (rc)
>> +        return rc;
>> +
>> +    if (!cpu)
>> +        rc = xen_set_callback_via(1);
>> +
>> +    return rc;
>> +}
>> +
>>   static __init void xen_alloc_callback_vector(void)
>>   {
>>       if (!xen_have_vector_callback)
>> @@ -2210,6 +2248,8 @@ static __init void xen_alloc_callback_vector(void)
>>   }
>>   #else
>>   void xen_setup_callback_vector(void) {}
>> +static inline void xen_init_setup_upcall_vector(void) {}
>> +int xen_set_upcall_vector(unsigned int cpu) {}
>>   static inline void xen_alloc_callback_vector(void) {}
>>   #endif
>> @@ -2271,10 +2311,9 @@ void __init xen_init_IRQ(void)
>>           if (xen_initial_domain())
>>               pci_xen_initial_domain();
>>       }
>> -    if (xen_feature(XENFEAT_hvm_callback_vector)) {
>> -        xen_setup_callback_vector();
>> -        xen_alloc_callback_vector();
>> -    }
>> +    xen_init_setup_upcall_vector();
>> +    xen_alloc_callback_vector();
>> +
>>       if (xen_hvm_domain()) {
>>           native_init_IRQ();
>> diff --git a/include/xen/hvm.h b/include/xen/hvm.h
>> index b7fd7fc9ad41..8da7a6747058 100644
>> --- a/include/xen/hvm.h
>> +++ b/include/xen/hvm.h
>> @@ -60,4 +60,6 @@ static inline int hvm_get_parameter(int idx, 
>> uint64_t *value)
>>   void xen_setup_callback_vector(void);
>> +int xen_set_upcall_vector(unsigned int cpu);
>> +
>>   #endif /* XEN_HVM_H__ */
>> diff --git a/include/xen/interface/hvm/hvm_op.h 
>> b/include/xen/interface/hvm/hvm_op.h
>> index f3097e79bb03..e714d8b6ef89 100644
>> --- a/include/xen/interface/hvm/hvm_op.h
>> +++ b/include/xen/interface/hvm/hvm_op.h
>> @@ -46,4 +46,19 @@ struct xen_hvm_get_mem_type {
>>   };
>>   DEFINE_GUEST_HANDLE_STRUCT(xen_hvm_get_mem_type);
>> +/*
>> + * HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used 
>> for event
>> + *                                 channel upcalls on the specified 
>> <vcpu>. If set,
>> + *                                 this vector will be used in 
>> preference to the
>> + *                                 domain global callback via (see
>> + *                                 HVM_PARAM_CALLBACK_IRQ).
>> + */
> 
> Technically this hypercall is x86 specific. IOW, it would be possible 
> for another architecture to define 23 for something different.
> 
> If it is not possible (or desired) to surround with an #ifdef, then I 
> think we should at least be mentioned it in the comment.
In Xen it is surrounded with an #ifdef. I am happy to do so here too, 
unless there is any opposition.

Thank you,

Jane.

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.