Received: by 10.192.165.148 with SMTP id m20csp4433060imm; Tue, 24 Apr 2018 02:39:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqMpMDoEtVgzQyZ82mRwMRoJWNIDbqwkOKSO9RlPycqCjG//Xyc1aqfM6o15c4hNpkUDBwb X-Received: by 10.101.78.8 with SMTP id r8mr1952356pgt.29.1524562759330; Tue, 24 Apr 2018 02:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524562759; cv=none; d=google.com; s=arc-20160816; b=AyuULzsRnk1MszoCxR9R6lN5f8F7nJf5Ad+w5yjl6tm8IiqvIFsf6dvOeN0yBAKOec KGB6PTz6kcR6KR9UwqylqfOcX6/7LffKDa2nN6opr5kQ1qQrMa0W5i/tqXpQQWscArld K1wCTpkcL+CGBfespDBT7W1taU2oXEoVS3TyXnK97Nfm+NGlsIYn02u98MEB5rJ4oVdQ Wdhlptff/nbWUWPWFRpq7IbNQAKLKxi1FSDaXQXrUq0Li/6YrDFd0mVs7JukKypqw3GE zd2TWzGngjVPkOKLWsxyZQ8QPpSoo2qmJPqj0gX3MptzPTvgGcS2iEKWpXEVCLqmsjNT jW9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=fUn46U6qNAZswgkiDppllPmgCXypKWMN7t07x8sRKck=; b=iI2ANoW4butTJOo8bvCzh4f4UzPVoZhW07qQNl2vtvuhMJv6mnw7kgOZZslXCbmwIA sav95HS168/btUGByUNQs8SWro3caElFX4NKxX5uAk+oymER7W0fBsJtO7q0dy+hXN5v uLPROhnW6MvLyCgm5ZvokZqUOlcfQKI2BJizeXtahaBkW0Pql40u/n5SspKMcn061rE/ i8LuXg+6t/hyXWglV8NCOuN+tb1prLzFSA5jGHKd0U2N3x5Oy6iFI0OCOUisxKdApaHc Lj7pw8JhX3EZQcoS5Wigu3gPY6fpNhaT5FVdcji9ndpJy4gYEfzpO0urz7d0bhiSknk8 6kHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si10604695pgv.220.2018.04.24.02.39.04; Tue, 24 Apr 2018 02:39:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753335AbeDXJ2u (ORCPT + 99 others); Tue, 24 Apr 2018 05:28:50 -0400 Received: from alexa-out-tai-01.qualcomm.com ([103.229.16.226]:25737 "EHLO alexa-out-tai-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752789AbeDXJ2q (ORCPT ); Tue, 24 Apr 2018 05:28:46 -0400 X-IronPort-AV: E=Sophos;i="5.49,322,1520870400"; d="scan'208";a="379039" Received: from ironmsg02-tai.qualcomm.com ([10.249.140.7]) by alexa-out-tai-01.qualcomm.com with ESMTP; 24 Apr 2018 17:28:43 +0800 X-IronPort-AV: E=McAfee;i="5900,7806,8872"; a="6714531" Received: from gkohli-linux.qualcomm.com ([10.204.78.26]) by ironmsg02-tai.qualcomm.com with ESMTP; 24 Apr 2018 02:28:29 -0700 Received: by gkohli-linux.qualcomm.com (Postfix, from userid 427023) id 2F7282C5D; Tue, 24 Apr 2018 14:58:28 +0530 (IST) From: Gaurav Kohli To: tglx@linutronix.de, mpe@ellerman.id.au, dzickus@redhat.com, peterz@infradead.org, mingo@kernel.org, bigeasy@linutronix.de Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Gaurav Kohli , Neeraj Upadhyay Subject: [PATCH] kthread/smpboot: Serialize kthread parking against wakeup Date: Tue, 24 Apr 2018 14:58:25 +0530 Message-Id: <1524562105-31026-1-git-send-email-gkohli@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The control cpu thread which initiates hotplug calls kthread_park() for hotplug thread and sets KTHREAD_SHOULD_PARK. After this control thread wakes up the hotplug thread. There is a chance that wakeup code sees the hotplug thread (running on AP core) in INTERRUPTIBLE state, but sets its state to RUNNING after hotplug thread has entered kthread_parkme() and changed its state to TASK_PARKED. This can result in panic later on in kthread_unpark(), as it sees KTHREAD_IS_PARKED flag set but fails to rebind the kthread, due to it being not in TASK_PARKED state. Fix this, by serializing wakeup state change, against state change before parking the kthread. Below is the possible race: Control thread Hotplug Thread kthread_park() set KTHREAD_SHOULD_PARK smpboot_thread_fn set_current_state(TASK_INTERRUPTIBLE); kthread_parkme wake_up_process() raw_spin_lock_irqsave(&p->pi_lock, flags); if (!(p->state & state)) -> this will fail goto out; __kthread_parkme __set_current_state(TASK_PARKED); if (p->on_rq && ttwu_remote(p, wake_flags)) ttwu_remote() p->state = TASK_RUNNING; schedule(); So to avoid this race, take pi_lock to serial state changes. Suggested-by: Pavankumar Kondeti Co-developed-by: Neeraj Upadhyay Signed-off-by: Neeraj Upadhyay Signed-off-by: Gaurav Kohli diff --git a/kernel/smpboot.c b/kernel/smpboot.c index 1650578..514b232 100644 --- a/kernel/smpboot.c +++ b/kernel/smpboot.c @@ -121,7 +121,9 @@ static int smpboot_thread_fn(void *data) } if (kthread_should_park()) { + raw_spin_lock(¤t->pi_lock); __set_current_state(TASK_RUNNING); + raw_spin_unlock(¤t->pi_lock); preempt_enable(); if (ht->park && td->status == HP_THREAD_ACTIVE) { BUG_ON(td->cpu != smp_processor_id()); -- 1.9.1