From patchwork Thu Aug 30 18:45:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 11066 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 539D223E29 for ; Thu, 30 Aug 2012 18:46:23 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 11B26A18551 for ; Thu, 30 Aug 2012 18:45:46 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id k11so1016832iea.11 for ; Thu, 30 Aug 2012 11:46:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-content-scanned:x-cbid:x-gm-message-state; bh=Ei2d1wjGNcVuZ/6a3/KOTXpHj8SJKLD9i7l8VGoXIv0=; b=FDW+RRWQCyLV0fs9pQlNe/adR3GmWT4sYL92ynk436NSMBRokSC5Qkk3FSfb/8uohR vm9kwY9gHTwAy01/MONnCfHdq/kbHqP/02MhfvZwn+W3JHf5XQR+L8x7j5uhy8ODEgmR uCyxEVUh1SGctvVCQC77By2vO42NfIv9SZK5mEnLk825ogeBgkl+BlS7VHbu2gj36CGT E2QvsnGzWRwROJRg1lmwUe02lv8qeJyzy343LViALyIZE34f56mnlxmIa8o5zx7Iju0y yZy55XPEHGHfFkoiznhHwrRudC+INaKjz+mzc8Qdw6HwaiunyDFQSNSP1QcBhEmqHSwE pNuA== Received: by 10.50.207.106 with SMTP id lv10mr2025595igc.0.1346352382814; Thu, 30 Aug 2012 11:46:22 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp25795igc; Thu, 30 Aug 2012 11:46:22 -0700 (PDT) Received: by 10.182.78.228 with SMTP id e4mr5704894obx.77.1346352382285; Thu, 30 Aug 2012 11:46:22 -0700 (PDT) Received: from e37.co.us.ibm.com (e37.co.us.ibm.com. [32.97.110.158]) by mx.google.com with ESMTPS id lr6si3156837obb.124.2012.08.30.11.46.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 11:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.158 as permitted sender) client-ip=32.97.110.158; Authentication-Results: mx.google.com; spf=pass (google.com: domain of paulmck@linux.vnet.ibm.com designates 32.97.110.158 as permitted sender) smtp.mail=paulmck@linux.vnet.ibm.com Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Aug 2012 12:46:19 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 30 Aug 2012 12:45:40 -0600 Received: from d03relay03.boulder.ibm.com (d03relay03.boulder.ibm.com [9.17.195.228]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 1BCC43E4007B for ; Thu, 30 Aug 2012 12:45:37 -0600 (MDT) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay03.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7UIjK5t150534 for ; Thu, 30 Aug 2012 12:45:20 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7UIjIbJ016876 for ; Thu, 30 Aug 2012 12:45:19 -0600 Received: from paulmck-ThinkPad-W500 (sig-9-77-132-62.mts.ibm.com [9.77.132.62]) by d03av01.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7UIjH5J016760; Thu, 30 Aug 2012 12:45:17 -0600 Received: by paulmck-ThinkPad-W500 (Postfix, from userid 1000) id E6995EA82A; Thu, 30 Aug 2012 11:45:16 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: mingo@elte.hu, laijs@cn.fujitsu.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca, josh@joshtriplett.org, niv@us.ibm.com, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, Valdis.Kletnieks@vt.edu, dhowells@redhat.com, eric.dumazet@gmail.com, darren@dvhart.com, fweisbec@gmail.com, sbw@mit.edu, patches@linaro.org, "Paul E. McKenney" Subject: [PATCH tip/core/rcu 5/5] rcu: Prevent initialization race in rcutorture kthreads Date: Thu, 30 Aug 2012 11:45:12 -0700 Message-Id: <1346352312-31987-5-git-send-email-paulmck@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.8 In-Reply-To: <1346352312-31987-1-git-send-email-paulmck@linux.vnet.ibm.com> References: <20120830184448.GA31753@linux.vnet.ibm.com> <1346352312-31987-1-git-send-email-paulmck@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12083018-7408-0000-0000-0000080A5936 X-Gm-Message-State: ALoCoQnrYBVB85hKk12YmzS3JRhdUE1BGpN/vg2uQ/9r+XrtURzvB7FICKCS34Sr9e1FDBB/Vqmv From: "Paul E. McKenney" When you do something like "t = kthread_run(...)", it is possible that the kthread will start running before the assignment to "t" happens. If the child kthread expects to find a pointer to its task_struct in "t", it will then be fatally disappointed. This commit therefore switches such cases to kthread_create() followed by wake_up_process(), guaranteeing that the assignment happens before the child kthread starts running. Reported-by: Fengguang Wu Signed-off-by: Paul E. McKenney --- kernel/rcutorture.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c index 8ea2726..3e2adae 100644 --- a/kernel/rcutorture.c +++ b/kernel/rcutorture.c @@ -2028,14 +2028,15 @@ rcu_torture_init(void) /* Start up the kthreads. */ VERBOSE_PRINTK_STRING("Creating rcu_torture_writer task"); - writer_task = kthread_run(rcu_torture_writer, NULL, - "rcu_torture_writer"); + writer_task = kthread_create(rcu_torture_writer, NULL, + "rcu_torture_writer"); if (IS_ERR(writer_task)) { firsterr = PTR_ERR(writer_task); VERBOSE_PRINTK_ERRSTRING("Failed to create writer"); writer_task = NULL; goto unwind; } + wake_up_process(writer_task); fakewriter_tasks = kzalloc(nfakewriters * sizeof(fakewriter_tasks[0]), GFP_KERNEL); if (fakewriter_tasks == NULL) { @@ -2150,14 +2151,15 @@ rcu_torture_init(void) } if (shutdown_secs > 0) { shutdown_time = jiffies + shutdown_secs * HZ; - shutdown_task = kthread_run(rcu_torture_shutdown, NULL, - "rcu_torture_shutdown"); + shutdown_task = kthread_create(rcu_torture_shutdown, NULL, + "rcu_torture_shutdown"); if (IS_ERR(shutdown_task)) { firsterr = PTR_ERR(shutdown_task); VERBOSE_PRINTK_ERRSTRING("Failed to create shutdown"); shutdown_task = NULL; goto unwind; } + wake_up_process(shutdown_task); } i = rcu_torture_onoff_init(); if (i != 0) {