From patchwork Tue Jul 19 15:34:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9237731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E987160574 for ; Tue, 19 Jul 2016 15:36:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA968275A2 for ; Tue, 19 Jul 2016 15:36:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF0D82787C; Tue, 19 Jul 2016 15:36:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4CBC6275A2 for ; Tue, 19 Jul 2016 15:36:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPX2C-0000jZ-3V; Tue, 19 Jul 2016 15:34:12 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bPX2B-0000j5-6f for xen-devel@lists.xenproject.org; Tue, 19 Jul 2016 15:34:11 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id B6/1C-12946-2784E875; Tue, 19 Jul 2016 15:34:10 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrPIsWRWlGSWpSXmKPExsXiVRvkrFvo0Rd u0H3T0OL7lslMDowehz9cYQlgjGLNzEvKr0hgzejZfYGt4JFgxYIbt1gaGFfxdjFycQgJTGeU WHR7JTuIwyKwhlXiZf8hVhBHQuASq8Tdjm6WLkZOICdGYsWkVUwQdpXEkj1/weJCAioSN7eDx EFGLWWSuHlgOzNIQlhAT+LI0R/sEHaKxLa+uYwgNpuAgcSbHXtZQWwRASWJe6smgzUzCzQzSi y/OResmUVAVWJm12uwBl4BL4n+Y5eBijg4OIHspX1MEIs9JR793sUGYosKyEmsvNzCClEuKHF y5hMWkHJmAU2J9bv0QcLMAvIS29/OYZ7AKDILSdUshKpZSKoWMDKvYtQoTi0qSy3SNTLUSyrK TM8oyU3MzNE1NDDVy00tLk5MT81JTCrWS87P3cQIjIB6BgbGHYx3J/sdYpTkYFIS5VUV7Q0X4 kvKT6nMSCzOiC8qzUktPsSowcEhMOHs3OlMUix5+XmpShK8nO594UKCRanpqRVpmTnAGIUple DgURLh/eAGlOYtLkjMLc5Mh0idYtTl2DL13lomIbAZUuK8jiAzBECKMkrz4EbA0sUlRlkpYV5 GBgYGIZ6C1KLczBJU+VeM4hyMSsK8HSBTeDLzSuA2vQI6ggnoCAPVbpAjShIRUlINjEHpO/Zc uKzozG3MYnXBQdpje/3j30Ia74319uY8MNl2gE+kxNf0Qwx7tr3rvZ+SqlMOZ4gtuyX86nLFl PWVq399Tn/VJ5qwaEdywsWCnRlK2lmG+6R2mB5q8lnbftT/y9zcdz6u6rL2Tq5aJ2fefRe/aM exjKu523QXcH8S/6ep6PR5h0HsASWW4oxEQy3mouJEAAOsLyoSAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1468942449!13992793!1 X-Originating-IP: [74.125.82.67] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26235 invoked from network); 19 Jul 2016 15:34:09 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-14.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 19 Jul 2016 15:34:09 -0000 Received: by mail-wm0-f67.google.com with SMTP id x83so3184448wma.3 for ; Tue, 19 Jul 2016 08:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=H4o3+SCvnQIXpqH7MyaTil8TX2gBVE0AXgKntQUbZzs=; b=fLo9mO0td1+hjpvZiAn25wEs8QjjHoHYoKDE2djaAL3oCU4vKsj4XayCs4nkf/wbjC wRofyq0rVVLhjsOEm9mtJSex2lySEF6vqwp2ca2TkfU/Z5JrpuLsYJxe7rJvgqHeYgiP jvxgQjAPo3m7yA0p617Bl13L6iCDpoEp/F/qcMOzTRwBaJ+Uil7HvPlc/L5jixw58h3l zyOGBHRPG6BdBlflsoNvdguNvHB76xRhOGrX78SyrZe8J8KHW8Ey+0797QdgmWSPnpcr rSbU8lY+4HF1EGTG5ZfeJEhDH0WxXzYF5A+Uygd/Og58QbyCgCqR51zENNFdiFborshr rmdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=H4o3+SCvnQIXpqH7MyaTil8TX2gBVE0AXgKntQUbZzs=; b=XghfT0X2z2P8UzHZD7UPFshfL0zc1NdfLckN5Zzfo+QgMzFYi9tTbAEP1N6XGOIQOv r5G8s9g1y6KW01zzqkWRoR9FLDg7HCO5NXw5Va9q+65mtAiIEoK//Eu3C5divz3h//1J vX81+bNYoNXwiklQRVKnXrmn2mxfBLdK1iefbUN9ptOvrXXqIfIoR0tEZ9pffhftSL/0 kZs1vW/ff3pd85ycE/efsXvvbbkgxK0AJ/uJfrKBzH9+6e3nKXHCAud3/yMhOJKP1SDH UQ9j+j1NUmr6ysGUfmlW2R6ViNUFn8Nl3nh0xlqDkevp8BkSOWvqHG/iPsURArjErWU+ xrhA== X-Gm-Message-State: ALyK8tLn/jKfEBy4LQVrYCpZ5p6BY7Cmo0x6a4h+F0UGmFdmpDIr8VeeYxRLqHheBq/69Q== X-Received: by 10.28.134.203 with SMTP id i194mr5246490wmd.22.1468942447500; Tue, 19 Jul 2016 08:34:07 -0700 (PDT) Received: from Solace.fritz.box (net-188-217-84-158.cust.vodafonedsl.it. [188.217.84.158]) by smtp.gmail.com with ESMTPSA id u125sm23727622wmg.22.2016.07.19.08.34.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 08:34:06 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Tue, 19 Jul 2016 17:34:04 +0200 Message-ID: <146894244486.483.13984277930071960202.stgit@Solace.fritz.box> In-Reply-To: <146894226840.483.8554580913887484141.stgit@Solace.fritz.box> References: <146894226840.483.8554580913887484141.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Andrew Cooper , Anshul Makkar , George Dunlap Subject: [Xen-devel] [PATCH v2 2/2] xen: credit2: fix potential issues in csched2_cpu_pick with tracing enabled X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In fact, when not finding a suitable runqueue where to place a vCPU, and hence using a fallback, we either: - don't issue any trace record (while we should), - risk underruning when accessing the runqueues array, while preparing the trace record. Fix both issues and, while there, also a couple of style problems found nearby. Spotted by Coverity. Signed-off-by: Dario Faggioli Reported-by: Andrew Cooper --- Cc: George Dunlap Cc: Anshul Makkar --- Changes from v1: * cite Coverity in the changelog. --- xen/common/sched_credit2.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c index a55240f..3009ff9 100644 --- a/xen/common/sched_credit2.c +++ b/xen/common/sched_credit2.c @@ -1443,7 +1443,8 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) { /* We may be here because someone requested us to migrate. */ __clear_bit(__CSFLAG_runq_migrate_request, &svc->flags); - return get_fallback_cpu(svc); + new_cpu = get_fallback_cpu(svc); + goto out; } /* First check to see if we're here because someone else suggested a place @@ -1505,7 +1506,7 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) if ( rqd_avgload < min_avgload ) { min_avgload = rqd_avgload; - min_rqi=i; + min_rqi = i; } } @@ -1520,20 +1521,20 @@ csched2_cpu_pick(const struct scheduler *ops, struct vcpu *vc) BUG_ON(new_cpu >= nr_cpu_ids); } -out_up: + out_up: read_unlock(&prv->lock); - + out: if ( unlikely(tb_init_done) ) { struct { uint64_t b_avgload; unsigned vcpu:16, dom:16; unsigned rq_id:16, new_cpu:16; - } d; - d.b_avgload = prv->rqd[min_rqi].b_avgload; + } d; d.dom = vc->domain->domain_id; d.vcpu = vc->vcpu_id; d.rq_id = c2r(ops, new_cpu); + d.b_avgload = prv->rqd[d.rq_id].b_avgload; d.new_cpu = new_cpu; __trace_var(TRC_CSCHED2_PICKED_CPU, 1, sizeof(d),