Fix cache flush bug of cpu offline Current xen cpu offline logic flush cache too early, which potentially break cache coherency. wbinvd should be the last ops before cpu going into dead, otherwise cache may be dirty, i.e, something like setting an A bit on page tables. Pointed out by Arjan van de Ven. Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) if ( (cx = &power->states[power->count-1]) == NULL ) goto default_halt; + /* + * cache must be flashed as the last ops before cpu going into dead, + * otherwise, cpu may dead with dirty data breaking cache coherency, + * leading to strange errors. + */ + wbinvd(); for ( ; ; ) { - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) - ACPI_FLUSH_CPU_CACHE(); - switch ( cx->entry_method ) { case ACPI_CSTATE_EM_FFH: @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } default_halt: + wbinvd(); for ( ; ; ) halt(); } diff -r 2dc3c1cc1bba xen/arch/x86/domain.c --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 @@ -93,6 +93,12 @@ static void default_idle(void) static void default_dead_idle(void) { + /* + * cache must be flashed as the last ops before cpu going into dead, + * otherwise, cpu may dead with dirty data breaking cache coherency, + * leading to strange errors. + */ + wbinvd(); for ( ; ; ) halt(); } @@ -100,7 +106,6 @@ static void play_dead(void) static void play_dead(void) { local_irq_disable(); - wbinvd(); /* * NOTE: After cpu_exit_clear, per-cpu variables are no longer accessible, _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2011-Mar-11 16:26 UTC
[Xen-devel] Re: [PATCH] Fix cache flush bug of cpu offline
On 11/03/2011 14:34, "Liu, Jinsong" <jinsong.liu@intel.com> wrote:> Fix cache flush bug of cpu offline > > Current xen cpu offline logic flush cache too early, which potentially break > cache coherency. > wbinvd should be the last ops before cpu going into dead, otherwise cache may > be dirty, > i.e, something like setting an A bit on page tables. Pointed out by Arjan van > de Ven.The position still seems a bit arbitrary. In the first hunk below, why is it safe to wbinvd() outside the for-loop and before reading cx->entry_method, but not before reading from processor_powers[]? It would be neater if we could put the wbinvd() in a wrapper function for calling *dead_idle. -- Keir> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> > > diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c > --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 > +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 > @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) > if ( (cx = &power->states[power->count-1]) == NULL ) > goto default_halt; > > + /* > + * cache must be flashed as the last ops before cpu going into dead, > + * otherwise, cpu may dead with dirty data breaking cache coherency, > + * leading to strange errors. > + */ > + wbinvd(); > for ( ; ; ) > { > - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) > - ACPI_FLUSH_CPU_CACHE(); > - > switch ( cx->entry_method ) > { > case ACPI_CSTATE_EM_FFH: > @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) > } > > default_halt: > + wbinvd(); > for ( ; ; ) > halt(); > } > diff -r 2dc3c1cc1bba xen/arch/x86/domain.c > --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 > +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 > @@ -93,6 +93,12 @@ static void default_idle(void) > > static void default_dead_idle(void) > { > + /* > + * cache must be flashed as the last ops before cpu going into dead, > + * otherwise, cpu may dead with dirty data breaking cache coherency, > + * leading to strange errors. > + */ > + wbinvd(); > for ( ; ; ) > halt(); > } > @@ -100,7 +106,6 @@ static void play_dead(void) > static void play_dead(void) > { > local_irq_disable(); > - wbinvd(); > > /* > * NOTE: After cpu_exit_clear, per-cpu variables are no longer > accessible,_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Liu, Jinsong
2011-Mar-11 16:50 UTC
[Xen-devel] RE: [PATCH] Fix cache flush bug of cpu offline
Keir Fraser wrote:> On 11/03/2011 14:34, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: > >> Fix cache flush bug of cpu offline >> >> Current xen cpu offline logic flush cache too early, which >> potentially break cache coherency. wbinvd should be the last ops >> before cpu going into dead, otherwise cache may be dirty, i.e, >> something like setting an A bit on page tables. Pointed out by Arjan >> van de Ven. > > The position still seems a bit arbitrary. In the first hunk below, > why is it safe to wbinvd() outside the for-loop and before reading > cx->entry_method, but not before reading from processor_powers[]? It > would be neater if we could put the wbinvd() in a wrapper function > for calling *dead_idle. > > -- Keirwe did experiment, if did wbinvd at current position (at play_dead), sometimes it bring strange issue when repeatly cpu offline/online. so for cpu dead, the near wbinvd to last step, the safer. wbinvd would better be the last ops before cpu dead, to avoid potential cache coherency break. In fact, it can do wbinvd inside loop, but as cpu_offline_3.patch said, at Xen 7400 when hyperthreading, the offlined thread may be spuriously waken up by its brother, and frequently waken inside the dead loop. In such case, considering heavy workload of wbinvd, we add a light-weight clflush instruction inside loop. Thanks, Jinsong> >> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >> >> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >> if ( (cx = &power->states[power->count-1]) == NULL ) >> goto default_halt; >> >> + /* >> + * cache must be flashed as the last ops before cpu going into >> dead, + * otherwise, cpu may dead with dirty data breaking cache >> coherency, + * leading to strange errors. >> + */ >> + wbinvd(); >> for ( ; ; ) >> { >> - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) >> - ACPI_FLUSH_CPU_CACHE(); >> - >> switch ( cx->entry_method ) >> { >> case ACPI_CSTATE_EM_FFH: >> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >> >> default_halt: >> + wbinvd(); >> for ( ; ; ) >> halt(); >> } >> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >> @@ -93,6 +93,12 @@ static void default_idle(void) >> >> static void default_dead_idle(void) >> { >> + /* >> + * cache must be flashed as the last ops before cpu going into >> dead, + * otherwise, cpu may dead with dirty data breaking cache >> coherency, + * leading to strange errors. >> + */ >> + wbinvd(); >> for ( ; ; ) >> halt(); >> } >> @@ -100,7 +106,6 @@ static void play_dead(void) >> static void play_dead(void) >> { >> local_irq_disable(); >> - wbinvd(); >> >> /* >> * NOTE: After cpu_exit_clear, per-cpu variables are no longer >> accessible,_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Liu, Jinsong
2011-Mar-11 17:18 UTC
[Xen-devel] RE: [PATCH] Fix cache flush bug of cpu offline
BTW, some history coding here at kernel side: ----------------------------------- commit ce5f68246bf2385d6174856708d0b746dc378f20 Author: H. Peter Anvin <hpa@linux.intel.com> Date: Mon Sep 20 13:04:45 2010 -0700 x86, hotplug: In the MWAIT case of play_dead, CLFLUSH the cache line When we''re using MWAIT for play_dead, explicitly CLFLUSH the cache line before executing MONITOR. This is a potential workaround for the Xeon 7400 erratum AAI65 after having a spurious wakeup and returning around the loop. "Potential" here because it is not certain that that erratum could actually trigger; however, the CLFLUSH should be harmless. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Acked-by: Venkatesh Pallipadi <venki@google.com> Cc: Asit Mallick <asit.k.mallick@intel.com> Cc: Arjan van de Ven <arjan@linux.kernel.org> Cc: Len Brown <lenb@kernel.org> --------------------------------------- commit a68e5c94f7d3dd64fef34dd5d97e365cae4bb42a Author: H. Peter Anvin <hpa@linux.intel.com> Date: Fri Sep 17 17:06:46 2010 -0700 x86, hotplug: Move WBINVD back outside the play_dead loop On processors with hyperthreading, when only one thread is offlined the other thread can cause a spurious wakeup on the idled thread. We do not want to re-WBINVD when that happens. Ideally, we should simply skip WBINVD unless we''re the last thread on a particular core to shut down, but there might be similar issues elsewhere in the system. Thus, revert to previous behavior of only WBINVD outside the loop. Partly as a result, remove the mb()''s around it: they are not necessary since wbinvd() is a serializing instruction, but they were intended to make sure the compiler didn''t do any funny loop optimizations. Reported-by: Asit Mallick <asit.k.mallick@intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Cc: Arjan van de Ven <arjan@linux.kernel.org> Cc: Len Brown <lenb@kernel.org> Cc: Venkatesh Pallipadi <venki@google.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.hl> -------------------------------------- commit ea53069231f9317062910d6e772cca4ce93de8c8 Author: H. Peter Anvin <hpa@linux.intel.com> Date: Fri Sep 17 15:39:11 2010 -0700 x86, hotplug: Use mwait to offline a processor, fix the legacy case The code in native_play_dead() has a number of problems: 1. We should use MWAIT when available, to put ourselves into a deeper sleep state. 2. We use the existence of CLFLUSH to determine if WBINVD is safe, but that is totally bogus -- WBINVD is 486+, whereas CLFLUSH is a much later addition. 3. We should do WBINVD inside the loop, just in case of something like setting an A bit on page tables. Pointed out by Arjan van de Ven. This code is based in part of a previous patch by Venki Pallipadi, but unlike that patch this one keeps all the detection code local instead of pre-caching a bunch of information. We''re shutting down the CPU; there is absolutely no hurry. This patch moves all the code to C and deletes the global wbinvd_halt() which is broken anyway. Originally-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com> Reviewed-by: Arjan van de Ven <arjan@linux.intel.com> Cc: Len Brown <lenb@kernel.org> Cc: Venkatesh Pallipadi <venki@google.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.hl> --------------------------------------- Thanks, Jinsong Keir Fraser wrote:> On 11/03/2011 14:34, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: > >> Fix cache flush bug of cpu offline >> >> Current xen cpu offline logic flush cache too early, which >> potentially break cache coherency. wbinvd should be the last ops >> before cpu going into dead, otherwise cache may be dirty, i.e, >> something like setting an A bit on page tables. Pointed out by Arjan >> van de Ven. > > The position still seems a bit arbitrary. In the first hunk below, > why is it safe to wbinvd() outside the for-loop and before reading > cx->entry_method, but not before reading from processor_powers[]? It > would be neater if we could put the wbinvd() in a wrapper function > for calling *dead_idle. > > -- Keir > >> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >> >> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >> if ( (cx = &power->states[power->count-1]) == NULL ) >> goto default_halt; >> >> + /* >> + * cache must be flashed as the last ops before cpu going into >> dead, + * otherwise, cpu may dead with dirty data breaking cache >> coherency, + * leading to strange errors. >> + */ >> + wbinvd(); >> for ( ; ; ) >> { >> - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) >> - ACPI_FLUSH_CPU_CACHE(); >> - >> switch ( cx->entry_method ) >> { >> case ACPI_CSTATE_EM_FFH: >> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >> >> default_halt: >> + wbinvd(); >> for ( ; ; ) >> halt(); >> } >> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >> @@ -93,6 +93,12 @@ static void default_idle(void) >> >> static void default_dead_idle(void) >> { >> + /* >> + * cache must be flashed as the last ops before cpu going into >> dead, + * otherwise, cpu may dead with dirty data breaking cache >> coherency, + * leading to strange errors. >> + */ >> + wbinvd(); >> for ( ; ; ) >> halt(); >> } >> @@ -100,7 +106,6 @@ static void play_dead(void) >> static void play_dead(void) >> { >> local_irq_disable(); >> - wbinvd(); >> >> /* >> * NOTE: After cpu_exit_clear, per-cpu variables are no longer >> accessible,_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2011-Mar-11 17:29 UTC
[Xen-devel] Re: [PATCH] Fix cache flush bug of cpu offline
On 11/03/2011 16:50, "Liu, Jinsong" <jinsong.liu@intel.com> wrote:> we did experiment, if did wbinvd at current position (at play_dead), sometimes > it bring strange issue when repeatly cpu offline/online. > so for cpu dead, the near wbinvd to last step, the safer. > wbinvd would better be the last ops before cpu dead, to avoid potential cache > coherency break.Okay, I applied your patches. However in a follow-up patch (c/s 23025) I have removed the WBINVD instructions from the default paths (i.e., the HLT loops) as the CPU still does cache coherency while in HLT/C1 state. Does that look okay to you? -- Keir> In fact, it can do wbinvd inside loop, but as cpu_offline_3.patch said, > at Xen 7400 when hyperthreading, the offlined thread may be spuriously waken > up by its brother, and frequently waken inside the dead loop. > In such case, considering heavy workload of wbinvd, we add a light-weight > clflush instruction inside loop. > > Thanks, > Jinsong > > >> >>> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >>> >>> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >>> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >>> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >>> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >>> if ( (cx = &power->states[power->count-1]) == NULL ) >>> goto default_halt; >>> >>> + /* >>> + * cache must be flashed as the last ops before cpu going into >>> dead, + * otherwise, cpu may dead with dirty data breaking cache >>> coherency, + * leading to strange errors. >>> + */ >>> + wbinvd(); >>> for ( ; ; ) >>> { >>> - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) >>> - ACPI_FLUSH_CPU_CACHE(); >>> - >>> switch ( cx->entry_method ) >>> { >>> case ACPI_CSTATE_EM_FFH: >>> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >>> >>> default_halt: >>> + wbinvd(); >>> for ( ; ; ) >>> halt(); >>> } >>> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >>> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >>> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >>> @@ -93,6 +93,12 @@ static void default_idle(void) >>> >>> static void default_dead_idle(void) >>> { >>> + /* >>> + * cache must be flashed as the last ops before cpu going into >>> dead, + * otherwise, cpu may dead with dirty data breaking cache >>> coherency, + * leading to strange errors. >>> + */ >>> + wbinvd(); >>> for ( ; ; ) >>> halt(); >>> } >>> @@ -100,7 +106,6 @@ static void play_dead(void) >>> static void play_dead(void) >>> { >>> local_irq_disable(); >>> - wbinvd(); >>> >>> /* >>> * NOTE: After cpu_exit_clear, per-cpu variables are no longer >>> accessible, >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Liu, Jinsong
2011-Mar-11 17:53 UTC
[Xen-devel] RE: [PATCH] Fix cache flush bug of cpu offline
Keir Fraser wrote:> On 11/03/2011 16:50, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: > >> we did experiment, if did wbinvd at current position (at play_dead), >> sometimes it bring strange issue when repeatly cpu offline/online. >> so for cpu dead, the near wbinvd to last step, the safer. >> wbinvd would better be the last ops before cpu dead, to avoid >> potential cache coherency break. > > Okay, I applied your patches. However in a follow-up patch (c/s > 23025) I have removed the WBINVD instructions from the default paths > (i.e., the HLT loops) as the CPU still does cache coherency while in > HLT/C1 state. > > Does that look okay to you? > > -- KeirIt''s right that cpu continue snoop bus transaction to keep cache coherency when HLT/C1. However, I think it better not remove wbinvd from HLT loops. I''m not quite sure if ''enter Cx'' == ''cpu play dead''. After all, resume from Cx different from cpu booting: when cpu online, it start from SIPI-SIPI. I worried some unknown hardware behavior will bring issue if we treat ''cpu play dead'' totally same as ''enter Cx''. Maybe that''s the reason why kernel insist on reserveing wbinvd before HLT when play dead. Thanks, Jinsong> >> In fact, it can do wbinvd inside loop, but as cpu_offline_3.patch >> said, >> at Xen 7400 when hyperthreading, the offlined thread may be >> spuriously waken up by its brother, and frequently waken inside the >> dead loop. >> In such case, considering heavy workload of wbinvd, we add a >> light-weight clflush instruction inside loop. >> >> Thanks, >> Jinsong >> >> >>> >>>> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >>>> >>>> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >>>> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >>>> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >>>> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >>>> if ( (cx = &power->states[power->count-1]) == NULL ) >>>> goto default_halt; >>>> >>>> + /* >>>> + * cache must be flashed as the last ops before cpu going into >>>> dead, + * otherwise, cpu may dead with dirty data breaking >>>> cache coherency, + * leading to strange errors. >>>> + */ >>>> + wbinvd(); >>>> for ( ; ; ) >>>> { >>>> - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) >>>> - ACPI_FLUSH_CPU_CACHE(); >>>> - >>>> switch ( cx->entry_method ) >>>> { >>>> case ACPI_CSTATE_EM_FFH: >>>> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >>>> >>>> default_halt: >>>> + wbinvd(); >>>> for ( ; ; ) >>>> halt(); >>>> } >>>> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >>>> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >>>> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >>>> @@ -93,6 +93,12 @@ static void default_idle(void) >>>> >>>> static void default_dead_idle(void) >>>> { >>>> + /* >>>> + * cache must be flashed as the last ops before cpu going into >>>> dead, + * otherwise, cpu may dead with dirty data breaking >>>> cache coherency, + * leading to strange errors. >>>> + */ >>>> + wbinvd(); >>>> for ( ; ; ) >>>> halt(); >>>> } >>>> @@ -100,7 +106,6 @@ static void play_dead(void) >>>> static void play_dead(void) >>>> { >>>> local_irq_disable(); >>>> - wbinvd(); >>>> >>>> /* >>>> * NOTE: After cpu_exit_clear, per-cpu variables are no longer >>>> accessible,_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2011-Mar-11 19:10 UTC
[Xen-devel] Re: [PATCH] Fix cache flush bug of cpu offline
On 11/03/2011 17:53, "Liu, Jinsong" <jinsong.liu@intel.com> wrote:> Keir Fraser wrote: >> On 11/03/2011 16:50, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: >> >>> we did experiment, if did wbinvd at current position (at play_dead), >>> sometimes it bring strange issue when repeatly cpu offline/online. >>> so for cpu dead, the near wbinvd to last step, the safer. >>> wbinvd would better be the last ops before cpu dead, to avoid >>> potential cache coherency break. >> >> Okay, I applied your patches. However in a follow-up patch (c/s >> 23025) I have removed the WBINVD instructions from the default paths >> (i.e., the HLT loops) as the CPU still does cache coherency while in >> HLT/C1 state. >> >> Does that look okay to you? >> >> -- Keir > > It''s right that cpu continue snoop bus transaction to keep cache coherency > when HLT/C1. > > However, I think it better not remove wbinvd from HLT loops. > I''m not quite sure if ''enter Cx'' == ''cpu play dead''. After all, resume from Cx > different from cpu booting: when cpu online, it start from SIPI-SIPI. > I worried some unknown hardware behavior will bring issue if we treat ''cpu > play dead'' totally same as ''enter Cx''. > Maybe that''s the reason why kernel insist on reserveing wbinvd before HLT when > play dead.An APIC INIT doesn''t touch the memory hierarchy, cache controls, nor CR0.CD and CR0.NW. The care over cache invalidation I believe solely comes down to the deep sleep that the CPU can be placed into via MWAIT, in which the cache-control logic gets switched off. -- Keir> Thanks, > Jinsong > >> >>> In fact, it can do wbinvd inside loop, but as cpu_offline_3.patch >>> said, >>> at Xen 7400 when hyperthreading, the offlined thread may be >>> spuriously waken up by its brother, and frequently waken inside the >>> dead loop. >>> In such case, considering heavy workload of wbinvd, we add a >>> light-weight clflush instruction inside loop. >>> >>> Thanks, >>> Jinsong >>> >>> >>>> >>>>> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >>>>> >>>>> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >>>>> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >>>>> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >>>>> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >>>>> if ( (cx = &power->states[power->count-1]) == NULL ) >>>>> goto default_halt; >>>>> >>>>> + /* >>>>> + * cache must be flashed as the last ops before cpu going into >>>>> dead, + * otherwise, cpu may dead with dirty data breaking >>>>> cache coherency, + * leading to strange errors. >>>>> + */ >>>>> + wbinvd(); >>>>> for ( ; ; ) >>>>> { >>>>> - if ( !power->flags.bm_check && cx->type == ACPI_STATE_C3 ) >>>>> - ACPI_FLUSH_CPU_CACHE(); >>>>> - >>>>> switch ( cx->entry_method ) >>>>> { >>>>> case ACPI_CSTATE_EM_FFH: >>>>> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >>>>> >>>>> default_halt: >>>>> + wbinvd(); >>>>> for ( ; ; ) >>>>> halt(); >>>>> } >>>>> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >>>>> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >>>>> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >>>>> @@ -93,6 +93,12 @@ static void default_idle(void) >>>>> >>>>> static void default_dead_idle(void) >>>>> { >>>>> + /* >>>>> + * cache must be flashed as the last ops before cpu going into >>>>> dead, + * otherwise, cpu may dead with dirty data breaking >>>>> cache coherency, + * leading to strange errors. >>>>> + */ >>>>> + wbinvd(); >>>>> for ( ; ; ) >>>>> halt(); >>>>> } >>>>> @@ -100,7 +106,6 @@ static void play_dead(void) >>>>> static void play_dead(void) >>>>> { >>>>> local_irq_disable(); >>>>> - wbinvd(); >>>>> >>>>> /* >>>>> * NOTE: After cpu_exit_clear, per-cpu variables are no longer >>>>> accessible, >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Liu, Jinsong
2011-Mar-11 19:44 UTC
[Xen-devel] RE: [PATCH] Fix cache flush bug of cpu offline
Keir Fraser wrote:> On 11/03/2011 17:53, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: > >> Keir Fraser wrote: >>> On 11/03/2011 16:50, "Liu, Jinsong" <jinsong.liu@intel.com> wrote: >>> >>>> we did experiment, if did wbinvd at current position (at >>>> play_dead), sometimes it bring strange issue when repeatly cpu >>>> offline/online. so for cpu dead, the near wbinvd to last step, the >>>> safer. >>>> wbinvd would better be the last ops before cpu dead, to avoid >>>> potential cache coherency break. >>> >>> Okay, I applied your patches. However in a follow-up patch (c/s >>> 23025) I have removed the WBINVD instructions from the default paths >>> (i.e., the HLT loops) as the CPU still does cache coherency while >>> in HLT/C1 state. >>> >>> Does that look okay to you? >>> >>> -- Keir >> >> It''s right that cpu continue snoop bus transaction to keep cache >> coherency when HLT/C1. >> >> However, I think it better not remove wbinvd from HLT loops. >> I''m not quite sure if ''enter Cx'' == ''cpu play dead''. After all, >> resume from Cx different from cpu booting: when cpu online, it start >> from SIPI-SIPI. >> I worried some unknown hardware behavior will bring issue if we >> treat ''cpu play dead'' totally same as ''enter Cx''. >> Maybe that''s the reason why kernel insist on reserveing wbinvd >> before HLT when play dead. > > An APIC INIT doesn''t touch the memory hierarchy, cache controls, nor > CR0.CD and CR0.NW. The care over cache invalidation I believe solely > comes down to the deep sleep that the CPU can be placed into via > MWAIT, in which the cache-control logic gets switched off. > > -- KeirReasonable ot me, thanks! Jinsong> >> Thanks, >> Jinsong >> >>> >>>> In fact, it can do wbinvd inside loop, but as cpu_offline_3.patch >>>> said, at Xen 7400 when hyperthreading, the offlined thread may be >>>> spuriously waken up by its brother, and frequently waken inside >>>> the dead loop. In such case, considering heavy workload of wbinvd, >>>> we add a light-weight clflush instruction inside loop. >>>> >>>> Thanks, >>>> Jinsong >>>> >>>> >>>>> >>>>>> Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> >>>>>> >>>>>> diff -r 2dc3c1cc1bba xen/arch/x86/acpi/cpu_idle.c >>>>>> --- a/xen/arch/x86/acpi/cpu_idle.c Mon Mar 07 05:31:46 2022 +0800 >>>>>> +++ b/xen/arch/x86/acpi/cpu_idle.c Thu Mar 10 23:40:51 2022 +0800 >>>>>> @@ -562,11 +562,14 @@ static void acpi_dead_idle(void) >>>>>> if ( (cx = &power->states[power->count-1]) == NULL ) >>>>>> goto default_halt; >>>>>> >>>>>> + /* >>>>>> + * cache must be flashed as the last ops before cpu going >>>>>> into dead, + * otherwise, cpu may dead with dirty data >>>>>> breaking cache coherency, + * leading to strange errors. + >>>>>> */ + wbinvd(); >>>>>> for ( ; ; ) >>>>>> { >>>>>> - if ( !power->flags.bm_check && cx->type =>>>>>> ACPI_STATE_C3 ) >>>>>> - ACPI_FLUSH_CPU_CACHE(); >>>>>> - >>>>>> switch ( cx->entry_method ) >>>>>> { >>>>>> case ACPI_CSTATE_EM_FFH: >>>>>> @@ -584,6 +587,7 @@ static void acpi_dead_idle(void) } >>>>>> >>>>>> default_halt: >>>>>> + wbinvd(); >>>>>> for ( ; ; ) >>>>>> halt(); >>>>>> } >>>>>> diff -r 2dc3c1cc1bba xen/arch/x86/domain.c >>>>>> --- a/xen/arch/x86/domain.c Mon Mar 07 05:31:46 2022 +0800 >>>>>> +++ b/xen/arch/x86/domain.c Thu Mar 10 23:40:51 2022 +0800 >>>>>> @@ -93,6 +93,12 @@ static void default_idle(void) >>>>>> >>>>>> static void default_dead_idle(void) >>>>>> { >>>>>> + /* >>>>>> + * cache must be flashed as the last ops before cpu going >>>>>> into dead, + * otherwise, cpu may dead with dirty data >>>>>> breaking cache coherency, + * leading to strange errors. + >>>>>> */ + wbinvd(); >>>>>> for ( ; ; ) >>>>>> halt(); >>>>>> } >>>>>> @@ -100,7 +106,6 @@ static void play_dead(void) >>>>>> static void play_dead(void) >>>>>> { >>>>>> local_irq_disable(); >>>>>> - wbinvd(); >>>>>> >>>>>> /* >>>>>> * NOTE: After cpu_exit_clear, per-cpu variables are no >>>>>> longer accessible,_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel