From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
x86@kernel.org, Boris Ostrovsky <boris.ostrovsky@oracle.com>,
David Vrabel <david.vrabel@citrix.com>,
Juergen Gross <jgross@suse.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Jan Beulich <JBeulich@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Steve Capper <Steve.Capper@arm.com>, Wei Chen <Wei.Chen@arm.com>,
Kaly Xin <Kaly.Xin@arm.com>
Subject: Re: [PATCH linux v3 3/9] xen: introduce xen_vcpu_id mapping
Date: Tue, 06 Sep 2016 10:31:18 +0200 [thread overview]
Message-ID: <87d1khv38p.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1609051213470.4105@sstabellini-ThinkPad-X260> (Stefano Stabellini's message of "Mon, 5 Sep 2016 12:20:50 -0700 (PDT)")
Stefano Stabellini <sstabellini@kernel.org> writes:
> On Mon, 5 Sep 2016, Vitaly Kuznetsov wrote:
>> Julien Grall <julien.grall@arm.com> writes:
>>
>> > Hi Vitaly,
>> >
>> > On 26/07/16 13:30, Vitaly Kuznetsov wrote:
>> >> It may happen that Xen's and Linux's ideas of vCPU id diverge. In
>> >> particular, when we crash on a secondary vCPU we may want to do kdump
>> >> and unlike plain kexec where we do migrate_to_reboot_cpu() we try booting
>> >> on the vCPU which crashed. This doesn't work very well for PVHVM guests as
>> >> we have a number of hypercalls where we pass vCPU id as a parameter. These
>> >> hypercalls either fail or do something unexpected. To solve the issue
>> >> introduce percpu xen_vcpu_id mapping. ARM and PV guests get direct mapping
>> >> for now. Boot CPU for PVHVM guest gets its id from CPUID. With secondary
>> >> CPUs it is a bit more trickier. Currently, we initialize IPI vectors
>> >> before these CPUs boot so we can't use CPUID. Use ACPI ids from MADT
>> >> instead.
>> >>
>> >> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> >> ---
>> >> Changes since v2:
>> >> - Use uint32_t for xen_vcpu_id mapping [Julien Grall]
>> >>
>> >> Changes since v1:
>> >> - Introduce xen_vcpu_nr() helper [David Vrabel]
>> >> - Use ACPI ids instead of vLAPIC ids /2 [Andrew Cooper, Jan Beulich]
>> >> ---
>> >> arch/arm/xen/enlighten.c | 10 ++++++++++
>> >> arch/x86/xen/enlighten.c | 23 ++++++++++++++++++++++-
>> >> include/xen/xen-ops.h | 6 ++++++
>> >> 3 files changed, 38 insertions(+), 1 deletion(-)
>> >>
>> >> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
>> >> index 75cd734..fe32267 100644
>> >> --- a/arch/arm/xen/enlighten.c
>> >> +++ b/arch/arm/xen/enlighten.c
>> >> @@ -46,6 +46,10 @@ struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
>> >> DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
>> >> static struct vcpu_info __percpu *xen_vcpu_info;
>> >>
>> >> +/* Linux <-> Xen vCPU id mapping */
>> >> +DEFINE_PER_CPU(uint32_t, xen_vcpu_id) = U32_MAX;
>> >> +EXPORT_PER_CPU_SYMBOL(xen_vcpu_id);
>> >> +
>> >> /* These are unused until we support booting "pre-ballooned" */
>> >> unsigned long xen_released_pages;
>> >> struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata;
>> >> @@ -179,6 +183,9 @@ static void xen_percpu_init(void)
>> >> pr_info("Xen: initializing cpu%d\n", cpu);
>> >> vcpup = per_cpu_ptr(xen_vcpu_info, cpu);
>> >>
>> >> + /* Direct vCPU id mapping for ARM guests. */
>> >> + per_cpu(xen_vcpu_id, cpu) = cpu;
>> >> +
>> >
>> > We did some internal testing on ARM64 with the latest Linux kernel
>> > (4.8-rc4) and noticed that this patch is breaking SMP support. Sorry
>> > for noticing the issue that late.
>>
>> Sorry for the breakage :-(
>>
>> >
>> > This function is called on the running CPU whilst some code (e.g
>> > init_control_block in drivers/xen/events/events_fifo.c) is executed
>> > whilst preparing the CPU on the boot CPU.
>> >
>> > So xen_vcpu_nr(cpu) will always return 0 in this case and
>> > init_control_block will fail to execute.
>> >
>>
>> I see,
>>
>> CPU_UP_PREPARE event happens before xen_starting_cpu() is called.
>>
>>
>> > I am not sure how to fix. I guess we could setup per_cpu(xen_vcpu_id,
>> > *) in xen_guest_init. Any opinions?
>>
>> As we're not doing kexec on ARM we can fix the immediate issue. I don't
>> know much about ARM and unfortunatelly I don't have a setup to test but
>> it seems there is no early_per_cpu* infrastructure for ARM so we may fix
>> it with the following:
>>
>> diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c
>> index 3d2cef6..f193414 100644
>> --- a/arch/arm/xen/enlighten.c
>> +++ b/arch/arm/xen/enlighten.c
>> @@ -170,9 +170,6 @@ static int xen_starting_cpu(unsigned int cpu)
>> pr_info("Xen: initializing cpu%d\n", cpu);
>> vcpup = per_cpu_ptr(xen_vcpu_info, cpu);
>>
>> - /* Direct vCPU id mapping for ARM guests. */
>> - per_cpu(xen_vcpu_id, cpu) = cpu;
>> -
>> info.mfn = virt_to_gfn(vcpup);
>> info.offset = xen_offset_in_page(vcpup);
>>
>> @@ -330,6 +327,7 @@ static int __init xen_guest_init(void)
>> {
>> struct xen_add_to_physmap xatp;
>> struct shared_info *shared_info_page = NULL;
>> + int cpu;
>>
>> if (!xen_domain())
>> return 0;
>> @@ -380,7 +378,8 @@ static int __init xen_guest_init(void)
>> return -ENOMEM;
>>
>> /* Direct vCPU id mapping for ARM guests. */
>> - per_cpu(xen_vcpu_id, 0) = 0;
>> + for_each_possible_cpu(cpu)
>> + per_cpu(xen_vcpu_id, cpu) = cpu;
>>
>> xen_auto_xlat_grant_frames.count = gnttab_max_grant_frames();
>> if (xen_xlate_map_ballooned_pages(&xen_auto_xlat_grant_frames.pfn,
>>
>> (not tested, if we can't use for_each_possible_cpu() that early we'll
>> have to check against NR_CPUS instead).
>
> Kind of defeat the purpose of xen_vcpu_id, but I guess it should work.
>
>> But unfortunatelly we'll have to get back to this in future. Turns out
>> we need to know Xen's idea of vCPU id _before_ this vCPU starts
>> executing code.
>
> Why?
E.g. for FIFO event channels we currently call
evtchn_fifo_cpu_notification() for CPU_UP_PREPARE event (and do a
hypercall which requires us to know vcpu id) and this happens before the
secodary cpu starts. I'm not sure this can't be changed in future.
>
>> On x86 we used ACPI_ID from MADT. Is there anything like
>> it on ARM?
>
> MPIDR:
>
> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0388e/CIHEBGFG.html
>
Thanks, but doesn't it work the same way CPUID instruction works? In
that case we won't be able to use it to figure out other CPU's id.
> But first we should formally document the relationship between MPIDR and
> vcpu id.
Of course.
--
Vitaly
next prev parent reply other threads:[~2016-09-06 8:31 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-26 12:30 [PATCH linux v3 0/9] xen: pvhvm: support bootup on secondary vCPUs Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 1/9] x86/xen: update cpuid.h from Xen-4.7 Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 2/9] x86/acpi: store ACPI ids from MADT for future usage Vitaly Kuznetsov
2017-03-01 19:54 ` Thomas Gleixner
2017-03-01 19:54 ` Thomas Gleixner
2017-03-01 22:04 ` Boris Ostrovsky
2017-03-01 22:04 ` Boris Ostrovsky
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 3/9] xen: introduce xen_vcpu_id mapping Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-09-02 15:29 ` Julien Grall
2016-09-04 21:12 ` Boris Ostrovsky
2016-09-04 21:12 ` Boris Ostrovsky
2016-09-05 9:42 ` Vitaly Kuznetsov
2016-09-05 9:42 ` Vitaly Kuznetsov
2016-09-05 19:20 ` Stefano Stabellini
2016-09-05 19:20 ` Stefano Stabellini
2016-09-06 8:31 ` Vitaly Kuznetsov [this message]
2016-09-06 18:09 ` Stefano Stabellini
2016-09-07 9:07 ` Vitaly Kuznetsov
2016-09-07 9:10 ` David Vrabel
2016-09-07 9:10 ` David Vrabel
2016-09-07 9:35 ` Julien Grall
2016-09-07 11:23 ` Vitaly Kuznetsov
2016-09-07 11:23 ` Vitaly Kuznetsov
2016-09-07 12:55 ` Julien Grall
2016-09-07 12:55 ` Julien Grall
2016-09-07 9:35 ` Julien Grall
2016-09-07 9:07 ` Vitaly Kuznetsov
2016-09-06 18:09 ` Stefano Stabellini
2016-09-06 8:31 ` Vitaly Kuznetsov
2016-09-08 6:29 ` Wei Chen
2016-09-08 6:29 ` Wei Chen
2016-09-02 15:29 ` Julien Grall
2016-07-26 12:30 ` [PATCH linux v3 4/9] x86/xen: use xen_vcpu_id mapping for HYPERVISOR_vcpu_op Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 5/9] x86/xen: use xen_vcpu_id mapping when pointing vcpu_info to the shared_info page Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 6/9] xen/events: use xen_vcpu_id mapping in events_base Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 7/9] xen/events: fifo: use xen_vcpu_id mapping Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 8/9] xen/evtchn: " Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 12:30 ` [PATCH linux v3 9/9] xen/pvhvm: run xen_vcpu_setup() for the boot CPU Vitaly Kuznetsov
2016-07-26 12:30 ` Vitaly Kuznetsov
2016-07-26 13:02 ` [Xen-devel] [PATCH linux v3 0/9] xen: pvhvm: support bootup on secondary vCPUs David Vrabel
2016-07-26 13:19 ` Vitaly Kuznetsov
2016-07-26 13:19 ` [Xen-devel] " Vitaly Kuznetsov
2016-07-26 17:36 ` Stefano Stabellini
2016-07-27 9:11 ` Vitaly Kuznetsov
2016-07-27 9:11 ` [Xen-devel] " Vitaly Kuznetsov
2016-07-26 17:36 ` Stefano Stabellini
2016-07-26 13:02 ` David Vrabel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d1khv38p.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=JBeulich@suse.com \
--cc=Kaly.Xin@arm.com \
--cc=Steve.Capper@arm.com \
--cc=Wei.Chen@arm.com \
--cc=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=david.vrabel@citrix.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=julien.grall@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=sstabellini@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.