From patchwork Wed Apr 30 18:05:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 29441 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 58A27202FE for ; Wed, 30 Apr 2014 18:08:34 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id x3sf2029215qcv.10 for ; Wed, 30 Apr 2014 11:08:34 -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=2dqhlChAvc7DaZliCl/bMKrzc4UFzTvQ7QlY/L3GWPQ=; b=lihRG8SqeSG+bUnnPHzFtONgztzK0+BId5ObcyvXRzOORlTMRsA98eVA4YdvtykaPp nEqOx4f89qB6Xtso5kTmuKXl+2V56nYD7cGu3l+RBS5ELDmIX616P3wET06k32u9N6Eb khLLFbCR2NMwyKqTWS0RzqDiaDl9Mcj7Ij1IS/hMjYk8aY9L+aB13Fv06s8H5s1iqVw7 UE4QJ5G6Yz/Zl4FF7Krwmk/FFppTh7A7Rqjpj4dsRdejwh+tTJTpRISGDwIcdT8foFi/ UvvQf7l7wWuyjCE5u3rnRgV1XwmpDMNZzjR60/tPsygQkoGxyadA1P+Phr5hHpssIaTY bcmw== X-Gm-Message-State: ALoCoQm45DGCSLRFvpmV1VixiavnviHR7kb02t+eGEjF7i+dkaO3Swgyn19haoMf7+7IWzGHJjae X-Received: by 10.236.171.169 with SMTP id r29mr2783071yhl.32.1398881313959; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.135 with SMTP id e7ls760660qga.70.gmail; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) X-Received: by 10.58.88.8 with SMTP id bc8mr1050191veb.39.1398881313828; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id cb3si5492242vdc.41.2014.04.30.11.08.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Apr 2014 11:08:33 -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.175; Received: by mail-ve0-f175.google.com with SMTP id oz11so2613442veb.6 for ; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) X-Received: by 10.52.2.229 with SMTP id 5mr3960248vdx.24.1398881313730; Wed, 30 Apr 2014 11:08:33 -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 ib8csp299604vcb; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) X-Received: by 10.58.95.102 with SMTP id dj6mr242903veb.68.1398881313373; Wed, 30 Apr 2014 11:08:33 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id sq9si5483773vdc.35.2014.04.30.11.08.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 30 Apr 2014 11:08:33 -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 1WfYtT-00033L-LX; Wed, 30 Apr 2014 18:06:07 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WfYtR-00033D-SP for xen-devel@lists.xenproject.org; Wed, 30 Apr 2014 18:06:06 +0000 Received: from [193.109.254.147:60144] by server-1.bemta-14.messagelabs.com id E9/5C-00839-D8B31635; Wed, 30 Apr 2014 18:06:05 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-10.tower-27.messagelabs.com!1398881164!1947606!1 X-Originating-IP: [74.125.83.53] 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 22529 invoked from network); 30 Apr 2014 18:06:04 -0000 Received: from mail-ee0-f53.google.com (HELO mail-ee0-f53.google.com) (74.125.83.53) by server-10.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 30 Apr 2014 18:06:04 -0000 Received: by mail-ee0-f53.google.com with SMTP id b15so509081eek.12 for ; Wed, 30 Apr 2014 11:06:04 -0700 (PDT) X-Received: by 10.14.202.5 with SMTP id c5mr5706926eeo.94.1398881163762; Wed, 30 Apr 2014 11:06:03 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id w12sm69706553eez.36.2014.04.30.11.06.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Apr 2014 11:06:02 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Wed, 30 Apr 2014 19:05:59 +0100 Message-Id: <1398881159-10640-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] 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 none of vcpu_vgic_init and vcpu_vtimer_init doesn't failed, 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 --- 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 *);