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

Re: [RESEND][PATCH] xen/arm: sched: Ensure the vCPU context is seen before vcpu_pause() returns


  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 23 Sep 2020 11:08:23 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.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-SenderADCheck; bh=X93lwwNey1L0K7fYhSn92oGBlQJ/ExKpW1zwjlRoVr8=; b=aTYiPXfYq763VRpRzvczBoMDnKsszFYr1O/EtQBIIdXX1scvrPT8ZxWOCbd2LqMtFjNMtC+r+PKqpnvwrd5Nk/hMmwJGkm2+8pUE+/4ECK4Hc2JAqngoyJbLfL1ZeWJrb+ilBlnIV+AcMq4yCNP10FCcIHb/ZbECalRSLcF44b9UU6ToW3aDiQGVc56Or861VN9/udLEYya1AFST1+V9kCF7frImtcafAlZLLT15I9GWecfrENmSKljaxJ3o8A2dLMNZ5OBvbKAW6BkZm4Yol82KigFtkn5i3az4dchesZ5/gurm62YCRFRXpVtZ7L7q88UklKlYSe/0nrBJ18KCsA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f9KAriQMZFM1FggoOJMy2XgJsl2kTdPMeeOvcwFUCq+zARkU6VfyFwyvHyXAoJE2lblv8faL15nEYLiEqmWhPVtso5fRBiR3L3WM3BnCQlN1lmqpsCZCIr7YdF+f5FoYT+7oQyTgLOlm7cCAYLRB0hfaOlJu88bsPaqFDyr+hRAOhFG56LT9w5iRjat+4g1C/sVfjeOn2yqNrybaS7DwZDIGdO2yejEKx6WpG22qHeHqxH1dFXxyxpLsDtCsQ7LorSZx+o6Bkudr9+cTVTtj05QwxDkh607T/fbPToRYdmcB7vofQ3br/7yKL+znlh8aMr6PyDJkA0TwLbu4MIvQ2A==
  • Authentication-results-original: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Cc: "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Julien Grall <jgrall@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>
  • Delivery-date: Wed, 23 Sep 2020 11:08:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHWkRb3YbUANCat5069iZiL+rQxOal2EYaA
  • Thread-topic: [RESEND][PATCH] xen/arm: sched: Ensure the vCPU context is seen before vcpu_pause() returns

Hi Julien,

> On 22 Sep 2020, at 20:31, Julien Grall <julien@xxxxxxx> wrote:
> 
> From: Julien Grall <jgrall@xxxxxxxxxx>
> 
> Some callers of vcpu_pause() will expect to access the latest vcpu
> context when the function returns (see XENDOMCTL_{set,get}vcpucontext}.
> 
> However, the latest vCPU context can only be observed after
> v->is_running has been observed to be false.
> 
> As there is no memory barrier instruction generated, a processor could
> try to speculatively access the vCPU context before it was observed.

The function vcpu_context_saved does contain a memory barrier already.

Shouldn’t we make sure instead that any time is_running is modified to
false there is a barrier before (which is the case in vcpu_context_saved) ?

I understand the goal here but the barrier seem very far from the modification
of is_running.

Cheers,
Bertrand

> 
> To prevent the corruption of the vCPU context, we need to insert a
> memory barrier instruction after v->is_running is observed and before
> the context is accessed. This barrier is added in sync_vcpu_execstate()
> as it seems to be the place where we expect the synchronization to
> happen.
> 
> Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>
> 
> ---
> 
> Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Cc: Jan Beulich <jbeulich@xxxxxxxx>
> Cc: George Dunlap <george.dunlap@xxxxxxxxxx>
> Cc: Dario Faggioli <dfaggioli@xxxxxxxx>
> Cc: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
> 
> I am also adding the x86 and scheduler maintainers because I am not sure
> whether this barrier should be part of the common code instead.
> ---
> xen/arch/arm/domain.c | 15 ++++++++++++++-
> 1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
> index 9258f6d3faa2..3b37f899b9da 100644
> --- a/xen/arch/arm/domain.c
> +++ b/xen/arch/arm/domain.c
> @@ -371,7 +371,20 @@ void sync_local_execstate(void)
> 
> void sync_vcpu_execstate(struct vcpu *v)
> {
> -    /* Nothing to do -- no lazy switching */
> +    /*
> +     * We don't support lazy switching.
> +     *
> +     * However the context may have been saved from a remote pCPU so we
> +     * need a barrier to ensure it is observed before continuing.
> +     *
> +     * Per vcpu_context_saved(), the context can be observed when
> +     * v->is_running is false (the caller should check it before calling
> +     * this function).
> +     *
> +     * Note this is a full barrier to also prevent update of the context
> +     * to happen before it was observed.
> +     */
> +    smp_mb();
> }
> 
> #define NEXT_ARG(fmt, args)                                                 \
> -- 
> 2.17.1
> 


 


Rackspace

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