Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp431447pxx; Wed, 28 Oct 2020 08:12:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRj7nTXTH8OHsmwkHKOLka8dq5BR4nJNMyzG/5LtBz3o/xorXjcfL5uJmTvaeqqTJ2KBDQ X-Received: by 2002:a17:906:5e49:: with SMTP id b9mr8024897eju.436.1603897940268; Wed, 28 Oct 2020 08:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603897940; cv=none; d=google.com; s=arc-20160816; b=ncCItC/XMA7jLDHV4zxqT6p1QZr2h4KTCwxa+PwK2LAr43TQW6K1erJU25ZYb7JJTo s3xSgt7QN+Yb2O33LMoBmz8OG/WKcUyByo7QAfeMpv3rSO+avGota0LTHGyo42z/1vJT ha/wDzbpdF1RxrA5QHCbOilEV5JWszKkmJiW4YBCgS3WpnLfyewTvItswfQQoWGrHoPX RJnJbUn0FHWBeAmYl3hLzxpSM0PRcdIRnDssPJaCv3gpC+erLAEEeHzEZMbrEZJ8lKfs P1W+R1DrC29AMnZ9USR80BpW1QUrB8NMQGjsssPHCMnnMQ/+5M6vrz9QWIQYGn7fHGYQ Wo6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to; bh=eFC98lPxctcUDjgboBGbGlI300P8oD7VEVjI6JAu9u0=; b=c9oGMUxxBAlW67GBqaQ8RZXiOHdfGdNrMjeWzkm+nlSCWCMRd6zfkWKMBjg7a5WPT/ mWzifcAnQhva5v7dXmRgYNjZBmEtUyj+4eKCT5bWkiI6qR75iP+L58RB+6kPh+uSp9j/ vXlmSqJanR6wp+ch5wFe5yttXu+VXX18ATLnqgBrvS1mFCfOJQWTS2Z1AZ+Yy97035Dn QEpaU4mA5qVvG9Ovlmo2Ilvsoxoo5l5MYS1ipeHQ6k8i7XNNYrDK+4QKIE86wbpn+KuF fV0RYGvBbJrnvgDUWzfyRT2wgPYKwarDQWDAXG3E/EAoioaIMaUkV1+hCbuv80G0GEGp eUYQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si2969573ejk.629.2020.10.28.08.11.56; Wed, 28 Oct 2020 08:12:20 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764485AbgJ0QbY (ORCPT + 99 others); Tue, 27 Oct 2020 12:31:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:47810 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763851AbgJ0QbU (ORCPT ); Tue, 27 Oct 2020 12:31:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9EACBAFF2; Tue, 27 Oct 2020 16:31:17 +0000 (UTC) To: Laurent Dufour , Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, nathanl@linux.ibm.com, cheloha@linux.ibm.com, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , stable@vger.kernel.org References: <20201027140926.276-1-ldufour@linux.ibm.com> <20201027142421.GW20500@dhcp22.suse.cz> <11bdd295-3ef8-fbeb-2c76-2a109fa26f19@linux.ibm.com> <20201027150350.GZ20500@dhcp22.suse.cz> From: Vlastimil Babka Subject: Re: [PATCH] mm/slub: fix panic in slab_alloc_node() Message-ID: <7ef64e75-2150-01a9-074d-a754348683b3@suse.cz> Date: Tue, 27 Oct 2020 17:31:14 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/27/20 4:12 PM, Laurent Dufour wrote: > Le 27/10/2020 à 16:03, Michal Hocko a écrit : >> On Tue 27-10-20 15:39:46, Laurent Dufour wrote: >>> Le 27/10/2020 à 15:24, Michal Hocko a écrit : >>>> [Cc Vlastimil] >>>> >>>> On Tue 27-10-20 15:09:26, Laurent Dufour wrote: >>>> >>>> Could you be more specific? I am especially confused how the memory >>>> hotplug is involved here. What kind of flush are we talking about? >>> >>> This happens when flush_cpu_slab() is called when a memory block is about to >>> be offlined, see slab_mem_going_offline_callback() called by the >>> MEM_GOING_OFFLINE's callback triggered by offline_pages(). >> >> This would be a very valuable information for the changelog. I have to >> admit that a more detailed description would help somebody not really >> familiar with slub internals like me. Agreed, please include that. >> I still fail to see why do we get an inconsistent state though. I >> thought that no object is associated with an offlined page so how come >> we have an object without any page? > > The inconsistent state came from the IPI interrupt calling flush_cpu_slab() > being taken between reading c->freelist and c->page. Yes; also good to state explicitly. >> How does this allocation path synchronizes with the offline callback? > > My understanding is that this is done by the call to this_cpu_cmpxchg_double() > done later, but I would let the slub experts detail that point. Yes, cmpxchg will detect that c->freelist changed. If we managed to read both c->freelist and c->page before the interrupt (and thus not crash), cmpxchg_double will fail on the s->cpu_slab->tid part as flush_slab() will also bump the tid. >>>>> In commit 6159d0f5c03e ("mm/slub.c: page is always non-NULL in >>>>> node_match()") check on the page pointer has been removed assuming that >>>>> page is always valid when it is called. It happens that this is not true in >>>>> that particular case, so check for page before calling node_match() here. >>>>> >>>>> Fixes: 6159d0f5c03e ("mm/slub.c: page is always non-NULL in node_match()") >>>>> Signed-off-by: Laurent Dufour With the expanded changelog, Acked-by: Vlastimil Babka Thanks! >>>>> Cc: Christoph Lameter >>>>> Cc: Pekka Enberg >>>>> Cc: David Rientjes >>>>> Cc: Joonsoo Kim >>>>> Cc: Andrew Morton >>>>> Cc: stable@vger.kernel.org >>>>> --- >>>>> mm/slub.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/mm/slub.c b/mm/slub.c >>>>> index 8f66de8a5ab3..7dc5c6aaf4b7 100644 >>>>> --- a/mm/slub.c >>>>> +++ b/mm/slub.c >>>>> @@ -2852,7 +2852,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, >>>>> object = c->freelist; >>>>> page = c->page; >>>>> - if (unlikely(!object || !node_match(page, node))) { >>>>> + if (unlikely(!object || !page || !node_match(page, node))) { >>>>> object = __slab_alloc(s, gfpflags, node, addr, c); >>>>> } else { >>>>> void *next_object = get_freepointer_safe(s, object); >>>>> -- >>>>> 2.29.1 >>>>> >>>> >>> >> > >