From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9745FC4332B for ; Thu, 19 Mar 2020 13:48:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 646FF208D6 for ; Thu, 19 Mar 2020 13:48:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 646FF208D6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EEAE96B0003; Thu, 19 Mar 2020 09:48:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E74656B0005; Thu, 19 Mar 2020 09:48:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3CCA6B0006; Thu, 19 Mar 2020 09:48:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id BE0166B0003 for ; Thu, 19 Mar 2020 09:48:04 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 5C971180AD81A for ; Thu, 19 Mar 2020 13:48:04 +0000 (UTC) X-FDA: 76612240488.18.sun57_63866525e121f X-HE-Tag: sun57_63866525e121f X-Filterd-Recvd-Size: 4525 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Mar 2020 13:48:03 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CC5EDACDF; Thu, 19 Mar 2020 13:47:59 +0000 (UTC) Subject: Re: [RFC 1/2] mm, slub: prevent kmalloc_node crashes and memory leaks To: Sachin Sant Cc: bharata@linux.ibm.com, Nathan Lynch , Srikar Dronamraju , linuxppc-dev@lists.ozlabs.org, Michal Hocko , Pekka Enberg , linux-mm@kvack.org, Kirill Tkhai , David Rientjes , Christopher Lameter , Mel Gorman , Joonsoo Kim , Michael Ellerman References: <20200318144220.18083-1-vbabka@suse.cz> <20200318160610.GD26049@in.ibm.com> <0F67B5AA-96DF-4977-BDC6-D72959B3F7EF@linux.vnet.ibm.com> <658E6AB8-581F-4722-BCBB-4BDD2245D265@linux.vnet.ibm.com> From: Vlastimil Babka Message-ID: <339cf655-393e-c48e-4797-86f61df56c35@suse.cz> Date: Thu, 19 Mar 2020 14:47:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <658E6AB8-581F-4722-BCBB-4BDD2245D265@linux.vnet.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/19/20 2:26 PM, Sachin Sant wrote: > > >> On 19-Mar-2020, at 6:53 PM, Vlastimil Babka wrote: >> >> On 3/19/20 9:52 AM, Sachin Sant wrote: >>> >>>> OK how about this version? It's somewhat ugly, but important is that the fast >>>> path case (c->page exists) is unaffected and another common case (c->page is >>>> NULL, but node is NUMA_NO_NODE) is just one extra check - impossible to avoid at >>>> some point anyway. >>>> >>> >>> I attempted the suggested tests. >>> >>> Test 1: March 18 linux-next + Patch 1 [1] + Patch 2 [2] >>> >>> Machine boots fine. numactl o/p after boot: >> >> Great, thanks! Can I add your Tested-by: then? > > Sure. > Tested-by: Sachin Sant > > Thank you for the fix. Thanks! Sorry to bother, but in the end I decided to do further change so I would appreciate verification if it still works as intended. The point is to use node_state(N_NORMAL_MEMORY) instead of node_present_pages(), as that is really what SLUB uses to decide whether to allocate the kmem_cache_node. So we should match this properly given the opportunity. I have also again removed the node_online() check in alloc_slab_page() as it really shouldn't be reachable with an offline node - everything is taken care of in ___slab_alloc, or callers use NUMA_NO_NODE. ----8<---- diff --git a/mm/slub.c b/mm/slub.c index 17dc00e33115..7113b1f9cd77 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1973,8 +1973,6 @@ static void *get_partial(struct kmem_cache *s, gfp_t flags, int node, if (node == NUMA_NO_NODE) searchnode = numa_mem_id(); - else if (!node_present_pages(node)) - searchnode = node_to_mem_node(node); object = get_partial_node(s, get_node(s, searchnode), c, flags); if (object || node != NUMA_NO_NODE) @@ -2563,17 +2561,27 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, struct page *page; page = c->page; - if (!page) + if (!page) { + /* + * if the node is not online or has no normal memory, just + * ignore the node constraint + */ + if (unlikely(node != NUMA_NO_NODE && + !node_state(node, N_NORMAL_MEMORY))) + node = NUMA_NO_NODE; goto new_slab; + } redo: if (unlikely(!node_match(page, node))) { - int searchnode = node; - - if (node != NUMA_NO_NODE && !node_present_pages(node)) - searchnode = node_to_mem_node(node); - - if (unlikely(!node_match(page, searchnode))) { + /* + * same as above but node_match() being false already + * implies node != NUMA_NO_NODE + */ + if (!node_state(node, N_NORMAL_MEMORY)) { + node = NUMA_NO_NODE; + goto redo; + } else { stat(s, ALLOC_NODE_MISMATCH); deactivate_slab(s, page, c->freelist, c); goto new_slab; -- 2.25.1