From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751975AbeEGHbL (ORCPT ); Mon, 7 May 2018 03:31:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:38617 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750732AbeEGHbI (ORCPT ); Mon, 7 May 2018 03:31:08 -0400 Subject: Re: [PATCH REPOST] Revert mm/vmstat.c: fix vmstat_update() preemption BUG To: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: tglx@linutronix.de, "Steven J . Hill" , Tejun Heo , Andrew Morton , Christoph Lameter References: <20180504104451.20278-1-bigeasy@linutronix.de> From: Vlastimil Babka Openpgp: preference=signencrypt Autocrypt: addr=vbabka@suse.cz; prefer-encrypt=mutual; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvHGTjKbJzC2xpFcY0DQbZzuwsIZ8OPJCc LM4S7mT25NE5kUTG/TKQCk922vRdGVMoLA7dIQrgXnRXtyT61sg8PG4wcfOnuWf8577aXP1x 6mzw3/jh3F+oSBHb/G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suse.cz> Date: Mon, 7 May 2018 09:31:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180504104451.20278-1-bigeasy@linutronix.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/04/2018 12:44 PM, Sebastian Andrzej Siewior wrote: > This patch reverts commit c7f26ccfb2c3 ("mm/vmstat.c: fix > vmstat_update() preemption BUG"). > Steven saw a "using smp_processor_id() in preemptible" message and > added a preempt_disable() section around it to keep it quiet. This is > not the right thing to do it does not fix the real problem. > > vmstat_update() is invoked by a kworker on a specific CPU. This worker > it bound to this CPU. The name of the worker was "kworker/1:1" so it > should have been a worker which was bound to CPU1. A worker which can > run on any CPU would have a `u' before the first digit. > > smp_processor_id() can be used in a preempt-enabled region as long as > the task is bound to a single CPU which is the case here. If it could > run on an arbitrary CPU then this is the problem we have an should seek > to resolve. > Not only this smp_processor_id() must not be migrated to another CPU but > also refresh_cpu_vm_stats() which might access wrong per-CPU variables. > Not to mention that other code relies on the fact that such a worker > runs on one specific CPU only. > > Therefore I revert that commit and we should look instead what broke the > affinity mask of the kworker. Yes. I think there's an important detail that should be perhaps included explicitly here. The check check_preemption_disabled() does include this test: /* * Kernel threads bound to a single CPU can safely use * smp_processor_id(): */ if (cpumask_equal(¤t->cpus_allowed, cpumask_of(this_cpu))) goto out; So indeed, if kworkers work as expected, there's no false positive bug. The report in commit c7f26ccfb2c3 included: BUG: using smp_processor_id() in preemptible [00000000] code: kworker/1:1/269 caller is vmstat_update+0x50/0xa0 CPU: 0 PID: 269 Comm: kworker/1:1 Not tainted I.e. kworker/1 running on CPU 0. Because the BUG was reported, we know that the test above did not prevent it. That means either the kworker's cpumask was not restricted to CPU 1 (it included also cpu 0), or it was restricted, but the restriction was ignored, and it still executed on cpu 0. Note the report also said "Attempting to hotplug CPUs with CONFIG_VM_EVENT_COUNTERS enabled can...". IIRC Tejun mentioned that during hotplug (or hotremove, actually?) the guarantees are off, but vmstat should not schedule work items on such cpus due to its hooks/checks. In any case I agree that the revert should be done immediately even before fixing the underlying bug. The preempt_disable/enable doesn't prevent the bug, it only prevents the debugging code from actually reporting it! Note that it's debugging code (CONFIG_DEBUG_PREEMPT) that production kernels most likely don't have enabled, so we are not even helping them not crash (while allowing possible data corruption). Acked-by: Vlastimil Babka > Cc: Steven J. Hill > Cc: Tejun Heo > Cc: Andrew Morton > Signed-off-by: Sebastian Andrzej Siewior > --- > mm/vmstat.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/mm/vmstat.c b/mm/vmstat.c > index 33581be705f0..40b2db6db6b1 100644 > --- a/mm/vmstat.c > +++ b/mm/vmstat.c > @@ -1839,11 +1839,9 @@ static void vmstat_update(struct work_struct *w) > * to occur in the future. Keep on running the > * update worker thread. > */ > - preempt_disable(); > queue_delayed_work_on(smp_processor_id(), mm_percpu_wq, > this_cpu_ptr(&vmstat_work), > round_jiffies_relative(sysctl_stat_interval)); > - preempt_enable(); > } > } > >