Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2779204pxj; Mon, 14 Jun 2021 07:03:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYSXfTksBIacaGXZtBlnVqWfLqLe0oBAnLLF1M1vKoFdZ96uAl6zd8XLJWbC0aoDInyq53 X-Received: by 2002:a05:6402:1a25:: with SMTP id be5mr17012353edb.369.1623679382695; Mon, 14 Jun 2021 07:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623679382; cv=none; d=google.com; s=arc-20160816; b=oZ5rO6ywhTSFd+2Mkm+s5cPCDJbgnr+ypcwyF74LkGGI03/yduK51UPzdqPMg3Yrir 02IU12uJ+u30SggAFDW+bILWr06uiCNk6BqXjaUCJWTkkn2j4Rdfd36Lwr+fhGN4WGa/ xgpxwRu67c+oYjVLNPgBAQkG1L89O7wOE9tz5RnWjD/iUmPeVY1jBj0atz8eMCKMk4Ht MqWx8rKem2xYS8Ykrxu5sF85sSZgH5IsI2BRzLFID2wwxtVLU7PRdDwXuaoe1DyK5kro yLIU3/gYgf4KkHT36B9dzxTrfRo8qbcd/M9e3pg98q/IZok1NbAyITjQML6SsukxRqaO c4TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=3DT1R4sMY2Bm8waC43/W6qp1g1k6z/nnrssefIHXpts=; b=OG0/pXMKiP7ZUhb/ysXhUUXnu1ccgq4qoesuZi+g/0BpY7n65cyPSqbUc0OInb0fzq crb2MaPKtrUWApz4anqt5YAmAXGjrv2csd4FFrk+LBROEg6/W2/ijSzrvsUzQ8SAC6tF YZVg7YrwcKf6cdQDfg81XxdltNdAaU2fVgI631uuPz+GVOuwTLKURXTczJx6a7u1P0x3 DfvGRp/RAKPi7WBrXqZ1XM3MlSDhLmRN3T9ZPNUXaRTHZqtei5dmxnxQk0LWw5EdXOLu hfZqCnRqdscGHeRFns5CXiXpw3+nw4nSYL+J8Li6ay1NPYWqNXapaVuMcEa6SDyvllON V1dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="l/jgwy4b"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7DRKZuke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gt8si11225246ejb.622.2021.06.14.07.02.39; Mon, 14 Jun 2021 07:03:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="l/jgwy4b"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=7DRKZuke; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234035AbhFNODo (ORCPT + 99 others); Mon, 14 Jun 2021 10:03:44 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:54976 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233180AbhFNODn (ORCPT ); Mon, 14 Jun 2021 10:03:43 -0400 Date: Mon, 14 Jun 2021 16:01:38 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1623679299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3DT1R4sMY2Bm8waC43/W6qp1g1k6z/nnrssefIHXpts=; b=l/jgwy4bBanobhax+edKgJIdrMspIYO3LBw1gsyL6zm2wUjsZNdilic6SMXWTOTkeVhhDe u6y4/SmiHs+wQ+iHphLvqeHbzQGdY/UflX7yvxrCbEVt4E+E2gJTCmAYIXVE+dSUZFsEOk J38+zl9sgDY9gdqsBftWhpnMVk7J0UoOqBytPCHmorcPyFm0DD2oCBpnWa5ibMsK9k01Vv kjBMFtbizppkoDq20i29KNwKLG8y/fyNfgj9MVAVXIdLqsbwRF0EQYpydqwxXnt6UpCkwU TyV089RJon43uKDL52oCLS9pgQ8yhqrybokTn59OqmRWJK21kVL43vBRA4z0HA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1623679299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3DT1R4sMY2Bm8waC43/W6qp1g1k6z/nnrssefIHXpts=; b=7DRKZukesw9FZsY7e3oUrBpBBFHFgoTIzeQsVbdN0CTO4DMYe8m1pG4PtXvix6ifMRiejR T/E6tm3gRegIWeBw== From: Sebastian Andrzej Siewior To: Vlastimil Babka Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Lameter , David Rientjes , Pekka Enberg , Joonsoo Kim , Thomas Gleixner , Mel Gorman , Jesper Dangaard Brouer , Peter Zijlstra , Jann Horn Subject: Re: [RFC v2 33/34] mm, slub: use migrate_disable() on PREEMPT_RT Message-ID: <20210614140138.urxtrsk3jddnv57r@linutronix.de> References: <20210609113903.1421-1-vbabka@suse.cz> <20210609113903.1421-34-vbabka@suse.cz> <20210614111619.l3ral7tt2wasvlb4@linutronix.de> <390fc59e-17ed-47eb-48ff-8dae93c9a718@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <390fc59e-17ed-47eb-48ff-8dae93c9a718@suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-14 13:33:43 [+0200], Vlastimil Babka wrote: > On 6/14/21 1:16 PM, Sebastian Andrzej Siewior wrote: > > I haven't looked at the series and I have just this tiny question: why > > did migrate_disable() crash for Mel on !RT and why do you expect that it > > does not happen on PREEMPT_RT? > > Right, so it's because __slab_alloc() has this optimization to avoid re-reading > 'c' in case there is no preemption enabled at all (or it's just voluntary). > > #ifdef CONFIG_PREEMPTION > /* > * We may have been preempted and rescheduled on a different > * cpu before disabling preemption. Need to reload cpu area > * pointer. > */ > c = slub_get_cpu_ptr(s->cpu_slab); > #endif > > Mel's config has CONFIG_PREEMPT_VOLUNTARY, which means CONFIG_PREEMPTION is not > enabled. > > But then later in ___slab_alloc() we have > > slub_put_cpu_ptr(s->cpu_slab); > page = new_slab(s, gfpflags, node); > c = slub_get_cpu_ptr(s->cpu_slab); > > And this is not hidden under CONFIG_PREEMPTION, so with the #ifdef bug the > slub_put_cpu_ptr did a migrate_enable() with Mel's config, without prior > migrate_disable(). Ach, right. The update to this field is done with cmpxchg-double (if I remember correctly) but I don't remember if this is also re-entry safe. > If there wasn't the #ifdef PREEMPT_RT bug: > - this slub_put_cpu_ptr() would translate to put_cpu_ptr() thus > preempt_enable(), which on this config is just a barrier(), so it doesn't matter > that there was no matching preempt_disable() before. > - with PREEMPT_RT the CONFIG_PREEMPTION would be enabled, so the > slub_get_cpu_ptr() would do a migrate_disable() and there's no imbalance. > > But now that I dig into this in detail, I can see there might be another > instance of this imbalance bug, if CONFIG_PREEMPTION is disabled, but > CONFIG_PREEMPT_COUNT is enabled, which seems to be possible in some debug > scenarios. Because then preempt_disable()/preempt_enable() still manipulate the > preempt counter and compiling them out in __slab_alloc() will cause imbalance. > > So I think the guards in __slab_alloc() should be using CONFIG_PREEMPT_COUNT > instead of CONFIG_PREEMPT to be correct on all configs. I dare not remove them > completely :) :) Sebastian