From patchwork Wed Apr 30 19:15:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 29443 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 05F57202FE for ; Wed, 30 Apr 2014 19:18:04 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id l6sf6938244qcy.7 for ; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-post:list-help :list-subscribe:mime-version:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive :content-type:content-transfer-encoding; bh=VOCbnD7MRc4w9GYOkpJKs/TgDPsJ4SiqfieA1Ite/bM=; b=kzJXm1i53CVUX074w7UAvrsseewt2MoCPvbPIj/1gZZr/wP3WgUJrcDbsOeaKLhTdp 5mL7wyn9VhRGrq01sB38eqnV26c/kxG7nLF8LNPuu6dQHOUX0hwqy+LgqBbMuK5cj7qc Hb++XmIlx+OwRE3ZtEk5E+qah5YqYQ7nSMjugGGVCQjZiul6NCqDkPQnBplXTnK2ekY3 zvErkl5YhYAWypiWXPQP8Pctb3KD47qGoa9SVWzB8TIe7/4+Y2Pqqp325szYhqVLriDx vYosR2uAsfqX/eL3ZGkW+yEs6iUEqmtDLCvJwiL6k7ngRaEs5u3fHP9x9qyq/aXBJbx9 MHnA== X-Gm-Message-State: ALoCoQnKJVPeGjFukEh8UES1rRyHaSxbL57ox1i6Shf0LntkjtzGuIFgTstUtgVecXD8ew+QCr1h X-Received: by 10.236.32.236 with SMTP id o72mr2851304yha.42.1398885484596; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.82 with SMTP id u76ls657131qgu.61.gmail; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) X-Received: by 10.58.74.38 with SMTP id q6mr4849030vev.7.1398885484385; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id u5si5525980vdo.166.2014.04.30.12.18.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 12:18:04 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so2712487veb.22 for ; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) X-Received: by 10.52.142.10 with SMTP id rs10mr4064367vdb.3.1398885484307; Wed, 30 Apr 2014 12:18:04 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp303711vcb; Wed, 30 Apr 2014 12:18:03 -0700 (PDT) X-Received: by 10.224.51.2 with SMTP id b2mr8038975qag.49.1398885481283; Wed, 30 Apr 2014 12:18:01 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id s6si11589034qaj.269.2014.04.30.12.18.00 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 30 Apr 2014 12:18:01 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WfZzB-0007bi-Ov; Wed, 30 Apr 2014 19:16:05 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WfZzA-0007bb-6B for xen-devel@lists.xenproject.org; Wed, 30 Apr 2014 19:16:04 +0000 Received: from [85.158.143.35:60315] by server-1.bemta-4.messagelabs.com id 5D/2D-09853-3FB41635; Wed, 30 Apr 2014 19:16:03 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-5.tower-21.messagelabs.com!1398885362!2085817!1 X-Originating-IP: [74.125.83.43] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29064 invoked from network); 30 Apr 2014 19:16:02 -0000 Received: from mail-ee0-f43.google.com (HELO mail-ee0-f43.google.com) (74.125.83.43) by server-5.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 30 Apr 2014 19:16:02 -0000 Received: by mail-ee0-f43.google.com with SMTP id e51so1717457eek.2 for ; Wed, 30 Apr 2014 12:16:02 -0700 (PDT) X-Received: by 10.14.179.193 with SMTP id h41mr5957283eem.27.1398885362323; Wed, 30 Apr 2014 12:16:02 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id 4sm70146769eeq.33.2014.04.30.12.15.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Apr 2014 12:15:59 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 30 Apr 2014 20:15:55 +0100 Message-Id: <1398885355-13200-1-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v2] xen/arm: vcpu: Correctly release resource when the VCPU failed to initialized X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: While I was adding new failing code at the end of the function, I've noticed that the vtimers are not freed which mess all the timers and will crash Xen quickly when the page will be reused. Currently neither vcpu_vgic_init nor vcpu_vtimer_init fail, so we are safe for now. With the new GICv3 code, the former function will be able to fail. This will result to a memory leak. Call vcpu_destroy if the initialization has failed. We also need to add a boolean to know if the vtimers are correctly setup as the timer common code doesn't have safe guard against removing non-initialized timer. Signed-off-by: Julien Grall --- Changes in v2: - Update commit message --- xen/arch/arm/domain.c | 8 ++++++-- xen/arch/arm/vtimer.c | 5 +++++ xen/include/asm-arm/domain.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index ccccb77..c47db4a 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -468,12 +468,16 @@ int vcpu_initialise(struct vcpu *v) processor_vcpu_initialise(v); if ( (rc = vcpu_vgic_init(v)) != 0 ) - return rc; + goto fail; if ( (rc = vcpu_vtimer_init(v)) != 0 ) - return rc; + goto fail; return rc; + +fail: + vcpu_destroy(v); + return rc; } void vcpu_destroy(struct vcpu *v) diff --git a/xen/arch/arm/vtimer.c b/xen/arch/arm/vtimer.c index cb690bb..c515e7e 100644 --- a/xen/arch/arm/vtimer.c +++ b/xen/arch/arm/vtimer.c @@ -77,11 +77,16 @@ int vcpu_vtimer_init(struct vcpu *v) : GUEST_TIMER_VIRT_PPI; t->v = v; + v->arch.vtimer_initialized = 1; + return 0; } void vcpu_timer_destroy(struct vcpu *v) { + if ( !v->arch.vtimer_initialized ) + return; + kill_timer(&v->arch.virt_timer.timer); kill_timer(&v->arch.phys_timer.timer); } diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index ec66a4e..1be3da2 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -285,6 +285,7 @@ struct arch_vcpu struct vtimer phys_timer; struct vtimer virt_timer; + bool_t vtimer_initialized; } __cacheline_aligned; void vcpu_show_execution_state(struct vcpu *);