From patchwork Fri Aug 12 04:07:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9276295 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 789CF60752 for ; Fri, 12 Aug 2016 04:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60C2E28824 for ; Fri, 12 Aug 2016 04:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5223928826; Fri, 12 Aug 2016 04:10:02 +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 7482828824 for ; Fri, 12 Aug 2016 04:10:00 +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 1bY3kV-0006HO-W8; Fri, 12 Aug 2016 04:07:11 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bY3kU-0006HI-4Q for xen-devel@lists.xenproject.org; Fri, 12 Aug 2016 04:07:10 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 60/E3-05661-D6B4DA75; Fri, 12 Aug 2016 04:07:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKIsWRWlGSWpSXmKPExsXiVRvkpJvjvTb c4OgtU4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePMi4csBY+5K1a2T2VtYPzP2cXIxSEkMJ1R YkLDXUYQh0VgKqvEuV+XWEAcCYGNrBJvzs9i62LkAHJiJKZvz4IwKyV+zUvtYuQEalaRuLl9F RPEoDlMEl8XPWUCSQgL6EkcOfqDHcL2l3j2byYjiM0mYCDxZsdeVhBbREBJ4t6qyWD1zAI1Ev NO32QBsVkEVCUOLjwIFucV8Jb4dmMLG4gtKiAnsfJyCytEXFDi5MwnLCD3MAtoSqzfpQ8xRl5 i+9s5zBMYhWYhqZqFUDULSdUCRuZVjBrFqUVlqUW6hoZ6SUWZ6RkluYmZObqGBmZ6uanFxYnp qTmJScV6yfm5mxiBwcwABDsYPy0LOMQoycGkJMrL6742XIgvKT+lMiOxOCO+qDQntfgQowYHh 8CEs3OnM0mx5OXnpSpJ8K7yAqoTLEpNT61Iy8wBxhtMqQQHj5IIbzZImre4IDG3ODMdInWKUZ djy9R7a5mEwGZIifMagBQJgBRllObBjYDF/iVGWSlhXkagA4V4ClKLcjNLUOVfMYpzMCoJ83a DTOHJzCuB2/QK6AgmoCNOmK0BOaIkESEl1cDYm7+669bhR6/iCyW/VAu2b1hoImhQfa5JUFXs fcOVR4kJV7bbT91nkhf3y9vmfHXxSclfReHFn8JSXhu1nFkUu+K/2+05oWZJIXu0ko5FJAbuK 69cz7L+4ewp+YkXNk/Kd/MyDwyQP2SQ0rf2urjKzOeMh38mn/5zmtNPMn631NEoU7aMwkQllu KMREMt5qLiRAA9/+pM+AIAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-15.tower-21.messagelabs.com!1470974828!28135220!1 X-Originating-IP: [74.125.82.66] X-SpamReason: No, hits=0.2 required=7.0 tests=RCVD_ILLEGAL_IP X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24904 invoked from network); 12 Aug 2016 04:07:08 -0000 Received: from mail-wm0-f66.google.com (HELO mail-wm0-f66.google.com) (74.125.82.66) by server-15.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Aug 2016 04:07:08 -0000 Received: by mail-wm0-f66.google.com with SMTP id q128so655391wma.1 for ; Thu, 11 Aug 2016 21:07:08 -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:user-agent:mime-version :content-transfer-encoding; bh=6oKDbYXdwj5tu/CRJWKliQPBZQKMEBYYK3BkIxudPqM=; b=r4nDqdtNRzHduy13kVkJi6z47VM+ySA92i99xIOgrPcm/75lSxi65jfYps9SLH2S0A 9E6MM+RDJz7q1Mf8O4+KKwnRnNiximnG2WOmoskSr7nWqDVhu0ZLRXMV2VhVLdXjo/xQ FV97fTFD3H8zo8oD4Z/ykg72YvT2AUEdK+Dk4e8zwH6rqZC3jCaRahKQrcQCMSxvxkz0 GmGkS7cEqy5IIiryGl+ytScwOP4Uqo4rXes5c4b0KylqEiCEE320oJpmPNqua4tVjDV0 49n6BKNMotgvwhCBi8+s2rFLUi8sPo+oZ13+1gKkxoa6hTtYVD1Jon5ju+ATqdvpcCLT 2mXA== 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 :user-agent:mime-version:content-transfer-encoding; bh=6oKDbYXdwj5tu/CRJWKliQPBZQKMEBYYK3BkIxudPqM=; b=bIubbn5EfZZap0x+7aPrrZw60POaeLf0x278NUskteGiBA8OS6nB+vks18syQMHRf+ zNlCxSEWRNx0QnpEAfvIsNvKkhscY6Oh3mm5dyqYkhwXzRTMDaXVU4QjUL3dcCKUp0M6 pPnLkc1+pMfTIPesjDPceWLbejOxIFG2QHrlu7izMId+XjKVWI5XF9VY1clyOGbnT099 xTKhHEmpqpctt6tWCej8R+DDIgnLjv32WDp1NVJtSJHlIIxlfm+uwZeigJC3ZadaykTO 5x9742HzNjJTyvD5NY6krBgXDs0g06jxpxYCUf7w+fyRlQqvxOUHldAgry1xrR380MLE oOzw== X-Gm-Message-State: AEkoousq8JInMqFv517fa62k2fik7sjDSNYIhT9NBNC/4H43RybMtXNfpxlSZZzfTI+E0Q== X-Received: by 10.194.16.162 with SMTP id h2mr13354263wjd.52.1470974828327; Thu, 11 Aug 2016 21:07:08 -0700 (PDT) Received: from Solace.fritz.box (net-2-32-14-104.cust.vodafonedsl.it. [2.32.14.104]) by smtp.gmail.com with ESMTPSA id q4sm5548924wjk.24.2016.08.11.21.07.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Aug 2016 21:07:07 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 12 Aug 2016 06:07:05 +0200 Message-ID: <147097482567.29177.2373077001942557324.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH] xen: credit1: fix a race when picking initial pCPU for a vCPU 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 the Credit1 hunk of 9f358ddd69463 ("xen: Have schedulers revise initial placement") csched_cpu_pick() is called without taking the runqueue lock of the (temporary) pCPU that the vCPU has been assigned to (e.g., in XEN_DOMCTL_max_vcpus). However, although 'hidden' in the IS_RUNQ_IDLE() macro, that function does access the runq (for doing load balancing calculations), and hence the appropriate lock must be taken. Races have been observed, in the form of IS_RUNQ_IDLE() falling over LIST_POISON. Reported-by: Andrew Cooper Signed-off-by: Dario Faggioli Acked-by: George Dunlap --- Cc: George Dunlap Cc: Andrew Cooper Cc: Jan Beulich --- xen/common/sched_credit.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c index 220ff0d..b6f82e8 100644 --- a/xen/common/sched_credit.c +++ b/xen/common/sched_credit.c @@ -998,9 +998,13 @@ csched_vcpu_insert(const struct scheduler *ops, struct vcpu *vc) BUG_ON( is_idle_vcpu(vc) ); - /* This is safe because vc isn't yet being scheduled */ + /* csched_cpu_pick() looks in vc->processor's runq, so we need the lock. */ + lock = vcpu_schedule_lock_irq(vc); + vc->processor = csched_cpu_pick(ops, vc); + spin_unlock_irq(lock); + lock = vcpu_schedule_lock_irq(vc); if ( !__vcpu_on_runq(svc) && vcpu_runnable(vc) && !vc->is_running )