From patchwork Wed Aug 1 20:04:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 10552929 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B558139A for ; Wed, 1 Aug 2018 20:04:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8973F2B7CA for ; Wed, 1 Aug 2018 20:04:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DCF32BA4E; Wed, 1 Aug 2018 20:04:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F0212BA53 for ; Wed, 1 Aug 2018 20:04:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC78D6B0005; Wed, 1 Aug 2018 16:04:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E50C56B0006; Wed, 1 Aug 2018 16:04:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC7C66B0007; Wed, 1 Aug 2018 16:04:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by kanga.kvack.org (Postfix) with ESMTP id A67C26B0005 for ; Wed, 1 Aug 2018 16:04:23 -0400 (EDT) Received: by mail-oi0-f69.google.com with SMTP id s68-v6so17693912oih.23 for ; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=TFI8atSi0GM/69YvIddp/hRRVym9hvZ6DtSBz2AeF94=; b=oBRbhVWIwlDDzsYruxV6CzNfVpMpBQ/2XsEBvQLknVFvITXSgUgp80dKG8EkZHMpCT I/gL3a5BS3WQO1+yPp1IUltdFZ0BWKnNAf/+sSq9Vu+Nba8XV3GAs4ZA2qNqCpIADFV8 STbeeZQPfLGgHbuad01F2yvZEBZ3RapAnPSU6ZAxPYyX9k54SYC4hGgNIsm85bt50Tge 0jiZfF2jOyOliCrH0Z/32qFgc0P6O9q4Mf+iaDcuwl0fbrLdbmPGsKEQT0yv9sxnh35J bdd6eg6oXUeenhHpwagUFxG18Wk+/RNb1YLm9inqYYqufzwnEXcwRd0Sf3So2gY+oENs C8Xw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com X-Gm-Message-State: AOUpUlEavr1ZUSEUit9Gul9WYNiduUvr7yyA+gqGCWAsE2ZMv5F6kpeN 4a3jjxAKn1LdGrW+Ca1Pf2D2EDy5yQ2fR+rHdogMSqRd2Wmm9l3LW8S7CL/ddJbldnOsbdXFcu5 ABuwOHnzOBaoVoD8FBUJGk2aqXM4Yvc5Ng+T9NjYperHT9We715CXJrEz7Kb+KiiRZA== X-Received: by 2002:aca:ebd8:: with SMTP id j207-v6mr5238345oih.206.1533153863356; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeYnQk1ScHkHeI6iYEF0uGwnys5ArnHDB2XZLXQQ2pXWcvHMJSm4V8FcBAS6RTKgroussdm X-Received: by 2002:aca:ebd8:: with SMTP id j207-v6mr5238291oih.206.1533153862461; Wed, 01 Aug 2018 13:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533153862; cv=none; d=google.com; s=arc-20160816; b=WAfPUSUrDJHfi2dqeP0jZhlB/0JHhyB5nI8q9JVGj/NeQxCXKJVCdrNYKjzFuMr36H WqNRIU6ox78reeTP9RwYWFf7ohfB5AeMQAhsRyvL5Jd+yh/cDlpS0QTxdBfamldJNcO2 BKHhqlKNAJnyYTG1p6qFYORYh52dc1g5tTm+n1REEMVJNb6X0XaG2wUZXjgVw3YXQb0M RKYNL34PV1bO2mATgNTG4HAuPEeeogf0l19clbgGKAvHW90mjDivGCwdiCkhJzrGlY4i IbHPieR2A75MUqWLnxcraxy8qp6doARsyvtGSAwY4LF69kUBZuR9i11Js8a6uxlt9Fui TiJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=TFI8atSi0GM/69YvIddp/hRRVym9hvZ6DtSBz2AeF94=; b=jhuscIZUGAKsa/gErDhqKoWHDG7miOjOkOhBU2qroDDonkZMIQSMKdvavO7faCHJl/ qL5DCW/9ojSnhjra0fcBznLVoygNWxcsoV1iWNIzwwg2oMZrQm3Pi9ylVsJOCu02nLcu OyAwwl806/Mr2NmWtkqhXBFc1xIxB8pE5vQ62xWkg49XDk2yqZ9GtqCoChRNd3rLMJNJ n2X8RoZj4D+303W2qiVirKX8Dl8QgYtgZelRREq1E94ng+JkjFhu+AL/ta7IUGsjlJJe HkxOx7l7t+RYCpJUgQ9V+johZQf9Ec0OZ9ZVcY4i0ST6cfKtwYSrP/ljaOE9aYVutr6B 7/sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id i11-v6si8628047oia.112.2018.08.01.13.04.22 for ; Wed, 01 Aug 2018 13:04:22 -0700 (PDT) Received-SPF: pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DE2EDED1; Wed, 1 Aug 2018 13:04:21 -0700 (PDT) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3B0143F5BA; Wed, 1 Aug 2018 13:04:21 -0700 (PDT) From: Jeremy Linton To: linux-mm@kvack.org Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, Punit.Agrawal@arm.com, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, bhelgaas@google.com, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [RFC 1/2] slub: Avoid trying to allocate memory on offline nodes Date: Wed, 1 Aug 2018 15:04:17 -0500 Message-Id: <20180801200418.1325826-2-jeremy.linton@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801200418.1325826-1-jeremy.linton@arm.com> References: <20180801200418.1325826-1-jeremy.linton@arm.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP If a user calls the *alloc_node() functions with an invalid node its possible to crash in alloc_pages_nodemask because NODE_DATA() returns a bad node, which propogates into the node zonelist in prepare_alloc_pages. This avoids that by not trying to allocate new slabs against offline nodes. (example backtrace) __alloc_pages_nodemask+0x128/0xf48 allocate_slab+0x94/0x528 new_slab+0x68/0xc8 ___slab_alloc+0x44c/0x520 __slab_alloc+0x50/0x68 kmem_cache_alloc_node_trace+0xe0/0x230 Signed-off-by: Jeremy Linton --- mm/slub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 51258eff4178..e03719bac1e2 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2519,6 +2519,8 @@ static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node, if (unlikely(!node_match(page, searchnode))) { stat(s, ALLOC_NODE_MISMATCH); deactivate_slab(s, page, c->freelist, c); + if (!node_online(searchnode)) + node = NUMA_NO_NODE; goto new_slab; } } From patchwork Wed Aug 1 20:04:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Linton X-Patchwork-Id: 10552931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04595139A for ; Wed, 1 Aug 2018 20:04:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4FDF2B5C9 for ; Wed, 1 Aug 2018 20:04:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D95B12B7CA; Wed, 1 Aug 2018 20:04:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C7FC2B5E9 for ; Wed, 1 Aug 2018 20:04:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7EA26B0007; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C05376B0008; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACD696B000A; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id 7A27F6B0008 for ; Wed, 1 Aug 2018 16:04:24 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id 20-v6so17805764ois.21 for ; Wed, 01 Aug 2018 13:04:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=nwL45KZXQc3dyip/An/8rY2zR22RmCtB6f8mc8vZbW4=; b=tvVC+PeePYAfCTVDBLVnfRCHvic096T6figjdUWzTIwNoihZcgU2bkAkmpgLQ/m9NE Vvr13FqSCv8gGFngIwZLx/koyvb802pmjVVlba6YNjYmvesDYXu+P4/wGrFUS710ZE3c gEYvtHKjDKIPxInVMN00t79BiSkhjuEzuh4cgeFqfNTlQfHFBAPXPjCN/k2r7w1R1Oj3 n56sbQfE5zHwNIChmGKKxF3zz+P7Ch4VaS32Yj3kROmWGzcsy5EU9bobB7ySWhc+SNnm ZLLsj5P7sQUaVJj/qp9iW5Aq9wWILvvN/QasyNaHDcsboU06eOBET94A09wOl+dwQxVL Fi0Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com X-Gm-Message-State: AOUpUlGu3n+1kmuhv4n/sQFdhhU+vxORBxQ85EWw08GjFADhIexbKWgv QGXyfsMWM1/tGW7xIMMjlC902fxgkifu123klS1njWoEt6Nrl+F54FOhxKcelNm5LUsCbEJix3r KtV8x1RYmzYj9dugoZXuGmm+Uk4JNqUjSlheH15Tv9aQc1+F/HOx0JXJc/cF3h1PTsA== X-Received: by 2002:aca:d0cc:: with SMTP id j73-v6mr4306122oiy.255.1533153864257; Wed, 01 Aug 2018 13:04:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd6pEg1cOMl4vv7oaRk1q1zozEMw0A9LmX8z6C/JTOBYgihNjm7YeYxWu3fGvlkIt9hMsz9 X-Received: by 2002:aca:d0cc:: with SMTP id j73-v6mr4306081oiy.255.1533153863571; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533153863; cv=none; d=google.com; s=arc-20160816; b=mjm50EBxw3MqA4nW+/P4NNunyGvebLCcN0hsfXU9PsJ1EKR1MOeb/UqWcaJnIiNv18 DXlfYaNvA4rWj2tCY9f0xpDzoQ05Tp9vgGV+RSsBAMcpN6q2dsdWYrgPpV+jYt7MSOJR Qk/bxxkZ44N3JDAiwoJFlOi3phRVlEhJNBYBA66DpxRLIeCGeh3xggaIBhzjOCui5bHL esuh1fcO9BPhw4VuR+P2CNhuBqHxKHU1qOs6rvw9NKP0M2Rg5g8hIS1dA3I50s4xPvaZ JQpunc6BqXXaBpaNYgRzH8+cS3F06UUvsbPBuW7tRyh5htjMlgxzOWQSmP8JvaK4zCxd yt4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nwL45KZXQc3dyip/An/8rY2zR22RmCtB6f8mc8vZbW4=; b=mCcqQ844ZMBkIKggenT6AFzzVDRHiviSVL+xqJCW5b6c3/CsoevqbpUv638TZsZbIW 0BAgOYAYrurRiGjTE8e3moHwQwMKjSUJGXqiyE3GPuskusAJa4VreOJL/BuChVkIBj2I 5HdmirXzopZFE1P+2q8qCtuMwaBS64qjsXSgq6aX2XRQfttdADEMollRnom/t0XabcZc ICG0GDREraod/f2RM4B79I2innBOHc4fI5h1DAJrK6SAJEoRGfkUtxjacqftYG2InPcI uNKfj3AtZbmrlj68n+OfoFAFUn0tm1eug981U55jwCj7sEcDPHkxqbZhZh1dQgWW3Iwk j+3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id e66-v6si11529738oif.85.2018.08.01.13.04.23 for ; Wed, 01 Aug 2018 13:04:23 -0700 (PDT) Received-SPF: pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jeremy.linton@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jeremy.linton@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3D0AC1596; Wed, 1 Aug 2018 13:04:23 -0700 (PDT) Received: from beelzebub.austin.arm.com (beelzebub.austin.arm.com [10.118.12.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9717D3F5BA; Wed, 1 Aug 2018 13:04:22 -0700 (PDT) From: Jeremy Linton To: linux-mm@kvack.org Cc: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, Punit.Agrawal@arm.com, Lorenzo.Pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, bhelgaas@google.com, linux-kernel@vger.kernel.org, Jeremy Linton Subject: [RFC 2/2] mm: harden alloc_pages code paths against bogus nodes Date: Wed, 1 Aug 2018 15:04:18 -0500 Message-Id: <20180801200418.1325826-3-jeremy.linton@arm.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180801200418.1325826-1-jeremy.linton@arm.com> References: <20180801200418.1325826-1-jeremy.linton@arm.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP Its possible to crash __alloc_pages_nodemask by passing it bogus node ids. This is caused by NODE_DATA() returning null (hopefully) when the requested node is offline. We can harded against the basic case of a mostly valid node, that isn't online by checking for null and failing prepare_alloc_pages. But this then suggests we should also harden NODE_DATA() like this #define NODE_DATA(nid) ( (nid) < MAX_NUMNODES ? node_data[(nid)] : NULL) eventually this starts to add a bunch of generally uneeded checks in some code paths that are called quite frequently. Signed-off-by: Jeremy Linton --- include/linux/gfp.h | 2 ++ mm/page_alloc.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index a6afcec53795..17d70271c42e 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -436,6 +436,8 @@ static inline int gfp_zonelist(gfp_t flags) */ static inline struct zonelist *node_zonelist(int nid, gfp_t flags) { + if (unlikely(!NODE_DATA(nid))) //VM_WARN_ON? + return NULL; return NODE_DATA(nid)->node_zonelists + gfp_zonelist(flags); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a790ef4be74e..3a3d9ac2662a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4306,6 +4306,8 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order, { ac->high_zoneidx = gfp_zone(gfp_mask); ac->zonelist = node_zonelist(preferred_nid, gfp_mask); + if (!ac->zonelist) + return false; ac->nodemask = nodemask; ac->migratetype = gfpflags_to_migratetype(gfp_mask);