linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Preeti U Murthy <preeti@linux.vnet.ibm.com>
To: kernelfans@gmail.com, linuxppc-dev@lists.ozlabs.org,
	kvm-ppc@vger.kernel.org
Cc: Paul Mackerras <paulus@samba.org>, Alexander Graf <agraf@suse.de>
Subject: Re: [RFC 07/11] powerpc: kvm: the stopper func to cease secondary hwthread
Date: Mon, 27 Oct 2014 11:37:37 +0530	[thread overview]
Message-ID: <544DE129.6010104@linux.vnet.ibm.com> (raw)
In-Reply-To: <1413487800-7162-8-git-send-email-kernelfans@gmail.com>

On 10/17/2014 12:59 AM, kernelfans@gmail.com wrote:
> To enter guest, primary hwtherad schedules the stopper func on
> secondary threads and force them into NAP mode.
> When exit to host,secondary threads hardcode to restore the stack,
> then switch back to the stopper func, i.e host.
> 
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  arch/powerpc/kvm/book3s_hv.c            | 15 +++++++++++++++
>  arch/powerpc/kvm/book3s_hv_rmhandlers.S | 34 +++++++++++++++++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index ba258c8..4348abd 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -1486,6 +1486,21 @@ static void kvmppc_remove_runnable(struct kvmppc_vcore *vc,
>  	list_del(&vcpu->arch.run_list);
>  }
>  
> +#ifdef KVMPPC_ENABLE_SECONDARY
> +
> +extern void kvmppc_secondary_stopper_enter();
> +
> +static int kvmppc_secondary_stopper(void *data)
> +{
> +	int cpu =smp_processor_id();
> +	struct paca_struct *lpaca = get_paca();
> +	BUG_ON(!(cpu%thread_per_core));
> +
> +	kvmppc_secondary_stopper_enter();
> +}
> +
> +#endif
> +
>  static int kvmppc_grab_hwthread(int cpu)
>  {
>  	struct paca_struct *tpaca;
> diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> index d5594b0..254038b 100644
> --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> @@ -349,7 +349,41 @@ kvm_do_nap:
>  
>  #ifdef PPCKVM_ENABLE_SECONDARY
>  kvm_secondary_exit_trampoline:
> +
> +	/* all register is free to use, later kvmppc_secondary_stopper_exit set up them*/
> +	//loop-wait for the primary to signal that host env is ready
> +
> +	LOAD_REG_ADDR(r5, kvmppc_secondary_stopper_exit)
> +	/* fixme, load msr from lpaca stack */
> +	li	r6, MSR_IR | MSR_DR
> +	mtsrr0	r5
> +	mtsrr1	r6
> +	RFI
> +
> +_GLOBAL_TOC(kvmppc_secondary_stopper_enter)
> +	mflr	r0
> +	std	r0, PPC_LR_STKOFF(r1)
> +	stdu	r1, -112(r1)
> +
> +	/* fixme: store other register such as msr */
> +
> +	/* prevent us to enter kernel */
> +	li	r0, 1
> +	stb	r0, HSTATE_HWTHREAD_REQ(r13)
> +	/* tell the primary that we are ready */
> +        li      r0,KVM_HWTHREAD_IN_KERNEL
> +        stb     r0,HSTATE_HWTHREAD_STATE(r13)
> +	nap
>  	b	.

I see a fundamental issues with this design. Note that the secondaries
are still capable of getting IPIs, timer interrupts and scheduler
interrupts in nap. Scheduling ticks do not get stopped just because we
nap. So the primary thread cannot assume that the secondaries will wait
in nap until it has switched to guest context. There will definitely be
race conditions here between primary switching context and the secondary
handling some interrupt in virtual mode.

So your answer to above could be that we are preventing the secondaries
from entering the kernel by setting the HSTATE_HWTHREAD_REQ above. But
we cannot do this because the secondary thread is as alive and kicking
as the primary thread on the host. There can be hrtimers queued, there
may be an IPI from a thread in another core. We cannot ignore handling
them while we wait for the primary thread to switch context.

There is also a bug as far as I can see with having a b . after nap. I
mentioned that in one of my earlier replies to this patch.


Regards
Preeti U Murthy
> +
> +/* enter with vmode */
> +kvmppc_secondary_stopper_exit:
> +	/* fixme, restore the stack which we store on lpaca */
> +
> +	ld	r0, 112+PPC_LR_STKOFF(r1)
> +	addi	r1, r1, 112
> +	mtlr	r0
> +	blr
>  #endif
>  
>  /******************************************************************************
> 

  parent reply	other threads:[~2014-10-27  6:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-16 19:29 [RFC 00/11]: powerKVM, release the compute power of secondary hwthread on host kernelfans
2014-10-16 19:29 ` [RFC 01/11] sched: introduce sys_cpumask in tsk to adapt asymmetric system kernelfans
2014-11-12  9:22   ` Srikar Dronamraju
2014-11-18  5:07     ` Liu ping fan
2014-10-16 19:29 ` [RFC 02/11] powerpc: kvm: ensure vcpu-thread run only on primary hwthread kernelfans
2014-11-12 10:17   ` Srikar Dronamraju
2014-10-16 19:29 ` [RFC 03/11] powerpc: kvm: add interface to control kvm function on a core kernelfans
2014-10-27  4:04   ` Preeti U Murthy
2014-11-18  5:17     ` Liu ping fan
2014-11-12 13:01   ` Srikar Dronamraju
2014-10-16 19:29 ` [RFC 04/11] powerpc: kvm: introduce a kthread on primary thread to anti tickless kernelfans
2014-10-27  4:45   ` Preeti U Murthy
2014-11-18  5:24     ` Liu ping fan
2014-10-16 19:29 ` [RFC 05/11] sched: introduce stop_cpus_async() to schedule special tsk on cpu kernelfans
2014-10-16 19:29 ` [RFC 06/11] powerpc: kvm: introduce online in paca to indicate whether cpu is needed by host kernelfans
2014-10-27  5:32   ` Preeti U Murthy
2014-11-18  5:29     ` Liu ping fan
2014-10-16 19:29 ` [RFC 07/11] powerpc: kvm: the stopper func to cease secondary hwthread kernelfans
2014-10-22  7:12   ` Preeti U Murthy
2014-10-27  6:07   ` Preeti U Murthy [this message]
2014-10-16 19:29 ` [RFC 08/11] powerpc: kvm: add a flag in vcore to sync primary with secondry hwthread kernelfans
2014-10-27  6:28   ` Preeti U Murthy
2014-10-16 19:29 ` [RFC 09/11] powerpc: kvm: handle time base on secondary hwthread kernelfans
2014-10-27  6:40   ` Preeti U Murthy
2014-11-18  5:43     ` Liu ping fan
2014-10-16 19:29 ` [RFC 10/11] powerpc: kvm: on_primary_thread() force the secondary threads into NAP mode kernelfans
2014-10-16 19:30 ` [RFC 11/11] powerpc: kvm: Kconfig add an option for enabling secondary hwthread kernelfans
2014-10-27  6:44   ` Preeti U Murthy
2014-11-18  5:47     ` Liu ping fan
2014-11-18 17:54 ` [RFC 00/11]: powerKVM, release the compute power of secondary hwthread on host Alexander Graf

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=544DE129.6010104@linux.vnet.ibm.com \
    --to=preeti@linux.vnet.ibm.com \
    --cc=agraf@suse.de \
    --cc=kernelfans@gmail.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).