Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10509035imu; Thu, 6 Dec 2018 02:16:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/UfmHFXpD8C7KKk5Wn4uqvYnCkyzj8IokoOGar7A+SFBeo2EUXdwwaQRRsCOM5ejoXXyuhy X-Received: by 2002:a62:6503:: with SMTP id z3mr27207282pfb.169.1544091413452; Thu, 06 Dec 2018 02:16:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544091413; cv=none; d=google.com; s=arc-20160816; b=tPqqgDt+o7i1IPEx/QVFak6Hpo4CODk7TQac6YJ8S5gjEjN0dE2sIG+GRc9rNmgKxA RLq4PFlVji6tQi7AUDbN9v+cNWByP6lwL7Yh66vs9jcKxrGDkfmZgmwFfBL3PyzHZf/X tBdDXV/1e/1mvSu3oVdHGMUv1sl3XrIUErwRvyaV3DWdkC7XlFLON77nC4X6dchrbVa4 BdT+sD/mZdhCqMmYRzzRLqIc9J88MBPn6QUOwhFVkULYvCZqawgJrJCt1x6d3DahQxRV il5eK9RqbBEd685vmAqEvwb3N/oXVpgrJJqhb+yY7u3T9EXvvlovsF4HAMUZ50Jqwt6N 0/jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=oTB918sj5RBrnuDAaAb3Xpic+KbvaJRvgvxjlOaQR/0=; b=hvCFD87UtEPjvwBwOCeYwB7sz5+T7iiMqap3erRTDTmtKVE7HM2D8JJiIC8uBDe0Kp yb9fWtsTD9zdQ2Tic8aXb2a2+ISRyOmgOwez7mhpo3U8esM54CQeU/hG95cXqzHmjFl9 T3Tknl8QZDGuwQXZN/dC+VIEWxJ8/qaCQn7v5xLoJm1VcWkV/OlFggDBWxGyu5/W0sgF kZaY6kMQ3C8UIWasWJRT7RHs4fTBKcy9n/DoRoGiNcZ8JfLvsfAtrLu3E/4SCcYVhZOf dW3lzwi5owNffFiJLKCJQf9PeOngIS4tcwDBik07ujx9oiY4JKwN97Vy0VVDQUuhtKlA AIlQ== 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 g1si20715286pgj.34.2018.12.06.02.16.37; Thu, 06 Dec 2018 02:16:53 -0800 (PST) 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 S1729054AbeLFKP6 (ORCPT + 99 others); Thu, 6 Dec 2018 05:15:58 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:50890 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727763AbeLFKP6 (ORCPT ); Thu, 6 Dec 2018 05:15:58 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1gUqhH-0004et-Lh; Thu, 06 Dec 2018 11:15:55 +0100 Date: Thu, 6 Dec 2018 11:15:55 +0100 From: Sebastian Andrzej Siewior To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org Subject: [PATCH RT] hrtimer: move state change before hrtimer_cancel in do_nanosleep() Message-ID: <20181206101555.xqrz2fl6k36bvezm@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a small window between setting t->task to NULL and waking the task up (which would set TASK_RUNNING). So the timer would fire, run and set ->task to NULL while the other side/do_nanosleep() wouldn't enter freezable_schedule(). After all we are peemptible here (in do_nanosleep() and on the timer wake up path) and on KVM/virt the virt-CPU might get preempted. So do_nanosleep() wouldn't enter freezable_schedule() but cancel the timer which is still running and wait for it via hrtimer_wait_for_timer(). Then wait_event()/might_sleep() would complain that it is invoked with state != TASK_RUNNING. This isn't a problem since it would be reset to TASK_RUNNING later anyway and we don't rely on the previous state. Move the state update to TASK_RUNNING before hrtimer_cancel() so there are no complains from might_sleep() about wrong state. Signed-off-by: Sebastian Andrzej Siewior --- kernel/time/hrtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index bf0ec3fbbe797..851b2134e77f4 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -1785,12 +1785,12 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod if (likely(t->task)) freezable_schedule(); + __set_current_state(TASK_RUNNING); hrtimer_cancel(&t->timer); mode = HRTIMER_MODE_ABS; } while (t->task && !signal_pending(current)); - __set_current_state(TASK_RUNNING); if (!t->task) return 0; -- 2.20.0.rc2