Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp861923ybx; Wed, 6 Nov 2019 09:29:46 -0800 (PST) X-Google-Smtp-Source: APXvYqxV3tuTIHaPgHx/o/kt0YFV1DywQabWG8VIo9u7zPXAsab6+lZWNqW9i96GwWbiAQqjOoUj X-Received: by 2002:a05:6402:54a:: with SMTP id i10mr3891864edx.230.1573061386652; Wed, 06 Nov 2019 09:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573061386; cv=none; d=google.com; s=arc-20160816; b=czNKxPtbG2CFanzwjxJNCW1VDz3F6bfbOr0CnvObKLDMQTItt7mWX6hvyYqv/EYt5F 7UEPBLmuT0MHUAx4kuXOqZDArKUzBrDl4IEBJsqFe/fqAt4J3gS+ryFVf5HvkFkx1dFN 3FU8KJ/vMhOHYkktha9boDAS/8Vq8sQ1RioCI5bCxO9ZzPkJZy3fmogmy8gvUZtBH+PE /a6DxkFCByKWEXOBLDvJHU6aFuZnQiRszHc8Vx+P+wsgGPGXYfyXaWpj1pMu80mbrMBz ogKRzIZdHfjpEcYS6jR/j5kuhQXvQIuq4hq16Jk0fJHmWEBQGdaqs7SsF/Q9BMwx1hjV R59A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=NsWA7XBpLM/epw+Wpo+YZxuWnVdArZbfjT2YXWIUhik=; b=uPIl+GCtIRIsbaPRx92W4w841e3hP+FL9NOm85nCaldLUDkm0G1qAKkmP/MONDdBWB uM553u4y4GF7WRIl46W6xF/48mJj3t8W8nVLeN5o5KHhD98Y3qrLj0FCLF+BYPOmwSZF qnr2SQHxl2+khbTnyvCxZuUmt3vndwVV3+o71c48iukDrswUCQi0JCfXKF9mKV0JGnYj XQRuT+QGZXafiJxHgQ4LpeAoCi54LD2qXbcbmrUXua9KBVycN2nPnjKvWW/Uv8JL3H+0 eCbvr3yMymtY1gUmRVb+ObN6nJxR97ZuxoG+38NliTrV3fe1PlwTEV9cM3I+RGxD7Zqe zpAg== 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 l40si13615376edb.432.2019.11.06.09.29.22; Wed, 06 Nov 2019 09:29:46 -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 S1732367AbfKFR0h (ORCPT + 99 others); Wed, 6 Nov 2019 12:26:37 -0500 Received: from foss.arm.com ([217.140.110.172]:43540 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbfKFR0h (ORCPT ); Wed, 6 Nov 2019 12:26:37 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 982B246A; Wed, 6 Nov 2019 09:26:36 -0800 (PST) Received: from e107158-lin.cambridge.arm.com (e107158-lin.cambridge.arm.com [10.1.195.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 743B03F719; Wed, 6 Nov 2019 09:26:34 -0800 (PST) Date: Wed, 6 Nov 2019 17:26:32 +0000 From: Qais Yousef To: Peter Zijlstra Cc: Quentin Perret , linux-kernel@vger.kernel.org, aaron.lwe@gmail.com, valentin.schneider@arm.com, mingo@kernel.org, pauld@redhat.com, jdesfossez@digitalocean.com, naravamudan@digitalocean.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, juri.lelli@redhat.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, kernel-team@android.com, john.stultz@linaro.org Subject: Re: NULL pointer dereference in pick_next_task_fair Message-ID: <20191106172631.euq7ggvfao2kvyld@e107158-lin.cambridge.arm.com> References: <20191028174603.GA246917@google.com> <20191106120525.GX4131@hirez.programming.kicks-ass.net> <20191106130838.GL5671@hirez.programming.kicks-ass.net> <20191106150450.fa5ppdejiggsb46a@e107158-lin.cambridge.arm.com> <20191106165733.GY4114@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191106165733.GY4114@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/06/19 17:57, Peter Zijlstra wrote: > On Wed, Nov 06, 2019 at 03:04:50PM +0000, Qais Yousef wrote: > > On 11/06/19 14:08, Peter Zijlstra wrote: > > > On Wed, Nov 06, 2019 at 01:05:25PM +0100, Peter Zijlstra wrote: > > > > > The only thing I'm now considering is if we shouldn't be setting > > > > ->on_cpu=2 _before_ calling put_prev_task(). I'll go audit the RT/DL > > > > cases. > > > > > > So I think it all works, but that's more by accident than anything else. > > > I'll move the ->on_cpu=2 assignment earlier. That clearly avoids calling > > > put_prev_task() while we're in put_prev_task(). > > > > Did you mean avoids calling *set_next_task()* while we're in put_prev_task()? > > Either, really. The change pattern does put_prev_task() first, and then > restores state by calling set_next_task(). And it can do that while > we're in put_prev_task(), unless we're setting ->on_cpu=2. *head starts spinning* I can't see how we can have double put_prev_task() in a row. Let me stare more at the code. > > > So what you're saying is that put_prev_task_{rt,dl}() could drop the rq_lock() > > too and the race could happen while we're inside these functions, correct? Or > > is it a different reason? > > Indeed, except it looks like that actually works (mostly by accident). +1 I think I got it now, it's the double_lock_balance() that can drop the lock. It even has a comment above it! > > > By the way, is all reads/writes to ->on_cpu happen when a lock is held? Ie: we > > don't need to use any smp read/write barriers? > > Yes, ->on_cpu is fully serialized by rq->lock. We use > smp_store_release() in finish_task() due to ttwu spin-waiting on it > (which reminds me, riel was seeing lots of that). Thanks. I had to ask as it was hard to walk all the paths. Sometimes I get tempted to sprinkle comments or lockdep_assert() but then I think that can easily get ugly and out of hand. I guess one just has to know the code. Cheers -- Qais Yousef